-
Notifications
You must be signed in to change notification settings - Fork 986
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
Serve provenance without requiring the Accept header #17084
Comments
This is covered by the documentation here (I didn't think to look so I dug around in the source code instead): https://docs.pypi.org/api/integrity/#get-provenance-for-file Although the docs say:
Which I think is incorrect documentation - you have to pass the Accept header to see the format shown in that example. |
Your browser is almost certainly sending
|
Running curl -s https://pypi.org/integrity/pydantic/1.10.19/pydantic-1.10.19-cp310-cp310-macosx_11_0_arm64.whl/provenance Not great from a developer experience / usability POV though, since I do a lot of my API research these days on a phone with Mobile Safari! |
That's because by default curl accepts any content type (
The issue is that we want to respect the |
The Here I explicitly list the integrity JSON media type as acceptable, yet the server refuses to send it: $ curl -H 'Accept: text/html, application/vnd.pypi.integrity.v1+json; q=0.9' https://pypi.org/integrity/pydantic/1.10.19/pydantic-1.10.19-cp310-cp310-macosx_11_0_arm64.whl/provenance
{"message":"Request not acceptable"} And here I don't list it, but the server does send it: $ curl -H 'Accept: image/png' https://pypi.org/integrity/pydantic/1.10.19/pydantic-1.10.19-cp310-cp310-macosx_11_0_arm64.whl/provenance
{"attestation_bundles":[{"attestations":[{"envelope":{"signature":"MEYCIQCwvxvlD0VNoopId6m0noBJHuJ/Ig6LPV/kckAb3c
... Even when I expressly prohibit it, the server sends it anyway: $ curl -H 'Accept: image/png, application/vnd.pypi.integrity.v1+json; q=0' https://pypi.org/integrity/pydantic/1.10.19/pydantic-1.10.19-cp310-cp310-macosx_11_0_arm64.whl/provenance
{"attestation_bundles":[{"attestations":[{"envelope":{"signature":"MEYCIQCwvxvlD0VNoopId6m0noBJHuJ/Ig6LPV/kckAb3c
... |
Not trying to solve this yet, but providing a little more context on why this behaves the current way. The code here will take in the Accept header if provided, if none match, like the case of Then in the view, if any of the options passed isn't the specific header, it's rejected. So if no Accept header is provided, or an Accept header with something that isn't correct This logic also denies the ability to pass the This seems slightly incorrect from the original intent to respond with a 404 if missing. |
I'll take a stab at improving the accept handling today 🙂 Edit: FWICT, this might also be an issue with the |
Oh, I see what's happening here in the With To fix this, I think we could probably tighten the accept handing: instead of doing the JSON fallback we could reject when no offer is accepted, and we could remove the HTML mimetypes from the offer list until we're actually ready to support them. In other words, the behavior would become:
Thoughts @miketheman @di? |
See pypi#17084. Signed-off-by: William Woodruff <[email protected]>
* integrity: refine Accept header handling See #17084. Signed-off-by: William Woodruff <[email protected]> * remove unneeded identity fallback Signed-off-by: William Woodruff <[email protected]> * remove unused MIME types Signed-off-by: William Woodruff <[email protected]> * remove HTML mime type uses Signed-off-by: William Woodruff <[email protected]> --------- Signed-off-by: William Woodruff <[email protected]>
Looks like this is now fixed - all of the test cases from the comments behave as expected. |
What's the problem this feature will solve?
When I visit this page in my browser:
https://pypi.org/integrity/pydantic/1.10.19/pydantic-1.10.19-cp310-cp310-macosx_11_0_arm64.whl/provenance
I get this:
To see the content of that page I have to send an
accept
header like this:Describe the solution you'd like
I'd prefer it if the page served me JSON without me having to send that accept header. That way I could explore and understand the API without needing to fire up a terminal or a custom HTTP client.
Additional context
Here's the implementation:
warehouse/warehouse/api/integrity.py
Lines 62 to 67 in 06a2b58
The text was updated successfully, but these errors were encountered: