Allow Angular XSS Attack
up vote
1
down vote
favorite
I want to create an example of xss attack, with angular 7, for teaching purposes.
<div class="container mt-3">
<div class="row">
<div class="col-12">
<ul>
<li *ngFor="let message of messages">{{message}}</li>
<li *ngFor="let message of messages" [innerHTML]="message"></li>
<li *ngFor="let message of messages" [innerHTML]="message | keepHtml"></li>
</ul>
<ng-container *ngIf="messages.length === 0">No messages</ng-container>
</div>
<div class="col-12">
<hr/>
<label>New Message</label>
<textarea class="form-control" [(ngModel)]="model.message" name="message"></textarea>
<button class="btn btn-success mt-2" (click)="submit()">Send Message</button>
</div>
</div>
Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'keepHtml', pure: false })
export class EscapeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(content) {
return this.sanitizer.bypassSecurityTrustHtml(content);
}
}
I want to send message <script>alert('1');</script>
and let the alert run
angular xss angular7
add a comment |
up vote
1
down vote
favorite
I want to create an example of xss attack, with angular 7, for teaching purposes.
<div class="container mt-3">
<div class="row">
<div class="col-12">
<ul>
<li *ngFor="let message of messages">{{message}}</li>
<li *ngFor="let message of messages" [innerHTML]="message"></li>
<li *ngFor="let message of messages" [innerHTML]="message | keepHtml"></li>
</ul>
<ng-container *ngIf="messages.length === 0">No messages</ng-container>
</div>
<div class="col-12">
<hr/>
<label>New Message</label>
<textarea class="form-control" [(ngModel)]="model.message" name="message"></textarea>
<button class="btn btn-success mt-2" (click)="submit()">Send Message</button>
</div>
</div>
Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'keepHtml', pure: false })
export class EscapeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(content) {
return this.sanitizer.bypassSecurityTrustHtml(content);
}
}
I want to send message <script>alert('1');</script>
and let the alert run
angular xss angular7
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
have you triedbypassSecurityTrustScript
?
– PierreDuc
Nov 22 at 7:29
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to create an example of xss attack, with angular 7, for teaching purposes.
<div class="container mt-3">
<div class="row">
<div class="col-12">
<ul>
<li *ngFor="let message of messages">{{message}}</li>
<li *ngFor="let message of messages" [innerHTML]="message"></li>
<li *ngFor="let message of messages" [innerHTML]="message | keepHtml"></li>
</ul>
<ng-container *ngIf="messages.length === 0">No messages</ng-container>
</div>
<div class="col-12">
<hr/>
<label>New Message</label>
<textarea class="form-control" [(ngModel)]="model.message" name="message"></textarea>
<button class="btn btn-success mt-2" (click)="submit()">Send Message</button>
</div>
</div>
Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'keepHtml', pure: false })
export class EscapeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(content) {
return this.sanitizer.bypassSecurityTrustHtml(content);
}
}
I want to send message <script>alert('1');</script>
and let the alert run
angular xss angular7
I want to create an example of xss attack, with angular 7, for teaching purposes.
<div class="container mt-3">
<div class="row">
<div class="col-12">
<ul>
<li *ngFor="let message of messages">{{message}}</li>
<li *ngFor="let message of messages" [innerHTML]="message"></li>
<li *ngFor="let message of messages" [innerHTML]="message | keepHtml"></li>
</ul>
<ng-container *ngIf="messages.length === 0">No messages</ng-container>
</div>
<div class="col-12">
<hr/>
<label>New Message</label>
<textarea class="form-control" [(ngModel)]="model.message" name="message"></textarea>
<button class="btn btn-success mt-2" (click)="submit()">Send Message</button>
</div>
</div>
Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'keepHtml', pure: false })
export class EscapeHtmlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {
}
transform(content) {
return this.sanitizer.bypassSecurityTrustHtml(content);
}
}
I want to send message <script>alert('1');</script>
and let the alert run
angular xss angular7
angular xss angular7
edited Nov 27 at 9:35
Goncalo Peres
1,1271314
1,1271314
asked Nov 22 at 7:25
Michalis
1,99612540
1,99612540
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
have you triedbypassSecurityTrustScript
?
– PierreDuc
Nov 22 at 7:29
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32
add a comment |
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
have you triedbypassSecurityTrustScript
?
– PierreDuc
Nov 22 at 7:29
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
have you tried
bypassSecurityTrustScript
?– PierreDuc
Nov 22 at 7:29
have you tried
bypassSecurityTrustScript
?– PierreDuc
Nov 22 at 7:29
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425793%2fallow-angular-xss-attack%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Probably not the best approach for teaching if you have to do extra work to make the attack possible. I would use an example where it is easy to get it wrong.
– Henry
Nov 22 at 7:27
Check this out angular.io/guide/security
– holydragon
Nov 22 at 7:29
have you tried
bypassSecurityTrustScript
?– PierreDuc
Nov 22 at 7:29
I get this error with bypassSecurityTrustScript: "Required a safe HTML, got a Script"
– Michalis
Nov 22 at 7:31
@Henry I want to make them see the actual problem and the actual solution from angular
– Michalis
Nov 22 at 7:32