Skip to content
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

Escape code examples in detect-html-injection.md #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions docs/rules/detect-html-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ document.wirte("Welcome " +
document.URL.substring(name, document.URL.length)); <- SINK
</script>
```
**Source**: document.URL
**Source**: `document.URL`

**Sink**: document.write()
**Sink**: `document.write()`

**Result**: document.write("<script>alert(docuemnt.cookie)</script>");
**Result**: `document.write("<script>alert(docuemnt.cookie)</script>");`

The exploit will take place when visiting the following URL:

Expand All @@ -43,12 +43,11 @@ Sinks: Sinks are all the DOM Properties, JavaScript functions, and other Client-

Function Name | Browser | Example
------------- | ------- | -------
document.write | All | document.write(“<b>” + userControlledVal + “</b>”);
document.writeln | All | document.writeln("<b>" + userControlledVal + "</b>");
anyElement.innerHTML | All | divElem.innerHTML = “Hello ” + userControlledVal
anyElement.outerHTML | All | divElem.outerHTML = "<div>Hello " + userControlledVal
+ "</div>"
anyElement.insertAdjacentHTML | All | divElem.insertAdjacentHTML("","<b>"+ userControlledVal + "</b>");)
`document.write` | All | `document.write(“<b>” + userControlledVal + “</b>”);`
`document.writeln` | All | `document.writeln("<b>" + userControlledVal + "</b>");`
`anyElement.innerHTML` | All | `divElem.innerHTML = “Hello ” + userControlledVal`
`anyElement.outerHTML` | All | `divElem.outerHTML = "<div>Hello " + userControlledVal + "</div>"`
`anyElement.insertAdjacentHTML` | All | `divElem.insertAdjacentHTML("","<b>"+ userControlledVal + "</b>");)`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the last parenthesis is on purpose:

Suggested change
`anyElement.insertAdjacentHTML` | All | `divElem.insertAdjacentHTML("","<b>"+ userControlledVal + "</b>");)`
`anyElement.insertAdjacentHTML` | All | `divElem.insertAdjacentHTML("","<b>"+ userControlledVal + "</b>");`


### Difference between document.write functions and properties like innerHTML
The document.write method:
Expand Down Expand Up @@ -115,9 +114,9 @@ var pos = document.URL.indexOf("foo=") + 4;
document.write(document.URL.substring(pos, document.URL.length));
</script>
```
* Source: document.URL
* Sink: document.write()
* Result: document.write(“<script>alert(document.cookie)</script>”);
* Source: `document.URL`
* Sink: `document.write()`
* Result: `document.write(“<script>alert(document.cookie)</script>”);`

The attack is possible to a Client-side level (this due to the # fragment identifier).

Expand Down