-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Java: Add MaDs for java.crypto.KDF
#20345
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
base: main
Are you sure you want to change the base?
Conversation
Click to show differences in coveragejavaGenerated file changes for java
- Java extensions,"``javax.*``, ``jakarta.*``",87,4159,90,10,4,2,1,1,4
+ Java extensions,"``javax.*``, ``jakarta.*``",87,4189,90,10,4,2,1,1,4
- Totals,,330,26328,2656,404,16,128,33,1,409
+ Totals,,330,26358,2656,404,16,128,33,1,409
- javax.crypto,19,,114,,,12,3,,2,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,61,53
+ javax.crypto,19,,144,,,12,3,,2,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,83,61 |
e284e6e
to
fa73d5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Model as Data (MaD) support for the java.crypto.KDF
API, enabling taint tracking through Key Derivation Function operations. The changes include comprehensive taint flow models for KDF operations and HKDF parameter specifications.
- Adds taint flow models for
javax.crypto.KDF
class methods - Adds taint flow models for
javax.crypto.spec.HKDFParameterSpec
and its builder pattern - Includes comprehensive test coverage for various KDF usage patterns
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
java/ql/lib/ext/javax.crypto.model.yml |
Adds summary models for KDF class methods including deriveKey and deriveData |
java/ql/lib/ext/javax.crypto.spec.model.yml |
Adds taint flow models for HKDF parameter specification builder methods and constructors |
java/ql/test/library-tests/dataflow/kdf/test.ql |
Test query for verifying taint flow through KDF operations |
java/ql/test/library-tests/dataflow/kdf/KDFDataflowTest.java |
Comprehensive test cases covering various KDF usage patterns |
java/ql/test/library-tests/dataflow/kdf/options |
Compilation options enabling Java 25 preview features |
java/ql/lib/change-notes/2025-09-02-kdf-api.md |
Release notes documenting the new KDF taint flow support |
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addSalt", "(SecretKey)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "thenExpand", "(byte[],int)", "", "Argument[this]", "ReturnValue", "taint", "manual"] | ||
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "thenExpand", "(byte[],int)", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
- ["javax.crypto.spec", "HKDFParameterSpec", False, "ofExtract", "()", "", "", "ReturnValue", "taint", "manual"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ofExtract()
method creates a clean builder instance and should not propagate taint by itself. Taint should only flow when actual key material is added via addIKM()
methods. This model could lead to false positives where clean HKDF operations are flagged as tainted.
- ["javax.crypto.spec", "HKDFParameterSpec", False, "ofExtract", "()", "", "", "ReturnValue", "taint", "manual"] |
Copilot uses AI. Check for mistakes.
fa73d5e
to
ccfbf55
Compare
a34b362
to
5d2268f
Compare
- ["javax.crypto", "KDF", False, "getInstance", "(String,KDFParameters,Provider)", "", "Argument[0]", "ReturnValue.SyntheticField[javax.crypto.KDF.algorithm]", "value", "manual"] | ||
- ["javax.crypto", "KDF", False, "getInstance", "(String,KDFParameters,String)", "", "Argument[0]", "ReturnValue.SyntheticField[javax.crypto.KDF.algorithm]", "value", "manual"] | ||
- ["javax.crypto", "KDF", True, "getAlgorithm", "()", "", "Argument[this].SyntheticField[javax.crypto.KDF.algorithm]", "ReturnValue", "value", "manual"] | ||
- ["javax.crypto", "KDF", True, "getProvider", "()", "", "Argument[this]", "ReturnValue", "value", "manual"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line looks suspicious. It suggests that getProvider()
is implemented as return this
. Should this have been a taint model rather than a value-preserving step?
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[0]", "Argument[this]", "taint", "manual"] | ||
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[0]", "ReturnValue", "taint", "manual"] | ||
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[this]", "ReturnValue", "taint", "manual"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fluent method so the flow from this to return should be value
. Once that's fixed, the two lines above will contain redundant information, as MaD has some support for fluent apis: You only need to provide the taint model that taints the argument - then the model that taints the output will be automatically added.
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[0]", "Argument[this]", "taint", "manual"] | |
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[0]", "ReturnValue", "taint", "manual"] | |
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[this]", "ReturnValue", "taint", "manual"] | |
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[0]", "Argument[this]", "taint", "manual"] | |
- ["javax.crypto.spec", "HKDFParameterSpec$Builder", True, "addIKM", "(byte[])", "", "Argument[this]", "ReturnValue", "value", "manual"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies to the other fluent api models below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll fix this 👍
@@ -16,30 +16,6 @@ methodWithDuplicate | |||
| AbstractCollection<E> | removeAll | Collection<?> | | |||
| AbstractCollection<E> | retainAll | Collection<?> | | |||
| AbstractCollection<E> | toArray | T[] | | |||
| AbstractCollection<Entry<K,V>> | add | Entry<K,V> | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff doesn't belong on this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, none of the Kotlin changes are part of this PR. I updated the base to idrissrio/java-upgrade-fix, so that commit now appears as well. Rebasing should remove it from the UI. You can safely ignore anything related to Kotlin.
|
||
KDF kdf = KDF.getInstance("HKDF-SHA256"); | ||
byte[] result = kdf.deriveData(spec); | ||
sink(result); // should flag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use inline expectation
Updates Java MaDs for
java.crypto.KDF
.Java Docs - KDF: https://docs.oracle.com/en/java/javase/24/docs/api/java.base/javax/crypto/KDF.html
Java Docs - HKDFParameterSpec: https://docs.oracle.com/en/java/javase/24/docs/api/java.base/javax/crypto/spec/HKDFParameterSpec.html
Java release note: https://jdk.java.net/25/release-notes#510