Prevent forbidden tags in head html template#3937
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c59b1c914f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR introduces a security enhancement by implementing a whitelist-based sanitization mechanism for head HTML insertion. The change prevents potential XSS and code injection attacks by filtering HTML content before inserting it into the document head.
Changes:
- Added
sanitizeHeadHTMLutility function that whitelists onlymetaandtitletags with specific attributes - Modified
host-mode-service.tsto use the new sanitization function before inserting HTML into the document head - Added comprehensive unit tests to verify the sanitization behavior
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| packages/host/app/utils/sanitize-head-html.ts | New utility implementing whitelist-based HTML sanitization for head content |
| packages/host/app/services/host-mode-service.ts | Updated to use sanitization function before inserting head HTML |
| packages/host/tests/unit/utils/sanitize-head-html-test.ts | Comprehensive test suite for the sanitization function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Preview deployments |
add26bc to
b32c147
Compare
lukemelia
left a comment
There was a problem hiding this comment.
Will users be able to understand this sanitization? Should there be some indicator in code mode that some of your head format output is not allowed? /cc @backspace
|
I know this issue wasn’t that explicit but I think this needs to happen in a different place; maybe where you’ve inserted it is correct, but it should also be present at least in I’m not sure how much of an affordance we want but I’d be surprised to have |
|
I think user could add Perhaps we should only validate head template to the point where it can only include the elements from the html head spec, and show a warning/error in code mode if user tries to use any other elements in the head template? |
okay, but I think we do need to consider the broader problem of XSS anywhere. Maybe it just fits in the “abuse” issue. |
|
notes from office hours:
|
b32c147 to
87397e8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e03326b76
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (let node of Array.from(template.content.childNodes)) { | ||
| if (node.nodeType === ELEMENT_NODE) { | ||
| let tagName = (node as Element).tagName.toLowerCase(); | ||
| if (!ALLOWED_HEAD_TAGS.has(tagName) && !disallowed.includes(tagName)) { | ||
| disallowed.push(tagName); |
There was a problem hiding this comment.
Surface stripped
<link> entries in head warnings
findDisallowedHeadTags only checks whether a top-level tag name is allowlisted, but the sanitizer also drops <link> elements when their rel or href fails safety checks (sanitizeLinkElement). That means inputs like <link rel="stylesheet" ...> or <link rel="icon" href="javascript:..."> are removed at render time with no warning in the head preview, which makes valid-looking head templates fail silently for authors.
Useful? React with 👍 / 👎.
9e03326 to
1c29dc7
Compare
<titlte>,<link>,<meta>, do not allow any other ones - strip them out when rendering