Skip to content

Commit

Permalink
Merge pull request #23 from Jonhvmp/alert-autofix-26
Browse files Browse the repository at this point in the history
Fix code scanning alert no. 26: Incomplete multi-character sanitization
  • Loading branch information
Jonhvmp authored Dec 7, 2024
2 parents fb4d9cc + 133372f commit 540eedb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion backend/src/models/Snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ SnippetSchema.pre<ISnippet>('save', function (next) {
this.code = this.code.replace(/</g, '&lt;').replace(/>/g, '&gt;');

// Remover atributos perigosos
this.code = this.code.replace(/on\w+="[^"]*"/g, '').replace(/on\w+='[^']*'/g, '');
let previousCode;
do {
previousCode = this.code;
this.code = this.code.replace(/on\w+="[^"]*"/g, '').replace(/on\w+='[^']*'/g, '');
} while (this.code !== previousCode);

// Remover URLs perigosas em estilos inline
this.code = this.code.replace(/style\s*=\s*["'][^"']*(javascript|data|vbscript):[^"']*["']/gi, 'style=""');
Expand Down

0 comments on commit 540eedb

Please sign in to comment.