Skip to content

Commit

Permalink
fix(3262): Allow anchor tags within the nav banner (#1319)
Browse files Browse the repository at this point in the history
Co-authored-by: mhirabar <[email protected]>
  • Loading branch information
foxtrot0304 and mhirabar authored Jan 9, 2025
1 parent bca3e35 commit cbcf9d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/nav-banner/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/>
<div class="banner-message">
<span>
{{banner.message}}
{{{input-sanitizer banner.message}}}
</span>
</div>
</div>
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/components/nav-banner/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,47 @@ module('Integration | Component | nav banner', function (hooks) {

assert.dom('.banner').hasText('× shutdown imminent');
});

test('it renders banner with image tag', async function (assert) {
const bannerStub = Service.extend({
fetchBanners: () =>
resolve([
EmberObject.create({
id: 2,
isActive: true,
message: `Image tag: <img src="#notanimage" onerror="alert('unsafe script injection from warning!')" />`
})
])
});

this.owner.register('service:banner', bannerStub);

await render(hbs`<NavBanner />`);

assert.dom('.banner-message').hasText('Image tag:');
});

test('it renders with link', async function (assert) {
const bannerStub = Service.extend({
fetchBanners: () =>
resolve([
EmberObject.create({
id: 3,
isActive: true,
message: `test - <a href="https://docs.screwdriver.cd/" onclick="alert('xss test');">screwdriver docs</a>`
})
])
});

this.owner.register('service:banner', bannerStub);

await render(hbs`<NavBanner />`);

assert.dom('.banner-message').hasText('test - screwdriver docs');
assert
.dom('.banner-message > span > a')
.hasAttribute('href', 'https://docs.screwdriver.cd/');
assert.dom('.banner-message > span > a').hasNoAttribute('rel');
assert.dom('.banner-message > span > a').hasNoAttribute('onclick');
});
});

0 comments on commit cbcf9d4

Please sign in to comment.