Comments (4)
from owasp-java-encoder.
Sure, here is an example
JSP file:
<%@ taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %>
<script type="text/javascript">
var i = -5; //this will normally be var i = ${variableFromController}
console.log(${e:forJavaScript(i)});
console.log(${e:forJavaScript(-6)});
</script>
The browser will see the first console.log(${e:forJavaScript(i)});
as console.log();
(literally no argument) while the second console.log(${e:forJavaScript(-6)});
as console.log(\-6);
which is a syntax error.
So, both console.log lines seem to produce invalid end result. What should I do in this case?
from owasp-java-encoder.
from owasp-java-encoder.
Hi Jim,
Thank you for your response!
First of all be sure to QUOTE all JS variables that come from untrusted data.
But I don't want to quote integers as they will become strings in that case (and I want numbers).
Also can you try this for me?
The following lines are not a valid javascript:
*alert ("test: " + (7 + **i));*
alert ("test: " + (7 + **i));
So, I assume you meant:
alert ("test: " + (7 + i));
which will of course create an alert with "test: 2" message.
After some thoughts, it might be that might question is silly. I just wanted to use escaping in order to protect Javascript code from XSS which is obviously necessary for strings. However, for numbers, I should probably just just native javascript functions: parseInt() or parseFloat(). They will make sure the input is safe in use in Javascript context.
Thank you for helping me realize that!
from owasp-java-encoder.
Related Issues (20)
- Configuring exclusions for `Encode.forHtml()` HOT 5
- Rename main branch HOT 1
- Create encode for URL function HOT 9
- Support for input canonicalization HOT 6
- JavaScriptEncoder escapes "-" what makes dates escaped HOT 6
- Create an encodeForEmail() function HOT 4
- Possible to inject expression property resulting XSS attack in IE browser by using certain document modes HOT 2
- Please sign the jar HOT 12
- Documentation Frames Broken by Content-Security-Policy HOT 1
- Process for reporting possible security vulnerabilties
- Correct javadoc for Encode class HOT 1
- Javadoc link is broken HOT 4
- Alternative method for deprecated forUri() method HOT 1
- Jsp tags not working together with EL expressions HOT 3
- log4j 1.2.17 dependency HOT 6
- Compile error HOT 6
- Any plans for a version using Jakarta Servlet 5.0? HOT 4
- Automatic module name not included in manifest
- I couldn't sanitize the vector "<%<!--'%><script>alert(1);</script -->", using the methods available in "encoder-1.2.3.jar". HOT 3
- Combining OWASP Sanitizer and Encoder HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from owasp-java-encoder.