Skip to content

CLARIN-DSpace v9/Refuse a licensed allzip before the zip headers go out - #1489

Open
milanmajchrak wants to merge 3 commits into
dtq-dev-93from
ufal/fix-allzip-license-gate-before-headers-9-base
Open

milanmajchrak wants to merge 3 commits into
dtq-dev-93from
ufal/fix-allzip-license-gate-before-headers-9-base

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

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}/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 ran only inside bitstreamService.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) before Content-Disposition, Content-Type and response.getOutputStream(). The check inside retrieve stays 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. DispatcherServlet resets the body and drops Content-Disposition before the exception handler answers, so in MockMvc even the old controller ends as a bare 401; a filter next to the controller therefore records whether Content-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:

  • Run MetadataBitstreamControllerIT.
  • On a running instance pick an item whose file has a licence with confirmation 1 or 2 (ASK_ONLY_ONCE / ASK_ALWAYS) and run
curl -sI "http://localhost:8080/server/api/core/items/<item uuid>/allzip?handleId=<handle>"

Before: HTTP/1.1 500 with Content-Type: application/zip. After: HTTP/1.1 401, or 403 with a logged-in user who has not agreed to the licence. An item without a licence still gives 200 and the zip.

Follow-up: the same fix on dtq-dev (7.x), written natively there.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR passes Checkstyle validation based on the Code Style Guide.
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests based on the Code Testing Guide.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR modifies REST API endpoints, I've opened a separate REST Contract PR related to this change.
  • If my PR includes new configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

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]>
milanmajchrak and others added 2 commits November 26, 2026 19:23
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]>

This branch has not been deployed

No deployments
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