-
Notifications
You must be signed in to change notification settings - Fork 669
fix: html script, style, and comment escaping #3159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "marko": patch | ||
| "@marko/runtime-tags": patch | ||
| --- | ||
|
|
||
| Fix escaping issue for dynamic text interpolation inside `<script>`, `<style>`, `<html-script>` and `<html-style>` tags. | ||
|
|
||
| The issue was that the escaping logic for those tags used a CASE SENSITIVE search for the closing tag which could be bypassed like so: | ||
|
|
||
| ```marko | ||
| <script>${"</SCRIPT><img src=x onerror=alert('uh oh')>"}</script> | ||
| ``` | ||
|
|
||
| Note that `script` and `style` there should _never_ render unsanitized user defined values, regardless of wether or not the closing tag is escaped, since these are conceptually just "eval". | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| "marko": patch | ||
| "@marko/runtime-tags": patch | ||
| --- | ||
|
|
||
| Fix escaping for `<html-comment>` tag. | ||
| Previously this tag relied on normal xml escaping which looks for `<`. | ||
| This PR updates to have a special escape for `<html-comment>` tags that replaces `>` instead. | ||
|
|
||
| ```marko | ||
| // Previously incorrectly escaped. | ||
| <html-comment>${">Uh oh"}</html-comment> | ||
| ``` | ||
|
DylanPiercey marked this conversation as resolved.
|
||
17 changes: 17 additions & 0 deletions
17
packages/runtime-class/src/runtime/html/helpers/escape-comment-placeholder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| "use strict"; | ||
| const unsafeCharsReg = />/g; | ||
| const replaceMatch = () => ">"; | ||
| const escape = (str) => | ||
| unsafeCharsReg.test(str) ? str.replace(unsafeCharsReg, replaceMatch) : str; | ||
|
|
||
| /** | ||
| * Escapes content placed inside an <html-comment> tag. | ||
| * | ||
| * For example: | ||
| * <html-comment>${userInput}</html-comment> | ||
| * | ||
| * Without escaping, a value of `><script>alert(1)</script><!--` would close the comment early. | ||
| */ | ||
| module.exports = function escapeCommentHelper(value) { | ||
| return escape(value + ""); | ||
|
DylanPiercey marked this conversation as resolved.
|
||
| }; | ||
2 changes: 1 addition & 1 deletion
2
packages/runtime-class/src/runtime/html/helpers/escape-script-placeholder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/runtime-class/src/runtime/html/helpers/escape-style-placeholder.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/runtime-class/test/render/fixtures/escape-comment/expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <!---->--> |
1 change: 1 addition & 0 deletions
1
packages/runtime-class/test/render/fixtures/escape-comment/template.marko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <html-comment>${input.text}</html-comment> |
3 changes: 3 additions & 0 deletions
3
packages/runtime-class/test/render/fixtures/escape-comment/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| exports.templateData = { | ||
| text: "-->", | ||
| }; |
1 change: 1 addition & 0 deletions
1
packages/runtime-class/test/render/fixtures/escape-comment/vdom-expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <!--"-->"--> |
3 changes: 3 additions & 0 deletions
3
packages/runtime-class/test/render/fixtures/escape-script-case/expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <script> | ||
| var foo = {"name":"Evil \x3C/script>"}; | ||
| </script><pre>{"name":"Evil </SCRIPT>"}</pre> |
4 changes: 4 additions & 0 deletions
4
packages/runtime-class/test/render/fixtures/escape-script-case/template.marko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <script> | ||
| var foo = ${JSON.stringify(input.foo)}; | ||
| </script> | ||
| <pre>${JSON.stringify(input.foo)}</pre> |
5 changes: 5 additions & 0 deletions
5
packages/runtime-class/test/render/fixtures/escape-script-case/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| exports.templateData = { | ||
| foo: { | ||
| name: "Evil </SCRIPT>", | ||
| }, | ||
| }; |
4 changes: 4 additions & 0 deletions
4
packages/runtime-class/test/render/fixtures/escape-script-case/vdom-expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <SCRIPT> | ||
| "\n var foo = {\"name\":\"Evil </SCRIPT>\"};\n" | ||
| <PRE> | ||
| "{\"name\":\"Evil </SCRIPT>\"}" |
5 changes: 5 additions & 0 deletions
5
packages/runtime-class/test/render/fixtures/escape-style-case/expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <style> | ||
| #foo { | ||
| background-color:\3C/style><script>alert("evil");</script>; | ||
| } | ||
| </style> |
5 changes: 5 additions & 0 deletions
5
packages/runtime-class/test/render/fixtures/escape-style-case/template.marko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <style> | ||
| #foo { | ||
| background-color:${input.color}; | ||
| } | ||
| </style> |
3 changes: 3 additions & 0 deletions
3
packages/runtime-class/test/render/fixtures/escape-style-case/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| exports.templateData = { | ||
| color: '</STYLE><script>alert("evil");</script>', | ||
| }; |
2 changes: 2 additions & 0 deletions
2
packages/runtime-class/test/render/fixtures/escape-style-case/vdom-expected.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <STYLE> | ||
| "\n #foo {\n background-color:</STYLE><script>alert(\"evil\");</script>;\n }\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ntime-tags/src/__tests__/fixtures/html-comment-placeholder/__snapshots__/.name-cache.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "vars": { | ||
| "props": {} | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...sts__/fixtures/html-comment-placeholder/__snapshots__/csr-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
9 changes: 9 additions & 0 deletions
9
...s/src/__tests__/fixtures/html-comment-placeholder/__snapshots__/csr.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Render | ||
| ```html | ||
| <!---->--> | ||
| ``` | ||
|
|
||
| # Mutations | ||
| ``` | ||
| INSERT #comment | ||
| ``` |
1 change: 1 addition & 0 deletions
1
..._tests__/fixtures/html-comment-placeholder/__snapshots__/dom.expected/template.hydrate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // size: 0 |
7 changes: 7 additions & 0 deletions
7
...gs/src/__tests__/fixtures/html-comment-placeholder/__snapshots__/dom.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export const $template = "<!---->"; | ||
| export const $walks = /* get, over(1) */" b"; | ||
| import * as _ from "@marko/runtime-tags/debug/dom"; | ||
| export function $setup($scope) { | ||
| _._text($scope["#comment/0"], `${_._to_text("-->")}`); | ||
| } | ||
| export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup); |
6 changes: 6 additions & 0 deletions
6
...s/src/__tests__/fixtures/html-comment-placeholder/__snapshots__/html.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import * as _ from "@marko/runtime-tags/debug/html"; | ||
| export default _._template("__tests__/template.marko", input => { | ||
| _._scope_reason(); | ||
| const $scope0_id = _._scope_id(); | ||
| _._html(`<!--${_._escape_comment("-->")}-->`); | ||
| }, 1); |
1 change: 1 addition & 0 deletions
1
...__/fixtures/html-comment-placeholder/__snapshots__/resume-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
8 changes: 8 additions & 0 deletions
8
...rc/__tests__/fixtures/html-comment-placeholder/__snapshots__/resume.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Render | ||
| ```html | ||
| <!---->--> | ||
| <html> | ||
| <head /> | ||
| <body /> | ||
| </html> | ||
| ``` |
1 change: 1 addition & 0 deletions
1
...sts__/fixtures/html-comment-placeholder/__snapshots__/ssr-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render End |
21 changes: 21 additions & 0 deletions
21
...s/src/__tests__/fixtures/html-comment-placeholder/__snapshots__/ssr.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Write | ||
| ```html | ||
| <!---->--> | ||
| ``` | ||
|
|
||
| # Render End | ||
| ```html | ||
| <!---->--> | ||
| <html> | ||
| <head /> | ||
| <body /> | ||
| </html> | ||
| ``` | ||
|
|
||
| # Mutations | ||
| ``` | ||
| INSERT #comment | ||
| INSERT html | ||
| INSERT html/head | ||
| INSERT html/body | ||
| ``` |
1 change: 1 addition & 0 deletions
1
packages/runtime-tags/src/__tests__/fixtures/html-comment-placeholder/template.marko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <html-comment>${"-->"}</html-comment> |
5 changes: 5 additions & 0 deletions
5
packages/runtime-tags/src/__tests__/fixtures/html-comment-placeholder/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { TestConfig } from "../../main.test"; | ||
|
|
||
| export const config: TestConfig = { | ||
| steps: [{}], | ||
| }; |
5 changes: 5 additions & 0 deletions
5
.../runtime-tags/src/__tests__/fixtures/html-script-injection/__snapshots__/.name-cache.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "vars": { | ||
| "props": {} | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
..._tests__/fixtures/html-script-injection/__snapshots__/csr-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
11 changes: 11 additions & 0 deletions
11
...tags/src/__tests__/fixtures/html-script-injection/__snapshots__/csr.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Render | ||
| ```html | ||
| <script> | ||
| var x = '</SCRIPT>' | ||
| </script> | ||
| ``` | ||
|
|
||
| # Mutations | ||
| ``` | ||
| INSERT script | ||
| ``` |
1 change: 1 addition & 0 deletions
1
...c/__tests__/fixtures/html-script-injection/__snapshots__/dom.expected/template.hydrate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // size: 0 |
9 changes: 9 additions & 0 deletions
9
...-tags/src/__tests__/fixtures/html-script-injection/__snapshots__/dom.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export const $template = "<script></script>"; | ||
| export const $walks = /* get, over(1) */" b"; | ||
| import * as _ from "@marko/runtime-tags/debug/dom"; | ||
| const $injection = /* @__PURE__ */_._let("injection/1", $scope => _._text_content($scope["#script/0"], `var x = '${_._to_text($scope.injection)}'`)); | ||
| export function $setup($scope) { | ||
| _._attr_nonce($scope, "#script/0"); | ||
| $injection($scope, "</SCRIPT>"); | ||
| } | ||
| export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup); |
8 changes: 8 additions & 0 deletions
8
...tags/src/__tests__/fixtures/html-script-injection/__snapshots__/html.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as _ from "@marko/runtime-tags/debug/html"; | ||
| export default _._template("__tests__/template.marko", input => { | ||
| _._scope_reason(); | ||
| const $scope0_id = _._scope_id(); | ||
| let injection = "</SCRIPT>"; | ||
| _._html(`<script${_._attr_nonce()}>var x = '${_._escape_script(injection)}'</script>`); | ||
| _._resume_branch($scope0_id); | ||
| }, 1); |
1 change: 1 addition & 0 deletions
1
...sts__/fixtures/html-script-injection/__snapshots__/resume-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
11 changes: 11 additions & 0 deletions
11
...s/src/__tests__/fixtures/html-script-injection/__snapshots__/resume.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Render | ||
| ```html | ||
| <html> | ||
| <head> | ||
| <script> | ||
| var x = '\x3C/script>' | ||
| </script> | ||
| </head> | ||
| <body /> | ||
| </html> | ||
| ``` |
1 change: 1 addition & 0 deletions
1
..._tests__/fixtures/html-script-injection/__snapshots__/ssr-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render End |
25 changes: 25 additions & 0 deletions
25
...tags/src/__tests__/fixtures/html-script-injection/__snapshots__/ssr.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Write | ||
| ```html | ||
| <script>var x = '\x3C/script>'</script> | ||
| ``` | ||
|
|
||
| # Render End | ||
| ```html | ||
| <html> | ||
| <head> | ||
| <script> | ||
| var x = '\x3C/script>' | ||
| </script> | ||
| </head> | ||
| <body /> | ||
| </html> | ||
| ``` | ||
|
|
||
| # Mutations | ||
| ``` | ||
| INSERT html | ||
| INSERT html/head | ||
| INSERT html/head/script | ||
| INSERT html/head/script/#text | ||
| INSERT html/body | ||
| ``` |
2 changes: 2 additions & 0 deletions
2
packages/runtime-tags/src/__tests__/fixtures/html-script-injection/template.marko
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <let/injection = "</SCRIPT>" /> | ||
| <html-script>var x = '${injection}'</html-script> |
5 changes: 5 additions & 0 deletions
5
packages/runtime-tags/src/__tests__/fixtures/html-script-injection/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { TestConfig } from "../../main.test"; | ||
|
|
||
| export const config: TestConfig = { | ||
| steps: [{}], | ||
| }; |
5 changes: 5 additions & 0 deletions
5
...s/runtime-tags/src/__tests__/fixtures/html-style-injection/__snapshots__/.name-cache.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "vars": { | ||
| "props": {} | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...__tests__/fixtures/html-style-injection/__snapshots__/csr-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
11 changes: 11 additions & 0 deletions
11
...-tags/src/__tests__/fixtures/html-style-injection/__snapshots__/csr.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Render | ||
| ```html | ||
| <style> | ||
| .evil { content: '</STYLE>'; } | ||
| </style> | ||
| ``` | ||
|
|
||
| # Mutations | ||
| ``` | ||
| INSERT style | ||
| ``` |
1 change: 1 addition & 0 deletions
1
...rc/__tests__/fixtures/html-style-injection/__snapshots__/dom.expected/template.hydrate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // size: 0 |
9 changes: 9 additions & 0 deletions
9
...e-tags/src/__tests__/fixtures/html-style-injection/__snapshots__/dom.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export const $template = "<style></style>"; | ||
| export const $walks = /* get, over(1) */" b"; | ||
| import * as _ from "@marko/runtime-tags/debug/dom"; | ||
| const $injection = /* @__PURE__ */_._let("injection/1", $scope => _._text_content($scope["#style/0"], `.evil { content: '${_._to_text($scope.injection)}'; }`)); | ||
| export function $setup($scope) { | ||
| _._attr_nonce($scope, "#style/0"); | ||
| $injection($scope, "</STYLE>"); | ||
| } | ||
| export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup); |
8 changes: 8 additions & 0 deletions
8
...-tags/src/__tests__/fixtures/html-style-injection/__snapshots__/html.expected/template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as _ from "@marko/runtime-tags/debug/html"; | ||
| export default _._template("__tests__/template.marko", input => { | ||
| _._scope_reason(); | ||
| const $scope0_id = _._scope_id(); | ||
| let injection = "</STYLE>"; | ||
| _._html(`<style${_._attr_nonce()}>.evil { content: '${_._escape_style(injection)}'; }</style>`); | ||
| _._resume_branch($scope0_id); | ||
| }, 1); |
1 change: 1 addition & 0 deletions
1
...ests__/fixtures/html-style-injection/__snapshots__/resume-sanitized.expected.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Render |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.