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 solve the problem of " being escaped in json strings #562

Open
aduoer opened this issue Feb 26, 2025 · 3 comments
Open

How to solve the problem of " being escaped in json strings #562

aduoer opened this issue Feb 26, 2025 · 3 comments

Comments

@aduoer
Copy link

aduoer commented Feb 26, 2025

Input: {
"names":"["alex","bob"]"
}
Expected output: {
"names":"["alex","bob"]"
}
Current output: {
"names":"[&quto;alex&quto;,&quto;bob&quto;]"
}

antisamy version: 1.7.7

@davewichers
Copy link
Collaborator

Can you please explain how you are using AntiSamy to do this? We need more details to be able to review/respond appropriately. cc @spassarop

@aduoer
Copy link
Author

aduoer commented Feb 27, 2025

Can you please explain how you are using AntiSamy to do this? We need more details to be able to review/respond appropriately. cc @spassarop

When using AntiSamy as an XSS filter, if your input parameters contain JSON strings and you want to avoid converting escaped characters like " back to " after processing, here's the solution:

​Problem Analysis
AntiSamy automatically escapes special characters to sanitize HTML/XML contexts. However, this breaks JSON validity if the input is a JSON string (e.g., {"key":"value"} becomes {"key":"value"}).

@davewichers
Copy link
Collaborator

@aduoer - Can you edit your response to properly escape it, because all your encoded stuff is decoded automatically when viewing it. You need to look at the 'Preview' view to make sure it looks like you intend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants