Skip to content

Commit 7e1534a

Browse files
committed
Java: migrate 'arg to return' taint steps to CSV
1 parent 5cdbde2 commit 7e1534a

File tree

2 files changed

+24
-57
lines changed

2 files changed

+24
-57
lines changed

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,30 @@ private predicate summaryModelCsv(string row) {
203203
"java.io;File;false;toPath;;;Argument[-1];ReturnValue;taint",
204204
"java.nio.file;Path;false;toFile;;;Argument[-1];ReturnValue;taint",
205205
"java.io;Reader;true;readLine;;;Argument[-1];ReturnValue;taint",
206-
"java.io;Reader;true;read;();;Argument[-1];ReturnValue;taint"
206+
"java.io;Reader;true;read;();;Argument[-1];ReturnValue;taint",
207+
// arg to return
208+
"java.util;Base64$Encoder;false;encode;(byte[]);;Argument[0];ReturnValue;taint",
209+
"java.util;Base64$Encoder;false;encode;(ByteBuffer);;Argument[0];ReturnValue;taint",
210+
"java.util;Base64$Encoder;false;encodeToString;(byte[]);;Argument[0];ReturnValue;taint",
211+
"java.util;Base64$Encoder;false;wrap;(OutputStream);;Argument[0];ReturnValue;taint",
212+
"java.util;Base64$Decoder;false;decode;(byte[]);;Argument[0];ReturnValue;taint",
213+
"java.util;Base64$Decoder;false;decode;(ByteBuffer);;Argument[0];ReturnValue;taint",
214+
"java.util;Base64$Decoder;false;decode;(String);;Argument[0];ReturnValue;taint",
215+
"java.util;Base64$Decoder;false;wrap;(InputStream);;Argument[0];ReturnValue;taint",
216+
"org.apache.commons.codec;Encoder;true;encode;;;Argument[0];ReturnValue;taint",
217+
"org.apache.commons.codec;Decoder;true;decode;;;Argument[0];ReturnValue;taint",
218+
"org.apache.commons.io;IOUtils;false;buffer;;;Argument[0];ReturnValue;taint",
219+
"org.apache.commons.io;IOUtils;false;readLines;;;Argument[0];ReturnValue;taint",
220+
"org.apache.commons.io;IOUtils;false;readFully;(InputStream,int);;Argument[0];ReturnValue;taint",
221+
"org.apache.commons.io;IOUtils;false;toBufferedInputStream;;;Argument[0];ReturnValue;taint",
222+
"org.apache.commons.io;IOUtils;false;toBufferedReader;;;Argument[0];ReturnValue;taint",
223+
"org.apache.commons.io;IOUtils;false;toByteArray;;;Argument[0];ReturnValue;taint",
224+
"org.apache.commons.io;IOUtils;false;toCharArray;;;Argument[0];ReturnValue;taint",
225+
"org.apache.commons.io;IOUtils;false;toInputStream;;;Argument[0];ReturnValue;taint",
226+
"org.apache.commons.io;IOUtils;false;toString;;;Argument[0];ReturnValue;taint",
227+
"java.net;URLDecoder;false;decode;;;Argument[0];ReturnValue;taint",
228+
"java.net;URI;false;create;;;Argument[0];ReturnValue;taint",
229+
"javax.xml.transform.sax;SAXSource;false;sourceToInputSource;;;Argument[0];ReturnValue;taint"
207230
]
208231
}
209232

java/ql/src/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -367,69 +367,13 @@ private predicate argToMethodStep(Expr tracked, MethodAccess sink) {
367367
* `arg`th argument is tainted.
368368
*/
369369
private predicate taintPreservingArgumentToMethod(Method method, int arg) {
370-
(
371-
method.getDeclaringType().hasQualifiedName("java.util", "Base64$Encoder") or
372-
method.getDeclaringType().hasQualifiedName("java.util", "Base64$Decoder") or
373-
method
374-
.getDeclaringType()
375-
.getASupertype*()
376-
.hasQualifiedName("org.apache.commons.codec", "Encoder") or
377-
method
378-
.getDeclaringType()
379-
.getASupertype*()
380-
.hasQualifiedName("org.apache.commons.codec", "Decoder")
381-
) and
382-
(
383-
method.getName() = "encode" and arg = 0 and method.getNumberOfParameters() = 1
384-
or
385-
method.getName() = "decode" and arg = 0 and method.getNumberOfParameters() = 1
386-
or
387-
method.getName() = "encodeToString" and arg = 0
388-
or
389-
method.getName() = "wrap" and arg = 0
390-
)
391-
or
392370
method.getDeclaringType().hasQualifiedName("org.apache.commons.codec.binary", "Base64") and
393371
(
394372
method.getName() = "decodeBase64" and arg = 0
395373
or
396374
method.getName().matches("encodeBase64%") and arg = 0
397375
)
398376
or
399-
method.getDeclaringType().hasQualifiedName("org.apache.commons.io", "IOUtils") and
400-
(
401-
method.getName() = "buffer" and arg = 0
402-
or
403-
method.getName() = "readLines" and arg = 0
404-
or
405-
method.getName() = "readFully" and arg = 0 and method.getParameterType(1).hasName("int")
406-
or
407-
method.getName() = "toBufferedInputStream" and arg = 0
408-
or
409-
method.getName() = "toBufferedReader" and arg = 0
410-
or
411-
method.getName() = "toByteArray" and arg = 0
412-
or
413-
method.getName() = "toCharArray" and arg = 0
414-
or
415-
method.getName() = "toInputStream" and arg = 0
416-
or
417-
method.getName() = "toString" and arg = 0
418-
)
419-
or
420-
method.getDeclaringType().hasQualifiedName("java.net", "URLDecoder") and
421-
method.hasName("decode") and
422-
arg = 0
423-
or
424-
// A URI created from a tainted string is still tainted.
425-
method.getDeclaringType() instanceof TypeUri and
426-
method.hasName("create") and
427-
arg = 0
428-
or
429-
method.getDeclaringType().hasQualifiedName("javax.xml.transform.sax", "SAXSource") and
430-
method.hasName("sourceToInputSource") and
431-
arg = 0
432-
or
433377
method.(TaintPreservingCallable).returnsTaintFrom(arg)
434378
}
435379

0 commit comments

Comments
 (0)