openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Batch import approval changes state on GET

Open federico-calo opened this issue 1 month ago • 3 comments

Problem

BatchImportApprove (openlibrary/plugins/openlibrary/code.py, route /import/batch/approve/) changes state on a GET request: for members of /usergroup/admin, it moves every item of the batch from needs_review to pending. Since it is a plain link, an admin can approve a batch simply by following a URL, without going through the batch page.

Separately, batch_import_view.html shows the "Approve" link to every viewer, including the submitter, who then gets a 403. The permission check itself works as expected.

Noticed while checking the status of batch #2128 (the test batch mentioned in #13775), then confirmed by reading the code; not tested. Reported by email to [email protected] on Oct 30, and was asked to open an issue here.

Reproducing the bug

  1. While logged in as a non-admin, submit a batch at /import/batch/new.
  2. Open /import/batch/ for that batch.
  • Expected behavior: the "Approve" control is shown to admins only, and approving requires a POST (a form button), so following a link cannot change a batch's status.
  • Actual behavior: the "Approve" link is shown to every viewer (non-admins get a 403 when following it), and for an admin a plain GET to /import/batch/approve/ moves the batch from needs_review to pending.

Context

  • Browser (Chrome, Safari, Firefox, etc): any
  • OS (Windows, Mac, etc): any
  • Logged in (Y/N): Y
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Rename BatchImportApprove.GET to POST (web.py then answers 405 to GET), and replace the link in batch_import_view.html with a small POST form button rendered only when ctx.user.is_admin(), the same group the handler checks. I'm happy to submit a PR once the approach has been reviewed.

Requirements Checklist

  • [ ] BatchImportApprove only accepts POST
  • [ ] The "Approve" control is a POST form button
  • [ ] The control is rendered only for admins

Related files

  • openlibrary/plugins/openlibrary/code.py
  • openlibrary/templates/batch_import_view.html

Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

federico-calo avatar Nov 03 '26 16:11 federico-calo

On it! Thank you!

mekarpeles avatar Nov 03 '26 23:11 mekarpeles

Thanks for the quick turnaround! Happy to test it or to contribute in any way if that's useful!

federico-calo avatar Nov 04 '26 04:11 federico-calo

Resolved via private security advisory GHSA-wq89-ph2h-pp44 — https://github.com/internetarchive/openlibrary/security/advisories/GHSA-wq89-ph2h-pp44 (maintainer access only).

Fix is on master: /import/batch/approve/<id> no longer changes state on GET (it is now inert and redirects to the batch view), and the approval is an admin-gated POST. Closing as resolved.

openlibrary-bot avatar Nov 16 '26 20:11 openlibrary-bot