Attachment #800031: bug-607067.patch for bug #607067

View | Details | Raw Unified | Return to bug 607067
Collapse All | Expand All

(-)a/browser/devtools/webconsole/test/browser_webconsole_bug_770099_violation.js (-1 / +1 lines)
Line     Link Here 
 Lines 3-19    Link Here 
3
 * Any copyright is dedicated to the Public Domain.
3
 * Any copyright is dedicated to the Public Domain.
4
 * http://creativecommons.org/publicdomain/zero/1.0/
4
 * http://creativecommons.org/publicdomain/zero/1.0/
5
 *
5
 *
6
 * ***** END LICENSE BLOCK ***** */
6
 * ***** END LICENSE BLOCK ***** */
7
7
8
// Tests that the Web Console CSP messages are displayed
8
// Tests that the Web Console CSP messages are displayed
9
9
10
const TEST_VIOLATION = "https://example.com/browser/browser/devtools/webconsole/test/test_bug_770099_violation.html";
10
const TEST_VIOLATION = "https://example.com/browser/browser/devtools/webconsole/test/test_bug_770099_violation.html";
11
const CSP_VIOLATION_MSG = "Content Security Policy: Directive default-src https://example.com:443 violated by http://some.example.com/test.png"
11
const CSP_VIOLATION_MSG = 'Content Security Policy: The page\'s settings blocked the loading of a resource at http://some.example.com/test.png ("default-src https://example.com:443").'
12
12
13
let hud = undefined;
13
let hud = undefined;
14
14
15
function test() {
15
function test() {
16
  addTab("data:text/html;charset=utf8,Web Console CSP violation test");
16
  addTab("data:text/html;charset=utf8,Web Console CSP violation test");
17
  browser.addEventListener("load", function _onLoad() {
17
  browser.addEventListener("load", function _onLoad() {
18
    browser.removeEventListener("load", _onLoad, true);
18
    browser.removeEventListener("load", _onLoad, true);
19
    openConsole(null, loadDocument);
19
    openConsole(null, loadDocument);
(-)a/content/base/src/CSPUtils.jsm (-11 / +11 lines)
Line     Link Here 
 Lines 293-309   CSPRep.fromString = function(aStr, self, Link Here 
293
      // grab value tokens and interpret them
293
      // grab value tokens and interpret them
294
      var options = dirvalue.split(/\s+/);
294
      var options = dirvalue.split(/\s+/);
295
      for each (var opt in options) {
295
      for each (var opt in options) {
296
        if (opt === "inline-script")
296
        if (opt === "inline-script")
297
          aCSPR._allowInlineScripts = true;
297
          aCSPR._allowInlineScripts = true;
298
        else if (opt === "eval-script")
298
        else if (opt === "eval-script")
299
          aCSPR._allowEval = true;
299
          aCSPR._allowEval = true;
300
        else
300
        else
301
          cspWarn(aCSPR, CSPLocalizer.getFormatStr("doNotUnderstandOption",
301
          cspWarn(aCSPR, CSPLocalizer.getFormatStr("ignoringUnknownOption",
302
                                                   [opt]));
302
                                                   [opt]));
303
      }
303
      }
304
      continue directive;
304
      continue directive;
305
    }
305
    }
306
306
307
    // ALLOW DIRECTIVE //////////////////////////////////////////////////
307
    // ALLOW DIRECTIVE //////////////////////////////////////////////////
308
    // parse "allow" as equivalent to "default-src", at least until the spec
308
    // parse "allow" as equivalent to "default-src", at least until the spec
309
    // stabilizes, at which time we can stop parsing "allow"
309
    // stabilizes, at which time we can stop parsing "allow"
 Lines 356-382   CSPRep.fromString = function(aStr, self, Link Here 
356
356
357
          // Verify that each report URI is in the same etld + 1 and that the
357
          // Verify that each report URI is in the same etld + 1 and that the
358
          // scheme and port match "self" if "self" is defined, and just that
358
          // scheme and port match "self" if "self" is defined, and just that
359
          // it's valid otherwise.
359
          // it's valid otherwise.
360
          if (self) {
360
          if (self) {
361
            if (gETLDService.getBaseDomain(uri) !==
361
            if (gETLDService.getBaseDomain(uri) !==
362
                gETLDService.getBaseDomain(selfUri)) {
362
                gETLDService.getBaseDomain(selfUri)) {
363
              cspWarn(aCSPR,
363
              cspWarn(aCSPR,
364
                      CSPLocalizer.getFormatStr("notETLDPlus1",
364
                      CSPLocalizer.getFormatStr("reportURInotETLDPlus1",
365
                                            [gETLDService.getBaseDomain(uri)]));
365
                                                [gETLDService.getBaseDomain(uri)]));
366
              continue;
366
              continue;
367
            }
367
            }
368
            if (!uri.schemeIs(selfUri.scheme)) {
368
            if (!uri.schemeIs(selfUri.scheme)) {
369
              cspWarn(aCSPR, CSPLocalizer.getFormatStr("notSameScheme",
369
              cspWarn(aCSPR, CSPLocalizer.getFormatStr("reportURInotSameSchemeAsSelf",
370
                                                       [uri.asciiSpec]));
370
                                                       [uri.asciiSpec]));
371
              continue;
371
              continue;
372
            }
372
            }
373
            if (uri.port && uri.port !== selfUri.port) {
373
            if (uri.port && uri.port !== selfUri.port) {
374
              cspWarn(aCSPR, CSPLocalizer.getFormatStr("notSamePort",
374
              cspWarn(aCSPR, CSPLocalizer.getFormatStr("reportURInotSamePortAsSelf",
375
                                                       [uri.asciiSpec]));
375
                                                       [uri.asciiSpec]));
376
              continue;
376
              continue;
377
            }
377
            }
378
          }
378
          }
379
        } catch(e) {
379
        } catch(e) {
380
          switch (e.result) {
380
          switch (e.result) {
381
            case Components.results.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS:
381
            case Components.results.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS:
382
            case Components.results.NS_ERROR_HOST_IS_IP_ADDRESS:
382
            case Components.results.NS_ERROR_HOST_IS_IP_ADDRESS:
 Lines 615-643   CSPRep.fromStringSpecCompliant = functio Link Here 
615
615
616
          // Verify that each report URI is in the same etld + 1 and that the
616
          // Verify that each report URI is in the same etld + 1 and that the
617
          // scheme and port match "self" if "self" is defined, and just that
617
          // scheme and port match "self" if "self" is defined, and just that
618
          // it's valid otherwise.
618
          // it's valid otherwise.
619
          if (self) {
619
          if (self) {
620
            if (gETLDService.getBaseDomain(uri) !==
620
            if (gETLDService.getBaseDomain(uri) !==
621
                gETLDService.getBaseDomain(selfUri)) {
621
                gETLDService.getBaseDomain(selfUri)) {
622
              cspWarn(aCSPR, 
622
              cspWarn(aCSPR, 
623
                      CSPLocalizer.getFormatStr("notETLDPlus1",
623
                      CSPLocalizer.getFormatStr("reportURInotETLDPlus1",
624
                                            [gETLDService.getBaseDomain(uri)]));
624
                                                [gETLDService.getBaseDomain(uri)]));
625
              continue;
625
              continue;
626
            }
626
            }
627
            if (!uri.schemeIs(selfUri.scheme)) {
627
            if (!uri.schemeIs(selfUri.scheme)) {
628
              cspWarn(aCSPR, 
628
              cspWarn(aCSPR,
629
                      CSPLocalizer.getFormatStr("notSameScheme",
629
                      CSPLocalizer.getFormatStr("reportURInotSameSchemeAsSelf",
630
                                                [uri.asciiSpec]));
630
                                                [uri.asciiSpec]));
631
              continue;
631
              continue;
632
            }
632
            }
633
            if (uri.port && uri.port !== selfUri.port) {
633
            if (uri.port && uri.port !== selfUri.port) {
634
              cspWarn(aCSPR, 
634
              cspWarn(aCSPR,
635
                      CSPLocalizer.getFormatStr("notSamePort",
635
                      CSPLocalizer.getFormatStr("reportURInotSamePortAsSelf",
636
                                                [uri.asciiSpec]));
636
                                                [uri.asciiSpec]));
637
              continue;
637
              continue;
638
            }
638
            }
639
          }
639
          }
640
        } catch(e) {
640
        } catch(e) {
641
          switch (e.result) {
641
          switch (e.result) {
642
            case Components.results.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS:
642
            case Components.results.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS:
643
            case Components.results.NS_ERROR_HOST_IS_IP_ADDRESS:
643
            case Components.results.NS_ERROR_HOST_IS_IP_ADDRESS:
(-)a/content/base/src/contentSecurityPolicy.js (-5 / +5 lines)
Line     Link Here 
 Lines 175-203   ContentSecurityPolicy.prototype = { Link Here 
175
  logViolationDetails:
175
  logViolationDetails:
176
  function(aViolationType, aSourceFile, aScriptSample, aLineNum) {
176
  function(aViolationType, aSourceFile, aScriptSample, aLineNum) {
177
    // allowsInlineScript and allowsEval both return true when report-only mode
177
    // allowsInlineScript and allowsEval both return true when report-only mode
178
    // is enabled, resulting in a call to this function. Therefore we need to
178
    // is enabled, resulting in a call to this function. Therefore we need to
179
    // check that the policy was in fact violated before logging any violations
179
    // check that the policy was in fact violated before logging any violations
180
    switch (aViolationType) {
180
    switch (aViolationType) {
181
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_INLINE_STYLE:
181
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_INLINE_STYLE:
182
      if (!this._policy.allowsInlineStyles)
182
      if (!this._policy.allowsInlineStyles)
183
        this._asyncReportViolation('self',null,'inline style base restriction',
183
        this._asyncReportViolation('self', null, CSPLocalizer.getStr("inlineStyleBlocked"),
184
                                   'violated base restriction: Inline Stylesheets will not apply',
184
                                   'violated base restriction: Inline Stylesheets will not apply',
185
                                   aSourceFile, aScriptSample, aLineNum);
185
                                   aSourceFile, aScriptSample, aLineNum);
186
      break;
186
      break;
187
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_INLINE_SCRIPT:
187
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_INLINE_SCRIPT:
188
      if (!this._policy.allowsInlineScripts)
188
      if (!this._policy.allowsInlineScripts)
189
        this._asyncReportViolation('self', null, 'inline script base restriction',
189
        this._asyncReportViolation('self', null, CSPLocalizer.getStr("inlineScriptBlocked"),
190
                                   'violated base restriction: Inline Scripts will not execute',
190
                                   'violated base restriction: Inline Scripts will not execute',
191
                                   aSourceFile, aScriptSample, aLineNum);
191
                                   aSourceFile, aScriptSample, aLineNum);
192
      break;
192
      break;
193
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_EVAL:
193
    case Ci.nsIContentSecurityPolicy.VIOLATION_TYPE_EVAL:
194
      if (!this._policy.allowsEvalInScripts)
194
      if (!this._policy.allowsEvalInScripts)
195
        this._asyncReportViolation('self', null, 'eval script base restriction',
195
        this._asyncReportViolation('self', null, CSPLocalizer.getStr("scriptFromStringBlocked"),
196
                                   'violated base restriction: Code will not be created from strings',
196
                                   'violated base restriction: Code will not be created from strings',
197
                                   aSourceFile, aScriptSample, aLineNum);
197
                                   aSourceFile, aScriptSample, aLineNum);
198
      break;
198
      break;
199
    }
199
    }
200
  },
200
  },
201
201
202
  set reportOnlyMode(val) {
202
  set reportOnlyMode(val) {
203
    this._reportOnlyMode = val;
203
    this._reportOnlyMode = val;
 Lines 357-375   ContentSecurityPolicy.prototype = { Link Here 
357
      if (aLineNum)
357
      if (aLineNum)
358
        report["csp-report"]["line-number"] = aLineNum;
358
        report["csp-report"]["line-number"] = aLineNum;
359
359
360
      var reportString = JSON.stringify(report);
360
      var reportString = JSON.stringify(report);
361
      CSPdebug("Constructed violation report:\n" + reportString);
361
      CSPdebug("Constructed violation report:\n" + reportString);
362
362
363
      var violationMessage = null;
363
      var violationMessage = null;
364
      if (blockedUri["asciiSpec"]) {
364
      if (blockedUri["asciiSpec"]) {
365
         violationMessage = CSPLocalizer.getFormatStr("directiveViolatedWithURI", [violatedDirective, blockedUri.asciiSpec]);
365
         violationMessage = CSPLocalizer.getFormatStr("CSPViolationWithURI", [violatedDirective, blockedUri.asciiSpec]);
366
      } else {
366
      } else {
367
         violationMessage = CSPLocalizer.getFormatStr("directiveViolated", [violatedDirective]);
367
         violationMessage = CSPLocalizer.getFormatStr("CSPViolation", [violatedDirective]);
368
      }
368
      }
369
      this._policy.log(WARN_FLAG, violationMessage,
369
      this._policy.log(WARN_FLAG, violationMessage,
370
                        (aSourceFile) ? aSourceFile : null,
370
                        (aSourceFile) ? aSourceFile : null,
371
                        (aScriptSample) ? decodeURIComponent(aScriptSample) : null,
371
                        (aScriptSample) ? decodeURIComponent(aScriptSample) : null,
372
                        (aLineNum) ? aLineNum : null);
372
                        (aLineNum) ? aLineNum : null);
373
373
374
      // For each URI in the report list, send out a report.
374
      // For each URI in the report list, send out a report.
375
      // We make the assumption that all of the URIs are absolute URIs; this
375
      // We make the assumption that all of the URIs are absolute URIs; this
(-)a/dom/locales/en-US/chrome/security/csp.properties (-14 / +21 lines)
Line     Link Here 
 Lines 1-59    Link Here 
1
# This Source Code Form is subject to the terms of the Mozilla Public
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
4
5
# CSP Warnings:
5
# CSP Warnings:
6
# LOCALIZATION NOTE (directiveViolated):
6
# LOCALIZATION NOTE (CSPViolation):
7
# %1$S is the directive that has been violated.
7
# %1$S is the reason why the resource has not been loaded.
8
directiveViolated = Directive %1$S violated
8
CSPViolation = The page's settings blocked the loading of a resource: %1$S
9
# LOCALIZATION NOTE (directiveViolatedWithURI):
9
# LOCALIZATION NOTE (CSPViolationWithURI):
10
# %1$S is the directive that has been violated.
10
# %1$S is the directive that has been violated.
11
# %2$S is the URI of the resource which violated the directive.
11
# %2$S is the URI of the resource which violated the directive.
12
directiveViolatedWithURI = Directive %1$S violated by %2$S
12
CSPViolationWithURI = The page's settings blocked the loading of a resource at %2$S ("%1$S").
13
# LOCALIZATION NOTE (triedToSendReport):
13
# LOCALIZATION NOTE (triedToSendReport):
14
# %1$S is the URI we attempted to send a report to.
14
# %1$S is the URI we attempted to send a report to.
15
triedToSendReport = Tried to send report to invalid URI: "%1$S"
15
triedToSendReport = Tried to send report to invalid URI: "%1$S"
16
# LOCALIZATION NOTE (errorWas):
16
# LOCALIZATION NOTE (errorWas):
17
# %1$S is the error resulting from attempting to send the report
17
# %1$S is the error resulting from attempting to send the report
18
errorWas = error was: "%1$S"
18
errorWas = error was: "%1$S"
19
# LOCALIZATION NOTE (couldNotParseReportURI):
19
# LOCALIZATION NOTE (couldNotParseReportURI):
20
# %1$S is the report URI that could not be parsed
20
# %1$S is the report URI that could not be parsed
21
couldNotParseReportURI = couldn't parse report URI: %1$S
21
couldNotParseReportURI = couldn't parse report URI: %1$S
22
# LOCALIZATION NOTE (couldNotProcessUnknownDirective):
22
# LOCALIZATION NOTE (couldNotProcessUnknownDirective):
23
# %1$S is the unknown directive
23
# %1$S is the unknown directive
24
couldNotProcessUnknownDirective = Couldn't process unknown directive '%1$S'
24
couldNotProcessUnknownDirective = Couldn't process unknown directive '%1$S'
25
# LOCALIZATION NOTE (doNotUnderstandOption):
25
# LOCALIZATION NOTE (ignoringUnknownOption):
26
# %1$S is the option that could not be understood
26
# %1$S is the option that could not be understood
27
doNotUnderstandOption = don't understand option '%1$S'.  Ignoring it.
27
ignoringUnknownOption = Ignoring unknown option %1$S
28
# LOCALIZATION NOTE (notETLDPlus1):
28
# LOCALIZATION NOTE (reportURInotETLDPlus1):
29
# %1$S is the ETLD of the report URI that could not be used
29
# %1$S is the ETLD of the report URI that could not be used
30
notETLDPlus1 = can't use report URI from non-matching eTLD+1: %1$S
30
reportURInotETLDPlus1 = The report URI (%1$S) must be from the same eTLD+1.
31
# LOCALIZATION NOTE (notSameScheme):
31
# LOCALIZATION NOTE (reportURInotSameSchemeAsSelf, reportURInotSamePortAsSelf):
32
# %1$S is the report URI that could not be used
32
# %1$S is the report URI that could not be used
33
notSameScheme = can't use report URI with different scheme from originating document: %1$S
33
reportURInotSameSchemeAsSelf = The report URI (%1$S) must use the same scheme as the originating document.
34
# LOCALIZATION NOTE (notSamePort):
34
reportURInotSamePortAsSelf = The report URI (%1$S) must use the same port as the originating document.
35
# %1$S is the report URI that could not be used
36
notSamePort = can't use report URI with different port from originating document: %1$S
37
# LOCALIZATION NOTE (pageCannotSendReportsTo):
35
# LOCALIZATION NOTE (pageCannotSendReportsTo):
38
# %1$S is the URI of the page with the policy
36
# %1$S is the URI of the page with the policy
39
# %2$S is the report URI that could not be used
37
# %2$S is the report URI that could not be used
40
pageCannotSendReportsTo = page on %1$S cannot send reports to %2$S
38
pageCannotSendReportsTo = page on %1$S cannot send reports to %2$S
41
allowOrDefaultSrcRequired = 'allow' or 'default-src' directive required but not present.  Reverting to "default-src 'none'"
39
allowOrDefaultSrcRequired = 'allow' or 'default-src' directive required but not present.  Reverting to "default-src 'none'"
42
# LOCALIZATION NOTE (failedToParseUnrecognizedSource):
40
# LOCALIZATION NOTE (failedToParseUnrecognizedSource):
43
# %1$S is the CSP Source that could not be parsed
41
# %1$S is the CSP Source that could not be parsed
44
failedToParseUnrecognizedSource = Failed to parse unrecognized source %1$S
42
failedToParseUnrecognizedSource = Failed to parse unrecognized source %1$S
45
# LOCALIZATION NOTE (reportPostRedirect):
43
# LOCALIZATION NOTE (reportPostRedirect):
46
# %1$S is the specified report URI before redirect
44
# %1$S is the specified report URI before redirect
47
reportPostRedirect = Post of violation report to %1$S failed, as a redirect occurred
45
reportPostRedirect = Post of violation report to %1$S failed, as a redirect occurred
48
# LOCALIZATION NOTE (allowDirectiveIsDeprecated):
46
# LOCALIZATION NOTE (allowDirectiveIsDeprecated):
49
# Don't translate "allow" and "default-src" as they are keywords and part of
47
# Don't translate "allow" and "default-src" as they are keywords and part of
50
# the CSP protocol syntax.
48
# the CSP protocol syntax.
51
allowDirectiveIsDeprecated = allow directive is deprecated, use the equivalent default-src directive instead
49
allowDirectiveIsDeprecated = allow directive is deprecated, use the equivalent default-src directive instead
50
# LOCALIZATION NOTE (inlineScriptBlocked):
51
# inline script refers to JavaScript code that is embedded into the HTML document.
52
inlineScriptBlocked = An attempt to execute inline scripts has been blocked
53
# LOCALIZATION NOTE (inlineStyleBlocked):
54
# inline style refers to CSS code that is embedded into the HTML document.
55
inlineStyleBlocked = An attempt to apply inline style sheets has been blocked
56
# LOCALIZATION NOTE (scriptFromStringBlocked):
57
# eval is a name and should not be localized.
58
scriptFromStringBlocked = An attempt to call JavaScript from a string (by calling a function like eval) has been blocked
52
59
53
# CSP Errors:
60
# CSP Errors:
54
policyURINotAlone = policy-uri directive can only appear alone
61
policyURINotAlone = policy-uri directive can only appear alone
55
noParentRequest = The policy-uri cannot be fetched without a parent request and a CSP.
62
noParentRequest = The policy-uri cannot be fetched without a parent request and a CSP.
56
# LOCALIZATION NOTE (policyURIParseError):
63
# LOCALIZATION NOTE (policyURIParseError):
57
# %1$S is the URI that could not be parsed
64
# %1$S is the URI that could not be parsed
58
policyURIParseError = could not parse URI in policy URI: %1$S
65
policyURIParseError = could not parse URI in policy URI: %1$S
59
# LOCALIZATION NOTE (nonMatchingHost):
66
# LOCALIZATION NOTE (nonMatchingHost):

Return to bug 607067