Skip to content

Avoid sha-1 resource load for remote download verification.#1547

Closed
timw wants to merge 1 commit into
chains-project:mainfrom
indexity-io:feature/sha1-validation-headers
Closed

Avoid sha-1 resource load for remote download verification.#1547
timw wants to merge 1 commit into
chains-project:mainfrom
indexity-io:feature/sha1-validation-headers

Conversation

@timw
Copy link
Copy Markdown
Contributor

@timw timw commented Apr 16, 2026

As per https://maven.apache.org/resolver/expected-checksums.html#non-standard-x-headers, many repository managers provide the SHA-1 in a header already, so the extra request can be avoided.

Fixes #1543

As per https://maven.apache.org/resolver/expected-checksums.html#non-standard-x-headers, many repository managers provide the sha-1 in a header already, so the extra request can be avoided.

Fixes chains-project#1543
@algomaster99
Copy link
Copy Markdown
Member

Hi @timw ! Thanks for your PRs. I have been a bit busy with other things, so I have not had time to look through them. Maybe @LogFlames can you take a look at this and the other two PRs if you have time?

Copy link
Copy Markdown
Member

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Very clever optimization. Just also want to ensure we document this information in the code. Rest everything is good.

Comment on lines +121 to +122
// Fallback to verify downloaded artifact with SHA-1. Look first in standard repository manager
// headers.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Fallback to verify downloaded artifact with SHA-1. Look first in standard repository manager
// headers.
// Look first in standard repository manager headers as per
// https://maven.apache.org/resolver/expected-checksums.html#non-standard-x-headers.
// Fallback to verify downloaded artifact with SHA-1.

// headers.
var maybeVerificationChecksum = artifactResponse
.headers()
.firstValue("x-checksum-sha1")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
.firstValue("x-checksum-sha1")
// curl -I https://repo1.maven.org/maven2/org/mvnpm/axios/1.15.1/axios-1.15.1.jar
// x-checksum-sha1: 8161aecbad5fceb8ce4aca8b557be1a8b77b5cbe
.firstValue("x-checksum-sha1")

.headers()
.firstValue("x-checksum-sha1")
.or(() -> artifactResponse.headers().firstValue("x-goog-meta-checksum-sha1"))
.or(() -> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
.or(() -> {
//Non-Maven Central or non-GCS hosted packages may not emit these headers
// curl -I https://plugins.gradle.org/m2/org/jmailen/gradle/kotlinter-gradle/5.3.0/kotlinter-gradle-5.3.0.jar
.or(() -> {

@algomaster99
Copy link
Copy Markdown
Member

@timw could you please accept my suggestions if you agree with them?

@fz-rh
Copy link
Copy Markdown
Collaborator

fz-rh commented May 12, 2026

Hi there! @timw @algomaster99

Nice optimization here. It would be nice to have it as a part of performance optimizations we need. We hit a performance bottleneck on some real world projects after implementing #1532.

Definitely vote for this one +1

@algomaster99
Copy link
Copy Markdown
Member

@fz-rh I think @timw has not seen my comments. I can resolve them and merge this. Feel free to drop your comments too.

@algomaster99
Copy link
Copy Markdown
Member

Move the PR here.

@algomaster99
Copy link
Copy Markdown
Member

@fz-rh the commit here is in main now.

@fz-rh
Copy link
Copy Markdown
Collaborator

fz-rh commented May 12, 2026

Thank you! @algomaster99
Btw. I am doing some performance tests of #1548

@algomaster99
Copy link
Copy Markdown
Member

Sounds good! Have not reviewed that PR yet but performance tests will definitely help in doing so.

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.

Avoid sha-1 resource loads in remote checksum calculator

3 participants