Repository navigation
CLARIN-DSpace v9/Refuse a licensed allzip before the zip headers go out - #1489
Open
milanmajchrak wants to merge 3 commits into
Open
milanmajchrak wants to merge 3 commits into
milanmajchrak wants to merge 3 commits into
Conversation
GET/HEAD /api/core/items/{uuid}/allzip answered 500 with Content-Type application/zip when a file of the item sits under an ASK_ONLY_ONCE or ASK_ALWAYS licence: the licence gate only ran inside bitstreamService.retrieve, after the headers and the zip stream were open. The controller now authorizes every bitstream first, so the refusal is a 401 or 403.
In MockMvc even the old controller ends as a bare 401: DispatcherServlet resets the body and drops Content-Disposition before the exception handler answers. The new IT therefore records, through a filter next to the controller, whether the content type or the output stream were started before the refusal.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
8 of 13 tasks
The builder cleanup deletes the bitstream before the licence, and the delete detaches the licence. The response recorder now also flags a Content-Disposition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References
Found in the CLARIN v9 acceptance check: allzip returns 500 instead of 401/403 on a licensed file. No dspace-customers issue.
No dtq-dev source: dtq-dev has the same order in the controller and needs the same fix natively (follow-up).
Description
GET/HEAD /api/core/items/{uuid}/allzipanswered 500 withContent-Type: application/zipwhen a file of the item sits under an ASK_ONLY_ONCE or ASK_ALWAYS licence. The licence gate ran only insidebitstreamService.retrieve, after the headers and the zip stream were open; the controller now authorizes every bitstream first, so the refusal is a normal 401 (anonymous) or 403 (logged in, licence not agreed).Instructions for Reviewers
List of changes in this PR:
MetadataBitstreamController.downloadFileZip:authorizeService.authorizeAction(READ)over all ORIGINAL bitstreams (vanilla policies plus the CLARIN licence gate) beforeContent-Disposition,Content-Typeandresponse.getOutputStream(). The check insideretrievestays as it was. An item that mixes open and licensed files is now refused as a whole; before, the zip started and broke at the licensed file.MetadataBitstreamControllerIT: new test with an item that has an open file and then a file under an ASK_ONLY_ONCE licence. Anonymous GET gives 401, a logged-in non-submitter gives 403.DispatcherServletresets the body and dropsContent-Dispositionbefore the exception handler answers, so in MockMvc even the old controller ends as a bare 401; a filter next to the controller therefore records whetherContent-Disposition, the content type or the output stream were touched before the refusal. The test fails on the old controller. The three existing tests are unchanged.Codex review (gpt-6.2-sol, high), 2 rounds: 3 findings fixed, all in the IT (no teardown override, so the shared cleanup always runs; the recorder also catches an early
Content-Disposition; an open file comes before the licensed one). Nothing is left open.How to test:
MetadataBitstreamControllerIT.Before:
HTTP/1.1 500withContent-Type: application/zip. After:HTTP/1.1 401, or403with a logged-in user who has not agreed to the licence. An item without a licence still gives200and the zip.Follow-up: the same fix on dtq-dev (7.x), written natively there.
Checklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.🤖 Generated with Claude Code