diff --git a/backend/src/models/Snippet.ts b/backend/src/models/Snippet.ts index 625d43b..e0ab7b7 100644 --- a/backend/src/models/Snippet.ts +++ b/backend/src/models/Snippet.ts @@ -86,9 +86,10 @@ SnippetSchema.pre('save', function (next) { // Remover atributos perigosos let previousCode; + const dangerousAttrRegex = /on\w+=(["'])(?:(?=(\\?))\2.)*?\1/g; do { previousCode = this.code; - this.code = this.code.replace(/on\w+="[^"]*"/g, '').replace(/on\w+='[^']*'/g, ''); + this.code = this.code.replace(dangerousAttrRegex, ''); } while (this.code !== previousCode); // Remover URLs perigosas em estilos inline