Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions packages/compiler/src/schema/trusted_types_sinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ const TRUSTED_TYPES_SINKS = new Set<string>([
// NB: no TrustedScript here, as the corresponding tags are stripped by the compiler.

// TrustedScriptURL
'base|href',
'embed|src',
'frame|src',
'iframe|src',
'link|href',
'object|codebase',
'object|data',
]);
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/test/schema/trusted_types_sinks_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ describe('isTrustedTypesSink', () => {
it('should classify Trusted Types sinks', () => {
expect(isTrustedTypesSink('iframe', 'srcdoc')).toBeTrue();
expect(isTrustedTypesSink('p', 'innerHTML')).toBeTrue();
expect(isTrustedTypesSink('base', 'href')).toBeTrue();
expect(isTrustedTypesSink('embed', 'src')).toBeTrue();
expect(isTrustedTypesSink('frame', 'src')).toBeTrue();
expect(isTrustedTypesSink('iframe', 'src')).toBeTrue();
expect(isTrustedTypesSink('link', 'href')).toBeTrue();
expect(isTrustedTypesSink('a', 'href')).toBeFalse();
expect(isTrustedTypesSink('base', 'href')).toBeFalse();
expect(isTrustedTypesSink('div', 'style')).toBeFalse();
});

Expand Down
13 changes: 11 additions & 2 deletions packages/core/test/linker/security_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {DomSanitizer} from '@angular/platform-browser';
import {clearTranslations, loadTranslations} from '@angular/localize';
import {computeMsgId} from '@angular/compiler';
import {clearTranslations, loadTranslations} from '@angular/localize';
import {DomSanitizer} from '@angular/platform-browser';
import {
ChangeDetectionStrategy,
Component,
Expand Down Expand Up @@ -376,6 +376,15 @@ describe('security integration tests', function () {
expect(link.getAttribute('href')).toEqual('unsafe:javascript:alert(1)');
});

it('should throw on translated base href attributes', () => {
const template = `<base href="/safe" i18n-href>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});

expect(() => TestBed.createComponent(SecuredComponent)).toThrowError(
/Translating attribute 'href' is disallowed for security reasons./,
);
});

it('should throw error on security-sensitive attributes with constant values', () => {
const template = `<iframe srcdoc="foo" i18n-srcdoc></iframe>`;
TestBed.overrideComponent(SecuredComponent, {set: {template}});
Expand Down
Loading