Files
codeql/javascript/ql/test/query-tests/Security/CWE-079/XssThroughDom/angular.ts
2025-02-28 13:29:30 +01:00

37 lines
861 B
TypeScript

import { Component } from "@angular/core";
import { NgForm } from "@angular/forms";
@Component({
template: `
<input type="text" (input)="setInput1($event)"></input>
<input type="text" (input)="setInput2($event.target)"></input>
<input type="text" [(ngModel)]="field"></input>
`
})
export class Foo {
field: string = ""; // $ Source
safeField: string = "";
setInput1(event) {
document.write(event.target.value); // $ Alert
}
setInput2(target) {
document.write(target.value); // $ Alert
}
setOtherInput(e) {
document.write(e.target.value);
document.write(e.value);
}
blah(form: NgForm) {
document.write(form.value.foo); // $ Alert
}
useField() {
document.write(this.field); // $ Alert
document.write(this.safeField);
}
}