From aa34ed466abc6ccb4aa577caf81a828d753233a0 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 11 Mar 2022 12:48:53 +0100 Subject: make the order of rules in generated CSP deterministic This is purely to help with automated testing. --- common/policy.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/policy.js b/common/policy.js index 47b2d1d..e14d8cd 100644 --- a/common/policy.js +++ b/common/policy.js @@ -52,9 +52,13 @@ function make_csp(nonce) { const rule = nonce ? `nonce-${nonce}` : "none"; - const csp_dict = {"prefetch-src": "none", "script-src-attr": "none"}; - Object.assign(csp_dict, {"script-src": rule, "script-src-elem": rule}); - return Object.entries(csp_dict).map(([a, b]) => `${a} '${b}';`).join(" "); + const csp_list = [ + ["prefetch-src", "none"], + ["script-src-attr", "none"], + ["script-src", rule], + ["script-src-elem", rule] + ]; + return csp_list.map(([a, b]) => `${a} '${b}';`).join(" "); } function decide_policy(patterns_tree, url, default_allow, secret) -- cgit v1.2.3