Repository navigation
[java] Fix #7008: HardCodedCryptoKey: False positive when a default value of System.getProperty() is treated as a hard-coded key - #7012
Conversation
|
Compared to main: (comment created at 2026-09-14 18:40:14+00:00 for 53e616e) |
renechoi
left a comment
There was a problem hiding this comment.
The System.getProperty guard only fires when that call is the expression being validated. When it is the qualifier, the FP survives. Both of these still report on this branch, on the property name, not the default:
new SecretKeySpec(System.getProperty("k", "d").getBytes(), "AES");
new SecretKeySpec(System.getProperty("k").getBytes(), "AES");
else if (SYSTEM_GET_PROPERTY.matchesCall(expr)) { return; } in the existing qualifier branch clears both, HardCodedCryptoKeyTest and InsecureCryptoIvTest green (21/21).
The array-initializer test also passes on unpatched main.
lukasgraef
left a comment
There was a problem hiding this comment.
Hi @MakerYuichi,
thanks for your contribution!
Please have a look at the release notes formatting and @renechoi's review comment.
Both should be addressed.
Added fixed issues and API changes sections to release notes.
|
Thanks again! I will take care of cleanup and merging. |
Describe the PR
HardCodedCryptoKeyRule(and the sharedAbstractHardCodedConstructorArgsVisitorit's built on) was flagging calls likeSystem.getProperty("test.key", "secretKey")as a hard-coded cryptographic key, because it scanned for any string literal inside the resolved argument expression including the property name and default value passed toSystem.getProperty, even though the actual value used at runtime may come from an external system property.This PR adds a check using
InvocationMatcherto recognize calls toSystem.getProperty(String)andSystem.getProperty(String, String), and skips flagging when the argument comes from one of these calls, since no string literal present is necessarily the actual key.While adding a regression test for this, I found and fixed a related but separate gap:
ASTArrayInitializervalues on the direct assignment path (e.g.byte[] key = { 0, 1, 2, ... }; new SecretKeySpec(key, "AES")) were not being reported at all — only theASTArrayAllocationform (byte[] key = new byte[] { ... }) was previously covered on that path.Added a test case and fix for this too.
Related issues
Fix #7008
Ready?
./mvnw clean verifypasses (checked automatically by github actions)