Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(705)

Unified Diff: Source/core/dom/SandboxFlags.cpp

Issue 27073003: CSP Suborigins Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/SandboxFlags.cpp
diff --git a/Source/core/dom/SandboxFlags.cpp b/Source/core/dom/SandboxFlags.cpp
index 8d8e01c2f7971c60a5cb31dd3e1df6f1aa0d0f6c..c6b531c627fc60efde69e3a94782ca91aaabc9de 100644
--- a/Source/core/dom/SandboxFlags.cpp
+++ b/Source/core/dom/SandboxFlags.cpp
@@ -91,4 +91,43 @@ SandboxFlags parseSandboxPolicy(const String& policy, String& invalidTokensError
return flags;
}
+String parseSuboriginName(const String& policy, String& invalidTokensErrorMessage)
+{
+ // Parse the name of the suborigin (no spaces, single string)
+ unsigned length = policy.length();
+ unsigned start = 0;
+ while (start < length && isHTMLSpace<UChar>(policy[start]))
+ ++start;
+
+ if (start >= length) {
+ invalidTokensErrorMessage = "No suborigin name specified.";
+ return "";
+ }
+
+ unsigned end = start + 1;
+ while (end < length && !isHTMLSpace<UChar>(policy[end])) {
+ if (!isASCIIAlphanumeric<UChar>(policy[end])) {
+ invalidTokensErrorMessage = "Invalid character \'" + policy.substring(end, 1) + "\' in suborigin.";
+ }
+ ++end;
+ }
+
+ if (start >= end) {
+ invalidTokensErrorMessage = "Empty suborigin name specified.";
+ return "";
+ }
+
+ unsigned finalSpaces = end + 1;
+ // Make sure there is nothing else specified after the final space.
+ while (finalSpaces < length && isHTMLSpace<UChar>(policy[finalSpaces]))
+ ++finalSpaces;
+
+ if (finalSpaces < length) {
+ invalidTokensErrorMessage = "There cannot be any spaces in the suborigin name.";
+ return "";
+ }
+
+ return policy.substring(start, end - start);
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698