forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Remove usage of htmlSafe (hashicorp#20235)
- Loading branch information
Showing
17 changed files
with
76 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
```release-note:bug | ||
ui: remove use of htmlSafe except when first sanitized | ||
``` |
This file contains 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 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 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 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 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 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 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 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 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { debug } from '@ember/debug'; | ||
import { htmlSafe } from '@ember/template'; | ||
import { sanitize } from 'dompurify'; | ||
|
||
export default helper(function sanitizedHtml([htmlString]) { | ||
try { | ||
return htmlSafe(sanitize(htmlString)); | ||
} catch (e) { | ||
debug('Error sanitizing string', e); | ||
// I couldn't get this to actually fail but as a fallback render the value as-is | ||
return htmlString; | ||
} | ||
}); |
This file contains 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 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 @@ | ||
export { default } from 'core/helpers/sanitized-html'; |
This file contains 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 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 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 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 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,35 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'vault/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Helper | sanitized-html', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it does not alter if string is safe', async function (assert) { | ||
this.set('inputValue', 'height: 15.33px'); | ||
|
||
await render(hbs`{{sanitized-html this.inputValue}}`); | ||
assert.dom(this.element).hasText('height: 15.33px'); | ||
}); | ||
|
||
test('it strips unsafe HTML before rendering safe HTML', async function (assert) { | ||
this.set( | ||
'inputValue', | ||
'<main data-test-thing>This is something<script data-test-script>window.alert(`h4cK3d`)</script></main>' | ||
); | ||
|
||
await render(hbs`{{sanitized-html this.inputValue}}`); | ||
assert.dom('[data-test-thing]').hasTagName('main'); | ||
assert.dom('[data-test-thing]').hasText('This is something', 'preserves non-problematic content'); | ||
assert.dom('[data-test-script]').doesNotExist('Script is stripped from render'); | ||
}); | ||
|
||
test('it does not invoke functions passed as value', async function (assert) { | ||
this.set('inputValue', () => { | ||
window.alert('h4cK3d'); | ||
}); | ||
await render(hbs`{{sanitized-html this.inputValue}}`); | ||
assert.dom(this.element).hasText("() => { window.alert('h4cK3d'); }"); | ||
}); | ||
}); |
This file contains 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