@appwarden/middleware 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/{chunk-FGAJVKNM.js → chunk-A5XGYLYS.js} +51 -5
- package/cloudflare.js +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @appwarden/middleware
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
[](https://www.npmjs.com/package/@appwarden/middleware)
|
|
5
5
|
[](https://docs.npmjs.com/generating-provenance-statements)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -75,6 +75,47 @@ var UseCSPInputSchema = z2.object({
|
|
|
75
75
|
{ path: ["directives"], message: "DirectivesRequired" /* DirectivesRequired */ }
|
|
76
76
|
);
|
|
77
77
|
|
|
78
|
+
// src/utils/cloudflare/csp-keywords.ts
|
|
79
|
+
var CSP_KEYWORDS = [
|
|
80
|
+
"self",
|
|
81
|
+
"none",
|
|
82
|
+
"unsafe-inline",
|
|
83
|
+
"unsafe-eval",
|
|
84
|
+
"unsafe-hashes",
|
|
85
|
+
"strict-dynamic",
|
|
86
|
+
"report-sample",
|
|
87
|
+
"unsafe-allow-redirects",
|
|
88
|
+
"wasm-unsafe-eval",
|
|
89
|
+
"trusted-types-eval",
|
|
90
|
+
"report-sha256",
|
|
91
|
+
"report-sha384",
|
|
92
|
+
"report-sha512",
|
|
93
|
+
"unsafe-webtransport-hashes"
|
|
94
|
+
];
|
|
95
|
+
var CSP_KEYWORDS_SET = new Set(CSP_KEYWORDS);
|
|
96
|
+
var isCSPKeyword = (value) => {
|
|
97
|
+
return CSP_KEYWORDS_SET.has(value.toLowerCase());
|
|
98
|
+
};
|
|
99
|
+
var isQuoted = (value) => {
|
|
100
|
+
return value.startsWith("'") && value.endsWith("'");
|
|
101
|
+
};
|
|
102
|
+
var autoQuoteCSPKeyword = (value) => {
|
|
103
|
+
const trimmed = value.trim();
|
|
104
|
+
if (isQuoted(trimmed)) {
|
|
105
|
+
return trimmed;
|
|
106
|
+
}
|
|
107
|
+
if (isCSPKeyword(trimmed)) {
|
|
108
|
+
return `'${trimmed}'`;
|
|
109
|
+
}
|
|
110
|
+
return trimmed;
|
|
111
|
+
};
|
|
112
|
+
var autoQuoteCSPDirectiveValue = (value) => {
|
|
113
|
+
return value.trim().split(/\s+/).filter(Boolean).map(autoQuoteCSPKeyword).join(" ");
|
|
114
|
+
};
|
|
115
|
+
var autoQuoteCSPDirectiveArray = (values) => {
|
|
116
|
+
return values.map(autoQuoteCSPKeyword);
|
|
117
|
+
};
|
|
118
|
+
|
|
78
119
|
// src/utils/cloudflare/make-csp-header.ts
|
|
79
120
|
var addNonce = (value, cspNonce) => value.replace("{{nonce}}", `'nonce-${cspNonce}'`);
|
|
80
121
|
var makeCSPHeader = (cspNonce, directives, mode) => {
|
|
@@ -85,14 +126,19 @@ var makeCSPHeader = (cspNonce, directives, mode) => {
|
|
|
85
126
|
throw new Error(`${originalName} is specified more than once`);
|
|
86
127
|
}
|
|
87
128
|
namesSeen.add(name);
|
|
129
|
+
let directiveValue;
|
|
88
130
|
if (Array.isArray(value)) {
|
|
89
|
-
|
|
131
|
+
directiveValue = autoQuoteCSPDirectiveArray(value).join(" ");
|
|
90
132
|
} else if (value === true) {
|
|
91
|
-
|
|
133
|
+
directiveValue = "";
|
|
134
|
+
} else if (typeof value === "string") {
|
|
135
|
+
directiveValue = autoQuoteCSPDirectiveValue(value);
|
|
136
|
+
} else {
|
|
137
|
+
return;
|
|
92
138
|
}
|
|
93
|
-
if (
|
|
94
|
-
result.push(`${name} ${addNonce(
|
|
95
|
-
} else
|
|
139
|
+
if (directiveValue) {
|
|
140
|
+
result.push(`${name} ${addNonce(directiveValue, cspNonce)}`);
|
|
141
|
+
} else {
|
|
96
142
|
result.push(name);
|
|
97
143
|
}
|
|
98
144
|
});
|
package/cloudflare.js
CHANGED
package/index.js
CHANGED