diff --git a/lib/ace/mode/_test/tokens_csp.json b/lib/ace/mode/_test/tokens_csp.json new file mode 100644 index 00000000000..d80077aafd2 --- /dev/null +++ b/lib/ace/mode/_test/tokens_csp.json @@ -0,0 +1,94 @@ +[[ + "start", + ["constant.language","child-src"] +],[ + "start", + ["constant.language","connect-src"] +],[ + "start", + ["constant.language","default-src"] +],[ + "start", + ["constant.language","font-src"] +],[ + "start", + ["constant.language","frame-src"] +],[ + "start", + ["constant.language","img-src"] +],[ + "start", + ["constant.language","manifest-src"] +],[ + "start", + ["constant.language","media-src"] +],[ + "start", + ["constant.language","object-src"] +],[ + "start", + ["constant.language","script-src"] +],[ + "start", + ["constant.language","style-src"] +],[ + "start", + ["constant.language","worker-src"] +],[ + "start", + ["constant.language","base-uri"] +],[ + "start", + ["constant.language","plugin-types"] +],[ + "start", + ["constant.language","sandbox"] +],[ + "start", + ["constant.language","disown-opener"] +],[ + "start", + ["constant.language","form-action"] +],[ + "start", + ["constant.language","frame-ancestors"] +],[ + "start", + ["constant.language","report-uri"] +],[ + "start", + ["constant.language","report-to"] +],[ + "start", + ["constant.language","upgrade-insecure-requests"] +],[ + "start", + ["constant.language","block-all-mixed-content"] +],[ + "start", + ["constant.language","require-sri-for"] +],[ + "start", + ["constant.language","reflected-xss"] +],[ + "start", + ["constant.language","referrer"] +],[ + "start", + ["constant.language","policy-uri"] +],[ + "start", + ["variable","'self'"] +],[ + "start", + ["variable","'unsafe-inline'"] +],[ + "start", + ["variable","'unsafe-eval'"] +],[ + "start", + ["variable","'strict-dynamic'"] +],[ + "start", + ["variable","'unsafe-hashed-attributes'"] +]] \ No newline at end of file diff --git a/lib/ace/mode/csp.js b/lib/ace/mode/csp.js new file mode 100644 index 00000000000..529bb735406 --- /dev/null +++ b/lib/ace/mode/csp.js @@ -0,0 +1,53 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +/* + THIS FILE WAS AUTOGENERATED BY mode.tmpl.js +*/ + +define(function(require, exports, module) { + "use strict"; + + var TextMode = require("./text").Mode; + var CspHighlightRules = require("./csp_highlight_rules").CspHighlightRules; + var oop = require("../lib/oop"); + + var Mode = function() { + this.HighlightRules = CspHighlightRules; + }; + + oop.inherits(Mode, TextMode); + + (function() { + this.$id = "ace/mode/csp"; + }).call(Mode.prototype); + + exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/csp_highlight_rules.js b/lib/ace/mode/csp_highlight_rules.js new file mode 100644 index 00000000000..19f4786878f --- /dev/null +++ b/lib/ace/mode/csp_highlight_rules.js @@ -0,0 +1,70 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +/* + EXPLANATION + + This highlight rules were created to help developer spot typos when working + with Content-Security-Policy (CSP). See: + https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/ + */ + +define(function(require, exports, module) { + "use strict"; + + var oop = require("../lib/oop"); + var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + + var CspHighlightRules = function() { + var keywordMapper = this.createKeywordMapper({ + "constant.language": "child-src|connect-src|default-src|font-src|frame-src|img-src|manifest-src|media-src|object-src" + + "|script-src|style-src|worker-src|base-uri|plugin-types|sandbox|disown-opener|form-action|frame-ancestors|report-uri" + + "|report-to|upgrade-insecure-requests|block-all-mixed-content|require-sri-for|reflected-xss|referrer|policy-uri", + "variable": "'none'|'self'|'unsafe-inline'|'unsafe-eval'|'strict-dynamic'|'unsafe-hashed-attributes'" + }, "identifier", true); + + this.$rules = { + start: [{ + token: "string.link", + regex: /https?:[^;\s]*/ + }, { + token: "operator.punctuation", + regex: /;/ + }, { + token: keywordMapper, + regex: /[^\s;]+/ + }] + }; + }; + + oop.inherits(CspHighlightRules, TextHighlightRules); + + exports.CspHighlightRules = CspHighlightRules; +}); \ No newline at end of file diff --git a/lib/ace/snippets/csp.js b/lib/ace/snippets/csp.js new file mode 100644 index 00000000000..359d9103986 --- /dev/null +++ b/lib/ace/snippets/csp.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./.snippets"); +exports.scope = ""; + +});