Skip to content

Commit e4b1ff6

Browse files
authoredFeb 14, 2025··
feat(core): whitelist styles with useHeadSafe() (#491)
* feat(core): whitelist styles with `useHeadSafe()` * doc: missing doc
1 parent e2d4ecd commit e4b1ff6

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed
 

‎docs/7.api/1.use-head-safe.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ The `useHeadSafe` composable is a wrapper around the [useHead](/guide/composable
99

1010
There is a whitelist of allowed tags and attributes. If you try to use a tag or attribute that isn't on the whitelist, it will be ignored.
1111

12-
The whitelist is very restrictive, as there are many vectors for XSS attacks. If you need to use a tag or attribute that isn't on the whitelist, you can use the [useHead](/guide/composables/use-head) composable instead,
12+
The whitelist is restrictive, as there are many vectors for XSS attacks. If you need to use a tag or attribute that isn't on the whitelist, you can use the [useHead](/guide/composables/use-head) composable instead,
1313
just make sure **you sanitise the input**.
1414

1515
The whitelist is as follows:
1616

1717
```ts
1818
const WhitelistAttributes = {
19-
htmlAttrs: ['id', 'class', 'lang', 'dir'],
20-
bodyAttrs: ['id', 'class'],
21-
meta: ['id', 'name', 'property', 'charset', 'content'],
22-
noscript: ['id', 'textContent'],
23-
script: ['id', 'type', 'textContent'],
24-
link: ['id', 'color', 'crossorigin', 'fetchpriority', 'href', 'hreflang', 'imagesrcset', 'imagesizes', 'integrity', 'media', 'referrerpolicy', 'rel', 'sizes', 'type'],
25-
}
19+
htmlAttrs: ['class', 'style', 'lang', 'dir'] satisfies (keyof HtmlAttributes)[],
20+
bodyAttrs: ['class', 'style'] satisfies (keyof BodyAttributes)[],
21+
meta: ['name', 'property', 'charset', 'content', 'media'] satisfies (keyof Meta)[],
22+
noscript: ['textContent'] satisfies (Partial<keyof Noscript> | 'textContent')[],
23+
style: ['media', 'textContent', 'nonce', 'title', 'blocking'] satisfies (Partial<keyof Style> | 'textContent')[],
24+
script: ['type', 'textContent', 'nonce', 'blocking'] satisfies (Partial<keyof Script> | 'textContent')[],
25+
link: ['color', 'crossorigin', 'fetchpriority', 'href', 'hreflang', 'imagesrcset', 'imagesizes', 'integrity', 'media', 'referrerpolicy', 'rel', 'sizes', 'type'] satisfies (keyof Link)[],
26+
} as const
2627
```
2728

28-
- Style tags and attributes not supported `<link rel="stylesheet" ...>`{lang="html"}, `<style>`{lang="html"}, they are a vector for XSS attacks and clickjacking.
2929
- Scripts of any sort are not allowed, except for JSON. `<script type="application/json">`{lang="html"}, use `textContent: myObject`.
3030
- http-equiv is not allowed on meta.
3131
- `data-*` attributes are allowed.
@@ -40,3 +40,7 @@ const thirdPartyMeta = loadMeta()
4040

4141
useHeadSafe(thirdPartyMeta)
4242
```
43+
44+
## Styles
45+
46+
While styles are permitted it's important to note that [clickjacking](https://en.wikipedia.org/wiki/Clickjacking) is still possible. You should ensure that your styles are safe to use.

0 commit comments

Comments
 (0)
Please sign in to comment.