Skip to content

Fix makeTemplateNode bypassing HTML sanitization#352

Open
phillipc wants to merge 1 commit intoknockout:mainfrom
Auge19:fix/foreach-sanitize-script-template
Open

Fix makeTemplateNode bypassing HTML sanitization#352
phillipc wants to merge 1 commit intoknockout:mainfrom
Auge19:fix/foreach-sanitize-script-template

Conversation

@phillipc
Copy link
Copy Markdown
Member

@phillipc phillipc commented Apr 21, 2026

Problem

makeTemplateNode in packages/binding.foreach/src/foreach.ts assigned sourceNode.text directly to parentNode.innerHTML for <script> template elements, bypassing all three HTML sanitization controls:

Fix

  • Export validateHTMLInput from @tko/utils (was previously internal to html.ts)
  • Route the <script> element's .text through validateHTMLInput() before assigning to innerHTML

This ensures the same size-limit, script-tag, and custom sanitizer checks apply to foreach <script> templates as they do everywhere else via parseHtmlFragment.

Testing

All 158 existing foreach tests pass (happy-dom + chromium).

Route <script> template content through validateHTMLInput in
makeTemplateNode so templateSizeLimit, allowScriptTagsInTemplates,
and sanitizeHtmlTemplate checks apply.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

@phillipc has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 36 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b6da2ab-a6f7-4438-adc7-b67f38385269

📥 Commits

Reviewing files that changed from the base of the PR and between 5657f94 and 33359ab.

📒 Files selected for processing (2)
  • packages/binding.foreach/src/foreach.ts
  • packages/utils/src/dom/html.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant