summaryrefslogtreecommitdiff
path: root/src/xss/Exceptions.js
blob: 4e80c39463ce6d6436a57d63d4ea1dfcfd4db9fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
'use strict';

XSS.Exceptions = (() => {

  var Exceptions = {
    get legacyExceptions() {
      delete this.legacyExceptions;
      this.legacyExceptions =
        Legacy.getRxPref("filterXExceptions",
          Legacy.RX.multi, "g", /^https?:[a-z:/@.?-]*$/i);
      return this.legacyExceptions;
    },

    async getWhitelist() {
      return (await Storage.get("sync", "xssWhitelist")).xssWhitelist;
    },
    async setWhitelist(xssWhitelist) {
      await Storage.set("sync", {xssWhitelist});
    },

    async shouldIgnore(xssReq) {
      function logEx(...args) {
        debug("[XSS preprocessing] Ignoring %o", xssReq, ...args);
      }

      let {
        srcObj,
        destObj,
        srcUrl,
        destUrl,
        srcOrigin,
        destOrigin,
        unescapedDest,
        isGet,
        isPost
      } = xssReq;

      // same srcUrl
      if (srcOrigin === destOrigin) {
        return true;
      }

      // same domain + https: source
      if (/^https:/.test(srcOrigin) && xssReq.srcDomain === xssReq.destDomain) {
        return true;
      }

      if (/^(?:chrome|resource|moz-extension|about):/.test(srcOrigin)) {
        debug("Privileged origin", srcOrigin);
      }

      // destination or @source matching legacy regexp
      if (this.legacyExceptions.test(unescapedDest) &&
        !this.isBadException(destObj.hostname) ||
        this.legacyExceptions.test("@" + unescape(srcUrl))) {
        logEx("Legacy exception", this.legacyExceptions);
        return true;
      }

      if (!srcObj && isGet) {
        if (/^https?:\/\/msdn\.microsoft\.com\/query\/[^<]+$/.test(unescapedDest)) {
          return true; // MSDN from Microsoft VS
        }
      }

      if (srcOrigin) { // srcUrl-specific exceptions

        if (/^about:(?!blank)/.test(srcOrigin))
          return true; // any about: URL except about:blank

        if (srcOrigin === "https://www.youtube.com" &&
          /^https:\/\/(?:plus\.googleapis|apis\.google)\.com\/[\w/]+\/widget\/render\/comments\?/.test(destUrl) &&
          Legacy.getPref("filterXExceptions.yt_comments")
        ) {
          logEx("YouTube comments exception");
          return true;
        }

        if (isPost) {

          if (srcOrigin === "https://sso.post.ch" && destOrigin === "https://app.swisspost.ch") {
            return true;
          }

          if (srcOrigin === "https://twitter.com" && /^https:\/\/.*\.twitter\.com$/.test(destOrigin)) {
            return true;
          }

          {
            let rx = /^https:\/\/(?:[a-z]+\.)?unionbank\.com$/;
            if (rx.test(srcOrigin) && rx.test(destOrigin)) {
              return true;
            }
          }

          if (/^https?:\/\/csr\.ebay\.(?:\w{2,3}|co\.uk)\/cse\/start\.jsf$/.test(srcUrl) &&
            /^https?:\/\/msa-lfn\.ebay\.(?:\w{2,3}|co\.uk)\/ws\/eBayISAPI\.dll\?[^<'"%]*$/.test(unescapedDest) &&
            destObj.protocol === srcObj.protocol &&
            Legacy.getPref("filterXException.ebay")) {
            logEx("Ebay exception");
            return true;
          }

          if (/^https:\/\/(?:cap\.securecode\.com|www\.securesuite\.net|(?:.*?\.)?firstdata\.(?:l[tv]|com))$/.test(srcUrl) &&
            Legacy.getPref("filterXException.visa")) {
            logEx("Verified by Visa exception");
            return true;
          }

          if (/\.verizon\.com$/.test(srcOrigin) &&
            /^https:\/\/signin\.verizon\.com\/sso\/authsso\/forumLogin\.jsp$/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.verizon")) {
            logEx("Verizon login exception");
            return true;
          }

          if (/^https?:\/\/mail\.lycos\.com\/lycos\/mail\/MailCompose\.lycos$/.test(srcUrl) &&
            /\.lycosmail\.lycos\.com$/.test(destOrigin) &&
            Legacy.getPref("filterXExceptions.lycosmail")) {
            logEx("Lycos Mail exception");
            return true;
          }

          if (/\.livejournal\.com$/.test(srcOrigin) &&
            /^https?:\/\/www\.livejournal\.com\/talkpost_do\.bml$/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.livejournal")) {
            logEx("Livejournal comments exception");
            return true;
          }

          if (srcOrigin == "https://ssl.rapidshare.com" &&
            xssReq.srcDomain == "rapidshare.com") {
            logEx("Rapidshare upload exception");
            return true;
          }

          if (srcOrigin == "http://wm.letitbit.net" &&
            /^http:\/\/http\.letitbit\.net:81\/cgi-bin\/multi\/upload\.cgi\?/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.letitibit")
          ) {
            logEx("letitbit.net upload exception");
            return true;
          }

          if (/\.deviantart\.com$/.test(srcOrigin) &&
            /^http:\/\/my\.deviantart\.com\/journal\/update\b/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.deviantart")
          ) {
            logEx("deviantart.com journal post exception");
            return true;
          }

          if (srcOrigin == "https://www.mymedicare.gov" &&
            destOrigin == "https://myporal.medicare.gov" &&
            Legacy.getPref("filterXExceptions.medicare")
          ) {
            logEx("mymedicare.gov exception");
            return true;
          }

          if (/^https?:\/\/(?:draft|www)\.blogger\.com\/template-editor\.g\?/.test(srcUrl) &&
            /^https?:\/\/[\w\-]+\.blogspot\.com\/b\/preview\?/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.blogspot")
          ) {
            logEx("blogspot.com template preview exception");
            return true;
          }

          if (/^https?:\/\/www\.readability\.com\/articles\/queue$/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.readability")) {
            logEx("Readability exception");
            return true;
          }

          if (/^https?:\/\/pdf\.printfriendly\.com\/pdfs\/make$/.test(destUrl) &&
            Legacy.getPref("filterXExceptions.printfriendly")) {
            logEx("Printfriendly exception");
            return true;
          }
        }
      }
    },

    isBadException(host) {
      // TLD check for Google search
      let m = host.match(/\bgoogle\.((?:[a-z]{1,3}\.)?[a-z]+)$/i);
      return m && tld.getPublicSuffix(host) != m[1];
    },

    partial(xssReq) {
      let {
        srcObj,
        destObj,
        srcUrl,
        destUrl,
        srcOrigin,
        destOrigin,
      } = xssReq;

      let skipParams, skipRx;
      if (/^https:\/\/www\.paypal\.com\/(?:[\w\-]+\/)?cgi-bin\/webscr\b/.test(destUrl)) {
        // Paypal buttons encrypted parameter causes a DOS, strip it out
        skipParams = ['encrypted'];
      } else if (/\.adnxs\.com$/.test(srcOrigin) && /\.adnxs\.com$/.test(destOrigin)) {
        skipParams = ['udj'];
      } else if (/^https?:\/\/www\.mendeley\.com\/import\/bookmarklet\/$/.test(destUrl)) {
        skipParams = ['html'];
      } else if (destObj.hash && /^https:/.test(srcOrigin) &&
        (/^https?:\/\/api\.facebook\.com\//.test(srcUrl) ||
          /^https:\/\/tbpl\.mozilla\.org\//.test(srcUrl) || // work-around for hg reftest DOS
          /^https:\/\/[^\/]+\.googleusercontent\.com\/gadgets\/ifr\?/.test(destUrl) // Google gadgets
        )) {
        skipRx = /#[^#]+$/; // remove receiver's hash
      } else if (/^https?:\/\/apps\.facebook\.com\//.test(srcUrl) && Legacy.getPref("filterXExceptions.fbconnect")) {
        skipRx = /&invite_url=javascript[^&]+/; // Zynga stuff
      } else if (/^https?:\/\/l\.yimg\.com\/j\/static\/frame\?e=/.test(destUrl) &&
        /\.yahoo\.com$/.test(srcOrigin) &&
        Legacy.getPref("filterXExceptions.yahoo")) {
        skipParams = ['e'];
      } else if (/^https?:\/\/wpcomwidgets\.com\/\?/.test(destUrl)) {
        skipParams = ["_data"];
      } else if (/^https:\/\/docs\.google\.com\/picker\?/.test(destUrl)) {
        skipParams = ["nav", "pp"];
      } else if (/^https:\/\/.*[\?&]scope=/.test(destUrl)) {
        skipRx = /[\?&]scope=[+\w]+(?=&|$)/;
      }
      if (skipParams) {
        skipRx = new RegExp("(?:^|[&?])(?:" + skipParams.join('|') + ")=[^&]+", "g");
      }
      return {
        skipParams,
        skipRx
      };
    }

  };
  return Exceptions;
})();