Skip to content

Report hashes of jars that we can resolve to dependencies - #338

Open
hansott wants to merge 2 commits into
scafrom
sca-java-artifact-hashes
Open

Report hashes of jars that we can resolve to dependencies#338
hansott wants to merge 2 commits into
scafrom
sca-java-artifact-hashes

Conversation

@hansott

@hansott hansott commented Aug 14, 2026

Copy link
Copy Markdown
Member

No description provided.

if (!packages.isEmpty()) {
return new JarScanResult(packages, null);
}
try (InputStream input = new BufferedInputStream(outerJar.getInputStream(nestedJar))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested JAR is read completely once for package scanning and again for SHA-1 calculation. Compute the digest during the initial pass to avoid doubling I/O for unresolved archives.

Details

✨ AI Reasoning
​The initial scan consumes the entire nested archive while looking for Maven metadata. When no packages are found, the code opens the same archive again and reads it from start to finish for hashing. This doubles disk or archive-stream work for every unresolved nested JAR and can be avoided by computing the digest during the first pass.

🔧 How do I fix it?
Move constant work outside loops. Use StringBuilder instead of string concatenation in loops. Cache compiled regex patterns. Use hash-based lookups instead of nested loops. Batch database operations instead of N+1 queries.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

Can't use std lib because we support several java versions
RoutesStore.clear();
UsersStore.clear();
RuntimePackagesStore.clear();
JavaArtifactsStore.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium - Artifact hashes are dropped permanently when a heartbeat fails

The new Java artifact inventory is cleared before the heartbeat is sent, so any network error or non-successful heartbeat response discards every collected hash from memory. Those hashes are only queued once per JAR location because observed locations are deduplicated permanently, so the collector will not recreate them after a transient outage. A temporary API failure therefore leaves the backend with a permanently incomplete artifact inventory until the process restarts or a new JAR is loaded.

Show fix

Do not delete JavaArtifactsStore before the heartbeat has been accepted. Instead, drain artifacts atomically only after a successful report, or keep a retry buffer and reinsert unsent artifacts when the heartbeat fails so transient API outages cannot permanently lose the one-time scan results.

More info - Reply on this comment to give feedback or ignore the issue.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

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

Successfully merging this pull request may close these issues.

1 participant