astro-helmet 1.2.0 → 1.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/package.json +1 -1
- package/src/Helmet.astro +17 -12
package/package.json
CHANGED
package/src/Helmet.astro
CHANGED
|
@@ -6,24 +6,29 @@ interface Props {
|
|
|
6
6
|
options?: {
|
|
7
7
|
omitHeadTags?: boolean
|
|
8
8
|
applyPriority?: (tag: Tag) => Required<Tag>
|
|
9
|
+
csp?: boolean
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
const { headItems, options = {} } = Astro.props
|
|
13
|
-
const { applyPriority, omitHeadTags = false } = options
|
|
14
|
+
const { applyPriority, omitHeadTags = false, csp: cspEnabled = false } = options
|
|
14
15
|
const head = renderHead(headItems, applyPriority)
|
|
15
16
|
|
|
16
|
-
// Register CSP hashes and resources when
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
// Register CSP hashes and resources when the consumer opts in via `options.csp`
|
|
18
|
+
// AND is running on Astro 6+ with CSP configured. Reading `Astro.csp` warns in
|
|
19
|
+
// production when CSP isn't configured, so the opt-in keeps the component
|
|
20
|
+
// silent for users who don't need CSP integration. Cast avoids typecheck
|
|
21
|
+
// failures for downstream consumers on Astro 4/5.
|
|
22
|
+
const csp = cspEnabled
|
|
23
|
+
? (Astro as unknown as {
|
|
24
|
+
csp?: {
|
|
25
|
+
insertScriptHash(hash: string): void
|
|
26
|
+
insertStyleHash(hash: string): void
|
|
27
|
+
insertScriptResource(url: string): void
|
|
28
|
+
insertStyleResource(url: string): void
|
|
29
|
+
}
|
|
30
|
+
}).csp
|
|
31
|
+
: undefined
|
|
27
32
|
if (csp) {
|
|
28
33
|
for (const { type, content } of getInlineContent(headItems)) {
|
|
29
34
|
const hashBuffer = await crypto.subtle.digest(
|