Backed out changeset 8acb67f2e136 (bug 1331838) for failing GTest CSPParser.SimplePolicies. r=backout on a CLOSED TREE
authorSebastian Hengst <archaeopteryx@coole-files.de>
Wed, 18 Jan 2017 17:28:03 +0100
changeset 377249 7715d62057e50fdafddeca167ecf2d1dbd79b35b
parent 377248 4be42c91eaa26c699a2aac9f4bc41213490051c1
child 377250 96cb95af530477edb66ae48d98c18533476e57bb
child 377316 7040329487e94de37890d010cfa9626c7b93a9b6
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1331838
milestone53.0a1
backs out8acb67f2e136fd063ab8c2c5b8574b1656da187e
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 8acb67f2e136 (bug 1331838) for failing GTest CSPParser.SimplePolicies. r=backout on a CLOSED TREE
dom/security/nsCSPParser.cpp
dom/security/nsCSPParser.h
--- a/dom/security/nsCSPParser.cpp
+++ b/dom/security/nsCSPParser.cpp
@@ -37,16 +37,18 @@ static const char16_t SEMICOLON    = ';'
 static const char16_t SLASH        = '/';
 static const char16_t PLUS         = '+';
 static const char16_t DASH         = '-';
 static const char16_t DOT          = '.';
 static const char16_t UNDERLINE    = '_';
 static const char16_t TILDE        = '~';
 static const char16_t WILDCARD     = '*';
 static const char16_t SINGLEQUOTE  = '\'';
+static const char16_t OPEN_CURL    = '{';
+static const char16_t CLOSE_CURL   = '}';
 static const char16_t NUMBER_SIGN  = '#';
 static const char16_t QUESTIONMARK = '?';
 static const char16_t PERCENT_SIGN = '%';
 static const char16_t EXCLAMATION  = '!';
 static const char16_t DOLLAR       = '$';
 static const char16_t AMPERSAND    = '&';
 static const char16_t OPENBRACE    = '(';
 static const char16_t CLOSINGBRACE = ')';
@@ -519,16 +521,36 @@ nsCSPParser::host()
     logWarningErrorToConsole(nsIScriptError::warningFlag, "hostNameMightBeKeyword",
                              params, ArrayLength(params));
   }
 
   // Create a new nsCSPHostSrc with the parsed host.
   return new nsCSPHostSrc(mCurValue);
 }
 
+// apps use special hosts; "app://{app-host-is-uid}""
+nsCSPHostSrc*
+nsCSPParser::appHost()
+{
+  CSPPARSERLOG(("nsCSPParser::appHost, mCurToken: %s, mCurValue: %s",
+               NS_ConvertUTF16toUTF8(mCurToken).get(),
+               NS_ConvertUTF16toUTF8(mCurValue).get()));
+
+  while (hostChar()) { /* consume */ }
+
+  // appHosts have to end with "}", otherwise we have to report an error
+  if (!accept(CLOSE_CURL)) {
+    const char16_t* params[] = { mCurToken.get() };
+    logWarningErrorToConsole(nsIScriptError::warningFlag, "couldntParseInvalidSource",
+                             params, ArrayLength(params));
+    return nullptr;
+  }
+  return new nsCSPHostSrc(mCurValue);
+}
+
 // keyword-source = "'self'" / "'unsafe-inline'" / "'unsafe-eval'"
 nsCSPBaseSrc*
 nsCSPParser::keywordSource()
 {
   CSPPARSERLOG(("nsCSPParser::keywordSource, mCurToken: %s, mCurValue: %s",
                NS_ConvertUTF16toUTF8(mCurToken).get(),
                NS_ConvertUTF16toUTF8(mCurValue).get()));
 
@@ -588,16 +610,23 @@ nsCSPParser::keywordSource()
 // host-source = [ scheme "://" ] host [ port ] [ path ]
 nsCSPHostSrc*
 nsCSPParser::hostSource()
 {
   CSPPARSERLOG(("nsCSPParser::hostSource, mCurToken: %s, mCurValue: %s",
                NS_ConvertUTF16toUTF8(mCurToken).get(),
                NS_ConvertUTF16toUTF8(mCurValue).get()));
 
+  // Special case handling for app specific hosts
+  if (accept(OPEN_CURL)) {
+    // If appHost() returns null, the error was handled in appHost().
+    // appHosts can not have a port, or path, we can return.
+    return appHost();
+  }
+
   nsCSPHostSrc* cspHost = host();
   if (!cspHost) {
     // Error was reported in host()
     return nullptr;
   }
 
   // Calling port() to see if there is a port to parse, if an error
   // occurs, port() reports the error, if port() returns true;
--- a/dom/security/nsCSPParser.h
+++ b/dom/security/nsCSPParser.h
@@ -128,16 +128,17 @@ class nsCSPParser {
     void                sandboxFlagList(nsCSPDirective* aDir);
     void                sourceList(nsTArray<nsCSPBaseSrc*>& outSrcs);
     nsCSPBaseSrc*       sourceExpression();
     nsCSPSchemeSrc*     schemeSource();
     nsCSPHostSrc*       hostSource();
     nsCSPBaseSrc*       keywordSource();
     nsCSPNonceSrc*      nonceSource();
     nsCSPHashSrc*       hashSource();
+    nsCSPHostSrc*       appHost(); // helper function to support app specific hosts
     nsCSPHostSrc*       host();
     bool                hostChar();
     bool                schemeChar();
     bool                port();
     bool                path(nsCSPHostSrc* aCspHost);
 
     bool subHost();                                         // helper function to parse subDomains
     bool atValidUnreservedChar();                           // helper function to parse unreserved