[Pkg-mozext-commits] [requestpolicy] 02/80: [refact] rewrite some code regarding #633

David Prévot taffit at moszumanska.debian.org
Sun Jul 5 15:02:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit b38bc45a8925a090adf8dddbcccc72913336295d
Author: Martin Kimmerle <dev at 256k.de>
Date:   Thu May 7 15:17:58 2015 +0200

    [refact] rewrite some code regarding #633
---
 src/content/lib/request-processor.redirects.js | 87 +++++++++++++++++---------
 1 file changed, 56 insertions(+), 31 deletions(-)

diff --git a/src/content/lib/request-processor.redirects.js b/src/content/lib/request-processor.redirects.js
index a6ea9e4..24d1858 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -263,41 +263,40 @@ let RequestProcessor = (function(self) {
         // We try to trace the blocked redirect back to a link click or form
         // submission if we can. It may indicate, for example, a link that
         // was to download a file but a redirect got blocked at some point.
-        var initialOrigin = originURI;
-        var initialDest = destURI;
-        // To prevent infinite loops, bound the number of iterations.
-        // Note that an apparent redirect loop doesn't mean a problem with a
-        // website as the site may be using other information, such as cookies
-        // that get set in the redirection process, to stop the redirection.
-        var iterations = 0;
-        const ASSUME_REDIRECT_LOOP = 100; // Chosen arbitrarily.
-        while (initialOrigin in internal.allowedRedirectsReverse &&
-               iterations++ < ASSUME_REDIRECT_LOOP) {
-          initialDest = initialOrigin;
-          initialOrigin = internal.allowedRedirectsReverse[initialOrigin];
-        }
-
-        if (initialOrigin in internal.clickedLinksReverse) {
-          for (var i in internal.clickedLinksReverse[initialOrigin]) {
-            // We hope there's only one possibility of a source page (that is,
-            // ideally there will be one iteration of this loop).
-            var sourcePage = i;
+        // Example:
+        //   "link click" -> "first redirect" -> "second redirect"
+        {
+          let initialOrigin = getOriginOfInitialRedirect();
+
+          if (internal.clickedLinksReverse.hasOwnProperty(initialOrigin)) {
+            let linkClickDest = initialOrigin;
+            let linkClickOrigin;
+
+            // fixme: bad smell! the same link (linkClickDest) could have
+            //        been clicked from different origins!
+            for (let i in internal.clickedLinksReverse[linkClickDest]) {
+              // We hope there's only one possibility of a source page (that is,
+              // ideally there will be one iteration of this loop).
+              linkClickOrigin = i;
+            }
+
+            // TODO: #633 - Review the following line (recordAllowedRequest).
+
+            // Maybe we just record the clicked link and each step in between as
+            // an allowed request, and the final blocked one as a blocked request.
+            // That is, make it show up in the requestpolicy menu like anything
+            // else.
+            // We set the "isInsert" parameter so we don't clobber the existing
+            // info about allowed and deleted requests.
+            internal.recordAllowedRequest(linkClickOrigin, linkClickDest, true,
+                                          request.requestResult);
           }
 
-          // Maybe we just record the clicked link and each step in between as
-          // an allowed request, and the final blocked one as a blocked request.
-          // That is, make it show up in the requestpolicy menu like anything
-          // else.
-          // We set the "isInsert" parameter so we don't clobber the existing
-          // info about allowed and deleted requests.
-          internal.recordAllowedRequest(sourcePage, initialOrigin, true,
-                                        request.requestResult);
+          // TODO: implement for form submissions whose redirects are blocked
+          //if (internal.submittedFormsReverse[initialOrigin]) {
+          //}
         }
 
-        // if (internal.submittedFormsReverse[initialOrigin]) {
-        // // TODO: implement for form submissions whose redirects are blocked
-        // }
-
         internal.recordRejectedRequest(request);
       }
       Logger.warning(Logger.TYPE_HEADER_REDIRECT,
@@ -330,6 +329,32 @@ let RequestProcessor = (function(self) {
     return true;
   }
 
+  /**
+   * @param {RedirectRequest} aRequest
+   */
+  function getOriginOfInitialRedirect(aRequest) {
+    var initialOrigin = aRequest.originURI;
+    var initialDest = aRequest.destURI;
+
+    // Prevent infinite loops, that is, bound the number of iterations.
+    // Note: An apparent redirect loop doesn't mean a problem with a
+    //       website as the site may be using other information,
+    //       such as cookies that get set in the redirection process,
+    //       to stop the redirection.
+    const ASSUME_REDIRECT_LOOP = 100; // Chosen arbitrarily.
+
+    for (let i = 0; i < ASSUME_REDIRECT_LOOP; ++i) {
+      if (false === (initialOrigin in internal.allowedRedirectsReverse)) {
+        // break the loop
+        break;
+      }
+
+      initialDest = initialOrigin;
+      initialOrigin = internal.allowedRedirectsReverse[initialOrigin];
+    }
+
+    return initialOrigin;
+  }
 
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list