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

whiteList does nothing #247

Open
chladnefazole opened this issue Nov 23, 2021 · 1 comment
Open

whiteList does nothing #247

chladnefazole opened this issue Nov 23, 2021 · 1 comment

Comments

@chladnefazole
Copy link

chladnefazole commented Nov 23, 2021

I have whitelist:

	{
		'!doctype': ['html'],
		meta: ['name', 'content', 'charset'],
		html: ['lang'],
		style: [],
		head: [],
		title: [],
		body: ['class'],
		footer: []
	},

But style, head, body, html tags are all being escaped still. table, tr, td, tbody, p, h1, h2 tags are not escaped. Basically, the list does nothing at all.

I am using the library via a CDN and therefore I'm calling the function like so:
var cleanHtml = filterXSS(dirtyHtml, sanitizerOptions);

@chladnefazole chladnefazole changed the title WhiteList settings replacing default whitelist whiteList does nothing Nov 23, 2021
@leizongmin
Copy link
Owner

Hi, @chladnefazole please try this example code:

var dirtyHtml =
  '<!doctype html><head><meta charset="utf-8" name="xx" content="yy"><title>Test</title><style></style></head><body class="aa"><footer></footer><div></div></body>';
var sanitizerOptions = {
  whiteList: {
    "!doctype": ["html"],
    meta: ["name", "content", "charset"],
    html: ["lang"],
    style: [],
    head: [],
    title: [],
    body: ["class"],
    footer: [],
  },
};
var cleanHtml = filterXSS(dirtyHtml, sanitizerOptions);
console.log(cleanHtml);

we can get the following result:

<!doctype html><head><meta charset="utf-8" name="xx" content="yy"><title>Test</title><style></style></head><body class="aa"><footer></footer>&lt;div&gt;&lt;/div&gt;</body>

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