<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>It seems clear that we can't just scan through the code to find cookie stealing. Yeah, that would help a little bit, but there are literally infinitely many ways to obfuscate a reference to &lt;code&gt;document.cookie&lt;/code&gt;. With even just a little thought, an experienced JavaScript programmer can probably find two different filter workarounds, and that's before factoring in Mozilla-specific quirks like &lt;code&gt;anyNodeInTheDocument.__parent__==document&lt;/code&gt;. It seems like only restrictions on Greasemonkey itself would be effective for preventing cookie theft. Perhaps messing around with the sandbox's access to document.cookie to notify the user when a userscript attempts to access a cookie?

Just to make my point clearer, here are several ways that would be very difficult to automatically filter or automatically recognize:

&lt;pre&gt;for(i in document){
   if(i.match(/^c\o{2}k(?:)[i\ii]\u0065(?:)$/)) // RegExp obfuscation
      stolenData=document[i] // it ONLY matches &quot;cookie&quot;
}&lt;/pre&gt;
&lt;pre&gt;for(i in document){
   if(i.charCodeAt(0)==99) // if and charcode obfuscation
      if(i.charCodeAt(1)==i.charCodeAt(2)==111)
         if(i.charCodeAt(3)==107)
            if(i.substring(4)==&quot;ie&quot;)
               stolenData=document[i]
}&lt;/pre&gt;
&lt;pre&gt;stolenData=anyNodeInTheDocument.__parent__.cookie // Mozilla-only&lt;/pre&gt;
&lt;pre&gt;leverage=
   {
      get x(){return document}, // requires getters
      get y(a){if(a)return &quot;co&quot;;return undefined}, // extra protection...
      get z(){return &quot;okie&quot;}
   };
V=leverage.__lookupGetter__(&quot;y&quot;)(1);
stolenData=leverage.x[V+leverage.z];&lt;/pre&gt;
&lt;pre&gt;stolenData=document[&quot;co&quot;+[&quot;o&quot;][0]+&quot;ki&quot;+(&quot;document&quot;).charAt(5)]
// string assembly... with a twist.&lt;/pre&gt;
&lt;pre&gt;A=&quot;coo&quot;;
// several hundred lines of code go here
B=&quot;kie&quot;;
// several hundred more lines of code go here
stolenData=document[A+B]&lt;/pre&gt;
I post these examples because I know that a determined attacker will think either of them or of something similar or better.</body>
  <body-html>&lt;p&gt;It seems clear that we can't just scan through the code to find cookie stealing. Yeah, that would help a little bit, but there are literally infinitely many ways to obfuscate a reference to &lt;code&gt;document.cookie&lt;/code&gt;. With even just a little thought, an experienced JavaScript programmer can probably find two different filter workarounds, and that's before factoring in Mozilla-specific quirks like &lt;code&gt;anyNodeInTheDocument.__parent__==document&lt;/code&gt;. It seems like only restrictions on Greasemonkey itself would be effective for preventing cookie theft. Perhaps messing around with the sandbox's access to document.cookie to notify the user when a userscript attempts to access a cookie?&lt;/p&gt;

&lt;p&gt;Just to make my point clearer, here are several ways that would be very difficult to automatically filter or automatically recognize:&lt;/p&gt;

&lt;p&gt;&lt;pre&gt;for(i in document){
   if(i.match(/^c\o{2}k(?:)[i\ii]\u0065(?:)$/)) // RegExp obfuscation
      stolenData=document[i] // it ONLY matches &quot;cookie&quot;
}&lt;/pre&gt;&lt;pre&gt;for(i in document){
   if(i.charCodeAt(0)==99) // if and charcode obfuscation
      if(i.charCodeAt(1)==i.charCodeAt(2)==111)
         if(i.charCodeAt(3)==107)
            if(i.substring(4)==&quot;ie&quot;)
               stolenData=document[i]
}&lt;/pre&gt;&lt;pre&gt;stolenData=anyNodeInTheDocument.__parent__.cookie // Mozilla-only&lt;/pre&gt;&lt;pre&gt;leverage=
   {
      get x(){return document}, // requires getters
      get y(a){if(a)return &quot;co&quot;;return undefined}, // extra protection...
      get z(){return &quot;okie&quot;}
   };
V=leverage.__lookupGetter__(&quot;y&quot;)(1);
stolenData=leverage.x[V+leverage.z];&lt;/pre&gt;&lt;pre&gt;stolenData=document[&quot;co&quot;+[&quot;o&quot;][0]+&quot;ki&quot;+(&quot;document&quot;).charAt(5)]
// string assembly... with a twist.&lt;/pre&gt;&lt;pre&gt;A=&quot;coo&quot;;
// several hundred lines of code go here
B=&quot;kie&quot;;
// several hundred more lines of code go here
stolenData=document[A+B]&lt;/pre&gt;
&lt;br /&gt;I post these examples because I know that a determined attacker will think either of them or of something similar or better.&lt;/p&gt;</body-html>
  <created-at type="datetime">2009-03-14T03:01:26Z</created-at>
  <forumable-id type="integer">3</forumable-id>
  <forumable-type>Forum</forumable-type>
  <id type="integer">102510</id>
  <topic-id type="integer">704</topic-id>
  <updated-at type="datetime">2009-03-14T03:08:25Z</updated-at>
  <user-agent nil="true"></user-agent>
  <user-id type="integer">51536</user-id>
</post>
