Json.parse is a safe evaluation
This commit is contained in:
@ -75,8 +75,10 @@ public class VfUnescapeElRule extends AbstractVfRule {
|
||||
|
||||
private void processElInScriptContext(ASTElExpression elExpression, ASTText prevText, Object data) {
|
||||
boolean quoted = false;
|
||||
boolean jsonParse = false;
|
||||
|
||||
if (prevText != null) {
|
||||
jsonParse = isJsonParse(prevText);
|
||||
if (isUnbalanced(prevText.getImage(), '\'') || isUnbalanced(prevText.getImage(), '\"')) {
|
||||
quoted = true;
|
||||
}
|
||||
@ -90,12 +92,21 @@ public class VfUnescapeElRule extends AbstractVfRule {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!(startsWithSafeResource(elExpression) || containsSafeFields(elExpression))) {
|
||||
if (!(jsonParse || startsWithSafeResource(elExpression) || containsSafeFields(elExpression))) {
|
||||
addViolation(data, elExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isJsonParse(ASTText prevText) {
|
||||
if (prevText.getImage().endsWith("JSON.parse(") || prevText.getImage().endsWith("jQuery.parseJSON(")
|
||||
|| prevText.getImage().endsWith("$.parseJSON(")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isUnbalanced(String image, char pattern) {
|
||||
char[] array = image.toCharArray();
|
||||
|
||||
|
@ -557,6 +557,7 @@ Safe unquoted followed by safe quoted
|
||||
]]></code>
|
||||
<source-type>vf</source-type>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
NOT method evaluates to safe boolean
|
||||
@ -572,5 +573,21 @@ NOT method evaluates to safe boolean
|
||||
<source-type>vf</source-type>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
JSON.parse method evaluates to safe JSON
|
||||
]]></description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
<apex:page>
|
||||
<script>
|
||||
var x = JSON.parse({!yes});
|
||||
jQuery.parseJSON({!yes});
|
||||
$.parseJSON({!yes});
|
||||
</script>
|
||||
</apex:page>
|
||||
]]></code>
|
||||
<source-type>vf</source-type>
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user