Is it XSS safe to allow clients to submit jQuery selectors?
I would run a selector string submitted potentially by trolls and put it into $('') to select elements on the page.
Is it XSS safe to allow clients to submit jQuery selectors?
I would run a selector string submitted potentially by trolls and put it into $('') to select elements on the page.
Copyright © 2021 Jogjafile Inc.
Ref: https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
Most of the time, ids are letters and digits, with hyphens or underscores. This code requires that the first character of the id is a letter, followed by more letters, numbers, underscores and dashes.
If you are willing to limit the accessible element ids in that way, you may use the following validation scheme to prevent XSS.
JavaScript (would run on the server)
PHP
This limits entry to simple ids, and it is implied you would add the # into the selector. If you are willing to allow more complex selectors, you can update the validation.