Skip to content

Commit

Permalink
Account for <a> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov committed Aug 20, 2024
1 parent 98f2fc2 commit d77887a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('NoXss', () => {
const entity = new Entity();

describe('Scripts', () => {
const XSS_STRINGS = ['<script src/>', "<script>alert('xss')</script>"];
// eslint-disable-next-line n8n-local-rules/no-unneeded-backticks
const XSS_STRINGS = ['<script src/>', "<script>alert('xss')</script>", `<a href="#">Jack</a>`];

for (const str of XSS_STRINGS) {
test(`should block ${str}`, async () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/validators/no-xss.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { registerDecorator, ValidatorConstraint } from 'class-validator';
@ValidatorConstraint({ name: 'NoXss', async: false })
class NoXssConstraint implements ValidatorConstraintInterface {
validate(value: string) {
return value === xss(value);
return (
value ===
xss(value, {
whiteList: {}, // no tags are allowed
})
);
}

defaultMessage() {
Expand Down

0 comments on commit d77887a

Please sign in to comment.