12 Matching Annotations
- Aug 2022
-
cheatsheetseries.owasp.org cheatsheetseries.owasp.org
-
If you're using JavaScript for writing to a HTML Attribute, look at the .setAttribute and [attribute] methods which will automatically HTML Attribute Encode. Those are Safe Sinks as long as the attribute name is hardcoded and innocuous, like id or class.
-
If you're using JavaScript for writing to HTML, look at the .textContent attribute as it is a Safe Sink and will automatically HTML Entity Encode.
-
- Oct 2020
-
www.onwebsecurity.com www.onwebsecurity.com
-
Yet it can be deceivingly difficult to properly encode (user) input
They were talking about output encoding but then switched to input encoding? Did they really mean to say input encoding here?
-
When processing untrusted user input for (web) applications, filter the input, and encode the output.
-
Encoding is dependent on the type of output - which means that for example a string, which will be used in a JavaScript variable, should be treated (encoded) differently than a string which will be used in plain HTML.
-
- Apr 2020
-
makandracards.com makandracards.com
-
What we actually want to do is to escape content if it is unsafe, but leave it unescaped if it is safe. To achieve this we can simply use SafeBuffer's concatenation behavior:
-
Our helper still returns a safe string, but correctly escapes content if it is unsafe. Note how much more flexible our group helper has become because it now works as expected with both safe and unsafe arguments. We can now leave it up to the caller whether to mark input as safe or not, and we no longer need to make any assumptions about the safeness of content.
-
A common mistake is to see those escaped angle brackets, and "improve" the helper by making everything html_safe:
-
-
security.stackexchange.com security.stackexchange.com
-
You don't "sanitize your output" you encode it for proper context within the application it is being presented. You encode the output for HTML, HTML Attribute, URL, JavaScript
-
When you output the data, you know the use case of the data. This knowledge allows you to safely sanitize the output data accordingly.
-
I would call this output encoding instead of sanitization
-
-
wpvip.com wpvip.com
-
1- Validation: you “validate”, ie deem valid or invalid, data at input time. For instance if asked for a zipcode user enters “zzz43”, that’s invalid. At this point, you can reject or… sanitize. 2- sanitization: you make data “sane” before storing it. For instance if you want a zipcode, you can remove any character that’s not [0-9] 3- escaping: at output time, you ensure data printed will never corrupt display and/or be used in an evil way (escaping HTML etc…)
-