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

[DONOTMERGE] SONARAJAVA-5010 #4869

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.sonar.plugins.java.api.JavaFileScannerContext;
import org.sonar.plugins.java.api.semantic.MethodMatchers;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree;
import org.sonar.plugins.java.api.tree.BinaryExpressionTree;
import org.sonar.plugins.java.api.tree.ConditionalExpressionTree;
import org.sonar.plugins.java.api.tree.ExpressionTree;
Expand Down Expand Up @@ -108,6 +109,12 @@ public static boolean isExpressionDerivedFromPlainText(ExpressionTree expression
Set<Symbol> visited) {
ExpressionTree arg = ExpressionUtils.skipParentheses(expression);
switch (arg.kind()) {
case ARRAY_ACCESS_EXPRESSION:
var access = (ArrayAccessExpressionTree) arg;
IdentifierTree arrayIdentifier = (IdentifierTree) access.expression();
VariableTree variable = (VariableTree) arrayIdentifier.symbol().declaration();
NewArrayTree initializer = (NewArrayTree) variable.initializer();
return isDerivedFromPlainText(initializer, secondaryLocations, visited);
case IDENTIFIER:
IdentifierTree identifier = (IdentifierTree) arg;
return isDerivedFromPlainText(identifier, secondaryLocations, visited);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public class HardCodedCredentialsShouldNotBeUsedCheckSample {
private static char[] secretCharArrayField = new char[]{0xC, 0xA, 0xF, 0xE};
private static CharSequence secretCharSequenceField = "Hello, World!".subSequence(0, 12);

public static final String[] SECRETS = {"secret_key"};
public static final String JWT_SECRET = SECRETS[0];

public String getSecretToken() {
return Jwts.builder()
.signWith(SignatureAlgorithm.HS256, JWT_SECRET)
.compact();
}

public static void nonCompliant(byte[] message, boolean condition, Charset encoding, SignatureAlgorithm paremSignatureAlgorithm) throws ServletException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, UnsupportedEncodingException, jakarta.servlet.ServletException {
// byte array based
SHA256.getHMAC(FINAL_SECRET_BYTE_ARRAY, message); // Noncompliant {{Revoke and change this password, as it is compromised.}}
Expand Down