Revision: 5419
Author:   [email protected]
Date:     Wed May 22 16:28:32 2013
Log: Fix NO_NETWORK policy causing guests to lose progress; don't fetch example.com.
https://codereview.appspot.com/9638047

* caja.policy.net.NO_NETWORK.fetch now invokes its callback rather than
  ignoring it.
  Fixes <https://code.google.com/p/google-caja/issues/detail?id=1579>.
* test-cajajs-invocation testBuilderApiNetNone checks that <script src>
  and XHR fail sensibly under NO_NETWORK.
* In default test driver, use domain "caja-test-url.test" instead of
  "example.com" for rewriting, and don't fetch any such urls if
  they go to the fetcher (not all do). The TLD ".test" is reserved
  by RFC 2606.
  Fixes <https://code.google.com/p/google-caja/issues/detail?id=1680>.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=5419

Modified:
 /trunk/src/com/google/caja/plugin/caja.js
 /trunk/tests/com/google/caja/plugin/default-test-driver.js
 /trunk/tests/com/google/caja/plugin/es53-test-cajajs-invocation.js
 /trunk/tests/com/google/caja/plugin/es53-test-domado-dom-guest.html

=======================================
--- /trunk/src/com/google/caja/plugin/caja.js   Thu Apr 11 19:45:31 2013
+++ /trunk/src/com/google/caja/plugin/caja.js   Wed May 22 16:28:32 2013
@@ -91,7 +91,12 @@
       },
       'NO_NETWORK': {
         'rewrite': function () { return null; },
-        'fetch': function() { }
+        'fetch': function(url, mime, callback) {
+          setTimeout(function() {
+            // TODO(kpreid): correct error response (define one if needed)
+            callback({});
+          }, 0);
+        }
       },
       'ALL': {
         'rewrite': function (uri) { return String(uri); },
=======================================
--- /trunk/tests/com/google/caja/plugin/default-test-driver.js Tue May 14 14:13:11 2013 +++ /trunk/tests/com/google/caja/plugin/default-test-driver.js Wed May 22 16:28:32 2013
@@ -45,7 +45,13 @@
       frameGroup.makeES5Frame(
           createDiv(),
           {
-            fetch: caja.policy.net.ALL.fetch,
+            fetch: function(uri, mime, callback) {
+              if (/^http:\/\/caja-test-url.test/.test(uri)) {
+ return caja.policy.net.NO_NETWORK.fetch(uri, mime, callback);
+              } else {
+                return caja.policy.net.ALL.fetch(uri, mime, callback);
+              }
+            },
             rewrite: function (uri, uriEffect, loaderType, hints) {
               if (uri.getPath().indexOf('test-image-41x13.png') !== -1) {
                 // used by es53-test-domado-dom-guest.html
@@ -54,7 +60,8 @@
               return URI.create(
                   'http',
                   null,
-                  'example.com',
+                  // .test is reserved by RFC 2606
+                  'caja-test-url.test',
                   null,
                   '/',
                   [
=======================================
--- /trunk/tests/com/google/caja/plugin/es53-test-cajajs-invocation.js Tue May 14 14:13:11 2013 +++ /trunk/tests/com/google/caja/plugin/es53-test-cajajs-invocation.js Wed May 22 16:28:32 2013
@@ -271,19 +271,38 @@

jsunitRegister('testBuilderApiNetNone', function testBuilderApiNetNone() {
     var div = createDiv();
-    caja.load(div, caja.policy.net.NO_NETWORK, function (frame) {
+ caja.load(div, caja.policy.net.NO_NETWORK, jsunitCallback(function(frame) {
+      var xhrRes = [];
       frame.code(
           location.protocol + '//' + location.host + '/',
           'text/html',
           '<a href="http://fake1.url/foo";>fake1</a>' +
-          '<a href="http://fake2.url/foo";>fake2</a>'
+          '<a href="http://fake2.url/foo";>fake2</a>' +
+          // script should not stall execution, just not load.
+          '<script src="http://bogus.invalid/foo.js";></script>' +
+          // xhr should indicate error response
+          '<script>' +
+          'r("init");' +
+          'var xhr = new XMLHttpRequest();' +
+ 'try { xhr.open("http://localhost/";); } catch (e) { r("" + e); }' +
+          'xhr.onreadystatechange = function() {' +
+          '  r(xhr.readyState + xhr.responseText);' +
+          '};' +
+          'xhr.send();' +
+          '</script>'
           )
-        .run(function (result) {
+        .api({r: frame.tame(frame.markFunction(
+            function(val) { xhrRes.push(val); }))})
+        .run(jsunitCallback(function(result) {
assertStringDoesNotContain('http://fake1.url/foo', div.innerHTML); assertStringDoesNotContain('http://fake2.url/foo', div.innerHTML); + // we don't actually care that this is specifically the error, but
+          // we want to make sure we do get a specific error and not a lost
+          // signal
+ assertEquals('init,URI violates security policy', String(xhrRes));
           jsunitPass('testBuilderApiNetNone');
-        });
-    });
+        }));
+    }));
   });

   jsunitRegister('testBuilderApiNetAll', function testBuilderApiNetAll() {
=======================================
--- /trunk/tests/com/google/caja/plugin/es53-test-domado-dom-guest.html Tue May 21 13:19:02 2013 +++ /trunk/tests/com/google/caja/plugin/es53-test-domado-dom-guest.html Wed May 22 16:28:32 2013
@@ -1338,8 +1338,8 @@
     // by some other whitespace processing we're not implementing.
     assertEquals(
         '\n' +
- ' <a href="http://example.com/?effect=NEW_DOCUMENT&amp;loader=' +
-        'UNSANDBOXED&amp;uri=http%3A%2F%2F' + location.hostname +
+        '    <a href="http://caja-test-url.test/?effect=NEW_DOCUMENT' +
+ '&amp;loader=UNSANDBOXED&amp;uri=http%3A%2F%2F' + location.hostname +
         '%3A' + location.port + '%2Fant-testlib%2F' +
         'com%2Fgoogle%2Fcaja%2Fplugin%2Ffoo">bar</a>\n' +
         '    <span>Hello world</span>\n' +
@@ -2860,12 +2860,12 @@
     assertEquals(
         (''
          + '<map name="foo-' + directAccess.getIdSuffix() + '">'
-         + '<area href="http://example.com/'
+         + '<area href="http://caja-test-url.test/'
          + '?effect=NEW_DOCUMENT&amp;loader=UNSANDBOXED'
          + '&amp;uri=(base)/areatarget.html" target="_blank">'
          + '</map>'
          + '<img'
-         + ' src="http://example.com/'
+         + ' src="http://caja-test-url.test/'
          + '?effect=SAME_DOCUMENT&amp;loader=SANDBOXED'
          + '&amp;uri=(base)/mappic.gif" usemap="#foo-'
          + directAccess.getIdSuffix() + '"'

--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to