Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False Negative: String concatenation with char should not consider char to be SAFE #711

Open
jbindel opened this issue Aug 17, 2023 · 1 comment

Comments

@jbindel
Copy link
Contributor

jbindel commented Aug 17, 2023

Environment

Component Version
Java 8
SpotBugs 4.7.3
FindSecBugs 1.12.0

Problem

False negative when concatenating a character onto a String. Characters should not be considered SAFE in the taint configuration. This affects several detectors that rely on the standard taint configuration.

Concatenating strings propagates the taint configuration of the input strings to the resulting string. The current configuration files consider concatenation of all primitive types to be safe, but the char type is not safe to concatenate.

Code

The example code relies on the findsecbugs-plugin/src/main/resources/taint-config/java-lang.txt configuration that declares java/lang/StringBuilder.append(C)Ljava/lang/StringBuilder;:1. PATH_TRAVERSAL_IN is one of the patterns that relies on taint analysis though many others do as well and are similarly affected.

The rules in java-lang.txt for StringBuffer are similarly affected, and there may be additional taint configuration rules that do the same.

import java.io.FileInputStream;
import java.io.IOException;

/**
 * Both methods create the same string input to FileInputStream from the same inputs.
 * Only the second method produces a positive PATH_TRAVERSAL_IN finding.
 * /
public class Example {
	public static FileInputStream falseNegative(String file, String foo) throws IOException {
		StringBuilder buf = new StringBuilder();
		// The foo variable is not trusted, and we circumvent that by
		// breaking it into a char array.
		for (char c : foo.toCharArray()) {
			buf.append(c);
		}
		return new FileInputStream("Hello" + buf);
	}

	public static FileInputStream truePositive(String file, String foo) throws IOException {
		return new FileInputStream("Hello" + foo);
	}
}
@jbindel jbindel changed the title False Negative: String concatenation with char should not be considered SAFE False Negative: String concatenation with char should not consider char to be SAFE Aug 17, 2023
@jbindel
Copy link
Contributor Author

jbindel commented Aug 18, 2023

See Pull Request #712

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant