Batch import approval changes state on GET
Problem
BatchImportApprove (openlibrary/plugins/openlibrary/code.py, route /import/batch/approve/
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
- While logged in as a non-admin, submit a batch at /import/batch/new.
- 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.
On it! Thank you!
Thanks for the quick turnaround! Happy to test it or to contribute in any way if that's useful!
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.