In Using WebSocket in point-to-point communication in Adobe ColdFusion 10 Dev Guide, the javascript object mysocket
created by <cfwebsocket>
can call an invoke()
method that can literally invoke Any public method on Any CFC from JavaScript.
How is this Not a security risk? How shall a cfc / function protect against being invoked by websocket?
1. Create a CFM page index.cfm.
<script type="text/javascript"> function msgHandler(msgobj){ var txt = document.getElementById("myDiv"); var message = ColdFusion.JSON.encode(msgobj); txt.innerHTML += message + "<br >" + "<br>"; } function invokecfcfn(){ var fname= document.getElementById("fnname").value; if (fname == "f2") { alert("f2 selected"); mysocket.invoke("mycfc", "f2", ["echo"]); } else mysocket.invoke("mycfc", fname); } </script> <cfwebsocket name="mysocket" onmessage="msgHandler"/> <form> <select id="fnname"> <option>f1</option> <option>f2</option> <option>f3</option> </select> <input id="invokefn" name="invokefn" value="Invoke CFC function " type="button" onclick="invokecfcfn();"> <div id="myDiv"> </div> </form>
2. Create a CFC mycfc.cfc that contains the function called from the client page.
<cfcomponent> <cffunction name="f1" > <cfreturn "Message returned from f1"> </cffunction> <cffunction name="f2" returntype="string" > <cfargument name="arg1" type="string" required="true" > <cfset msg= "Message from wsssendmessage of f2 which you called with arg " & arg1> <cfset wssendMessage(msg)> <cfreturn "Message returned from f2"> </cffunction> <cffunction name="f3" > <cfthread action="run" name="t1" > <cfloop index="i" from="1" to="10"> <cfset sleep(20000)> <cfset wssendMessage("Message #i# from wsssendmessage of f3 #now()#")> </cfloop> </cfthread> <cfreturn "Thread initiated in f3"> </cffunction> </cfcomponent>
EDIT: not Any function, private function returns:
{
"clientid":39550088,
"ns":"coldfusion.websocket.channels",
"reqType":"invoke",
"code":4001,
"type":"response",
"msg":"The method f1 was not found in component mycfc.cfc."
}
UPDATE:
I tried moving mycfc.cfc
to /com
(outside of webroot) and added a mapping to /com
and the functions can STILL be successfully invoked.
UPDATE: July 3, 2013
The Adobe Product Security Incident Response Team (PSIRT) is aware of this issue and is actively engaged with the ColdFusion Product Team to release a fix.
http://blogs.coldfusion.com/post.cfm/coldfusion-10-websocket-vulnerebility
UPDATE: July 9, 2013
Adobe has released a security hotfix for ColdFusion 10 for Windows, Macintosh and Linux. This hotfix addresses a vulnerability (CVE-2013-3350) that could permit an attacker to invoke public methods on ColdFusion Components (CFC) using WebSockets.
http://www.adobe.com/support/security/bulletins/apsb13-19.html