Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
Use createTextNode() to avoid possible XSS (#145)
Browse files Browse the repository at this point in the history
* Use createTextNode() to avoid possible XSS

For reference: https://stackoverflow.com/questions/476821/is-a-dom-text-node-guaranteed-to-not-be-interpreted-as-html
For XSS Example: https://jsfiddle.net/32795mpy/

* delete whitespace for CI

* update variable names

"hiddenText" => "shavedText"
"wrapper" =>  "elWithShavedText"
  • Loading branch information
digitalcraft authored and yowainwright committed Apr 17, 2019
1 parent 0e0365d commit 1876911
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/shave.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ export default function shave (target, maxHeight, opts = {}) {
el.insertAdjacentHTML('beforeend', charHtml)
const diff = spaces ? ` ${words.slice(max).join(' ')}` : words.slice(max)

el.insertAdjacentHTML(
'beforeend',
`<span class="${classname}" style="display:none;">${diff}</span>`,
)
// https://stackoverflow.com/questions/476821/is-a-dom-text-node-guaranteed-to-not-be-interpreted-as-html
const shavedText = document.createTextNode(diff)
const elWithShavedText = document.createElement('span')
elWithShavedText.classList.add(classname)
elWithShavedText.style.display = 'none'
elWithShavedText.appendChild(shavedText)
el.insertAdjacentElement('beforeend', elWithShavedText)

styles.height = heightStyle
styles.maxHeight = maxHeightStyle
Expand Down

0 comments on commit 1876911

Please # to comment.