Fix makeTemplateNode bypassing HTML sanitization#352
Fix makeTemplateNode bypassing HTML sanitization#352phillipc wants to merge 2 commits intoknockout:mainfrom
Conversation
Route <script> template content through validateHTMLInput in makeTemplateNode so templateSizeLimit, allowScriptTagsInTemplates, and sanitizeHtmlTemplate checks apply.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes a security vulnerability in the ChangesScript Template Sanitization Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Adversarial reviewFix at Must fix before merge:
Worth deciding: Out of scope (note for the record):
|
|
Changeset how-to (sorry, should have included this): bunx changeset add
# select @tko/binding.foreach AND @tko/utils, pick "patch" (or "minor" if treating the silent→throw shift as breaking-ish), paste description
# commit the generated .changeset/<slug>.md with the fixOr hand-write ---
'@tko/binding.foreach': patch
'@tko/utils': patch
---
Fix `makeTemplateNode` bypassing HTML sanitization for `<script>` foreach templates. `validateHTMLInput` is now exported from `@tko/utils`. Behavior change: previously silent acceptance of oversized templates / embedded `<script>` bodies under `allowScriptTagsInTemplates: false` now throws. If you intentionally embed `<script>` content in a foreach template, set `allowScriptTagsInTemplates: true`. |
|
@brianmhunt I have implemented the requested changes |
Problem
makeTemplateNodeinpackages/binding.foreach/src/foreach.tsassignedsourceNode.textdirectly toparentNode.innerHTMLfor<script>template elements, bypassing all three HTML sanitization controls:options.templateSizeLimitoptions.allowScriptTagsInTemplatesoptions.sanitizeHtmlTemplateDetected in Add TypeScript code review skill and updated findings plans #350
Fix
validateHTMLInputfrom@tko/utils(was previously internal tohtml.ts)<script>element's.textthroughvalidateHTMLInput()before assigning toinnerHTMLThis ensures the same size-limit, script-tag, and custom sanitizer checks apply to foreach
<script>templates as they do everywhere else viaparseHtmlFragment.Testing
All 158 existing foreach tests pass (happy-dom + chromium).
Summary by CodeRabbit
Bug Fixes
allowScriptTagsInTemplates: true.Tests