Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to whitelist tag attributes in xss validator? (Error in docs) #426

Open
MickL opened this issue Apr 15, 2024 · 5 comments
Open

How to whitelist tag attributes in xss validator? (Error in docs) #426

MickL opened this issue Apr 15, 2024 · 5 comments
Labels
question Further information is requested
Milestone

Comments

@MickL
Copy link

MickL commented Apr 15, 2024

How can I whitelist tag attributes in the xss validator? The docs say:

{ 'tagName': 'attr-1', 'attr-2' }

But this would be invalid TypeScript. I guess you meant to use an array?

{ 'tagName': ['attr-1', 'attr-2'] }

If yes then it doesnt work for me: whiteList: { a: ['href', 'target', 'rel'] }. I can whitelist tags like strong but I cant whitelist a tag with attributes. Maybe it is a bug also.

@MickL MickL added the question Further information is requested label Apr 15, 2024
@Baroshem
Copy link
Owner

Hey Buddy,

Thanks for reporting this issue. The XSS validator uses the xss js package so it could be the upstream issue. As you suggest, I think there is also an issue in the documentation that dhoukd be fixed.

@MickL
Copy link
Author

MickL commented Apr 15, 2024

Can you reproduce? Maybe it is an upstream issue, it doesnt work like this: whiteList: { strong, a: ['href', 'target', 'rel'] } -> Usage of <strong> is ok, <a href="#">abc</a> not.

Maybe because the json arrives like this? <a href=\"#\">abc</a>

Also this xss validation things are very very hard to debug because there is no console log output why a request has been blocked.

@Baroshem
Copy link
Owner

Yes, I can reproduce and I think it is related with #206

When I passed this string with yours whitelist xss validation configuration I got:

{ text: '<a href="' }

I think the issue is not related with whitelisting not working but rather with the fact that underlying package escapes the > character which results in an error for you.

Would you be interested in contributing to the project with a PoC of something that could fix this problem? :)

@MickL
Copy link
Author

MickL commented Apr 22, 2024

Unfortunately I dont have the time and probably also the insights :(

@Baroshem
Copy link
Owner

Ok, I will take a look at it in the upcoming days to see if I can fix it somehow

@Baroshem Baroshem added this to the 2.0.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants