@@ -36,6 +36,50 @@ public class DynamicPropagatorScanner implements IVulScan {
3636 new HttpService ()
3737 ));
3838
39+ // VulnType => List<TAGS, UNTAGS>
40+ private static final Map <String , List <TaintTag []>> TAINT_TAG_CHECKS = new HashMap <String , List <TaintTag []>>() {{
41+ put (VulnType .REFLECTED_XSS .getName (), Arrays .asList (
42+ new TaintTag []{TaintTag .UNTRUSTED , TaintTag .CROSS_SITE },
43+ new TaintTag []{TaintTag .BASE64_ENCODED , TaintTag .HTML_ENCODED , TaintTag .LDAP_ENCODED ,
44+ TaintTag .SQL_ENCODED , TaintTag .URL_ENCODED , TaintTag .XML_ENCODED , TaintTag .XPATH_ENCODED ,
45+ TaintTag .XSS_ENCODED , TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
46+ ));
47+ put (VulnType .SQL_INJECTION .getName (), Arrays .asList (
48+ new TaintTag []{TaintTag .UNTRUSTED },
49+ new TaintTag []{TaintTag .SQL_ENCODED , TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
50+ ));
51+ put (VulnType .HQL_INJECTION .getName (), Arrays .asList (
52+ new TaintTag []{TaintTag .UNTRUSTED },
53+ new TaintTag []{TaintTag .SQL_ENCODED , TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
54+ ));
55+ put (VulnType .LDAP_INJECTION .getName (), Arrays .asList (
56+ new TaintTag []{TaintTag .UNTRUSTED },
57+ new TaintTag []{TaintTag .BASE64_ENCODED , TaintTag .HTML_ENCODED , TaintTag .LDAP_ENCODED ,
58+ TaintTag .SQL_ENCODED , TaintTag .URL_ENCODED , TaintTag .XML_ENCODED , TaintTag .XPATH_ENCODED ,
59+ TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
60+ ));
61+ put (VulnType .XPATH_INJECTION .getName (), Arrays .asList (
62+ new TaintTag []{TaintTag .UNTRUSTED },
63+ new TaintTag []{TaintTag .XML_ENCODED , TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
64+ ));
65+ put (VulnType .CMD_INJECTION .getName (), Arrays .asList (
66+ new TaintTag []{TaintTag .UNTRUSTED },
67+ new TaintTag []{TaintTag .BASE64_ENCODED , TaintTag .HTML_ENCODED , TaintTag .LDAP_ENCODED ,
68+ TaintTag .SQL_ENCODED , TaintTag .URL_ENCODED , TaintTag .XML_ENCODED , TaintTag .XPATH_ENCODED ,
69+ TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
70+ ));
71+ put (VulnType .PATH_TRAVERSAL .getName (), Arrays .asList (
72+ new TaintTag []{TaintTag .UNTRUSTED },
73+ new TaintTag []{TaintTag .BASE64_ENCODED , TaintTag .HTML_ENCODED , TaintTag .LDAP_ENCODED ,
74+ TaintTag .URL_ENCODED , TaintTag .XML_ENCODED , TaintTag .XPATH_ENCODED ,
75+ TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
76+ ));
77+ put (VulnType .UNVALIDATED_REDIRECT .getName (), Arrays .asList (
78+ new TaintTag []{TaintTag .UNTRUSTED },
79+ new TaintTag []{TaintTag .URL_ENCODED , TaintTag .HTTP_TOKEN_LIMITED_CHARS , TaintTag .NUMERIC_LIMITED_CHARS }
80+ ));
81+ }};
82+
3983 @ Override
4084 public void scan (MethodEvent event , SinkNode sinkNode ) {
4185 for (SinkSafeChecker chk : SAFE_CHECKERS ) {
@@ -118,29 +162,28 @@ private boolean sinkSourceHitTaintPool(MethodEvent event, SinkNode sinkNode) {
118162 }
119163
120164
121- // TODO: check taint tags at server
122- if (VulnType .REFLECTED_XSS .equals (sinkNode .getVulType ()) && !sourceInstances .isEmpty ()) {
123- boolean tagsHit = false ;
124- for (Object sourceInstance : sourceInstances ) {
125- long hash = TaintPoolUtils .getStringHash (sourceInstance );
126- TaintRanges tr = EngineManager .TAINT_RANGES_POOL .get (hash );
127- if (tr == null || tr .isEmpty ()) {
128- continue ;
165+ if (!sourceInstances .isEmpty ()) {
166+ List <TaintTag []> tagList = TAINT_TAG_CHECKS .get (sinkNode .getVulType ());
167+ if (tagList != null ) {
168+ boolean tagsHit = false ;
169+ TaintTag [] required = tagList .get (0 );
170+ TaintTag [] disallowed = tagList .get (1 );
171+
172+ for (Object sourceInstance : sourceInstances ) {
173+ long hash = TaintPoolUtils .getStringHash (sourceInstance );
174+ TaintRanges tr = EngineManager .TAINT_RANGES_POOL .get (hash );
175+ if (tr == null || tr .isEmpty ()) {
176+ continue ;
177+ }
178+
179+ if (tr .hasRequiredTaintTags (required ) && !tr .hasDisallowedTaintTags (disallowed )) {
180+ tagsHit = true ;
181+ }
129182 }
130- TaintTag [] required = new TaintTag []{
131- TaintTag .UNTRUSTED , TaintTag .CROSS_SITE
132- };
133- TaintTag [] disallowed = new TaintTag []{
134- TaintTag .XSS_ENCODED , TaintTag .URL_ENCODED ,
135- TaintTag .HTML_ENCODED , TaintTag .BASE64_ENCODED
136- };
137- if (tr .hasRequiredTaintTags (required ) && !tr .hasDisallowedTaintTags (disallowed )) {
138- tagsHit = true ;
183+ if (!tagsHit ) {
184+ return false ;
139185 }
140186 }
141- if (!tagsHit ) {
142- return false ;
143- }
144187 }
145188
146189 if (hasTaint ) {
0 commit comments