modsec: Can't upload cover art
Problem
When I choose a cover from my desktop to upload and hit Upload, the dialog just shows a blank rectangle instead of the uploaded picture and the picture is not uploaded. This started happening on Wednesday last week, I think.
Reproducing the bug
- Download this cover and save it as
Real, Vol. 1.jpg. - Go to edition OL62350777M.
- Hit
Edit - Click
Add Cover Image. - Hit
Browse. - Select the cover.
- Hit upload.
-
Expected behavior: The cover should be uploaded and then displayed in the dialog.
-
Actual behavior: A blank rectangle is displayed and the cover is not uploaded.
Context
- Browser (Chrome, Safari, Firefox, etc): Firefox
- OS (Windows, Mac, etc): Linux
- Logged in (Y/N): Y
- Environment (prod, dev, local): prod
Breakdown
Implementation Details (for maintainers)
Requirements Checklist
- [ ]
Related files
Stakeholders
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.
I'd like to take a look at this issue , kindly assign
I investigated this and found the root cause (I think). Cover uploads bigger than 1 MB are getting blocked by the ModSecurity WAF with an HTTP 460 before they ever reach the app. The upload dialog's iframe just gets that empty 460 back, which is why you see a blank rectangle and the cover never saves.
I reproduced it on production: small images upload fine, but anything over ~1 MB fails instantly with a 460. It's purely about file size, not image dimensions. An 81-megapixel image that happened to compress under 1 MB uploaded fine, while a 1.1 MB image failed. That 1 MB cutoff is the giveaway: it matches ModSecurity's SecRequestBodyNoFilesLimit, whose default is exactly 1 MB. Since most real covers are 1–5 MB, almost every upload trips it.
A few things this rules out:
- It's not
client_max_body_size— that's set to50mindocker/nginx.conf. - It's not the app's validator in
openlibrary/plugins/upstream/covers.pyas that allows up to 10 MB, and the request never gets that far.
ModSecurity is turned on at the server level in docker/web_nginx.conf, and the upload endpoints fall under location / so the WAF applies to them. The actual rule lives in /olsystem/etc/nginx/modsecurity_openlibrary.conf in the private olsystem repo, which is why this started without any matching change in this repo.
Suggestion: Raise (or drop) SecRequestBodyNoFilesLimit in the olsystem ModSecurity config. File uploads shouldn't be counted against a no-files body limit in the first place.
Thanks for the writeup! Was this changed recently?
See #12718 as related. Each week we're trying to go through batches of false positives and add them. It seems cover uploads is one such case, thank you.
I've investigated the issue and found that cover/photo uploads over ~1 MB are being blocked by ModSecurity's SecRequestBodyNoFilesLimit before reaching the application.
I've opened a PR with a targeted nginx fix that disables ModSecurity only for the three affected upload endpoints, while preserving the existing rate limiting and the application's 10 MB file-size and image validation. Happy to adjust the approach if the team would prefer handling the limit through olsystem instead.
Update from the WAF logs. The blank rectangle is not a 403 — it's a 460, and that distinction matters because it means something different is failing.
The dominant cause on cover uploads is ModSecurity failing to parse the multipart upload body at all (REQBODY_ERROR), which returns 460 rather than 403. The upload JS gets a non-200 and renders nothing, which matches the blank rectangle you describe rather than an error message.
It has largely stopped. Denials of this shape ran at 33–37/day in early September (33 on Sept 6, 37 on Sept 9) and dropped to 1–2/day from Sept 11 onward, with the last on Sept 16. Something in that window addressed most of it.
I'm not closing this, for two reasons:
- I can't tie the remaining 1–2/day to a cause, and that residue is exactly the size that could still be hitting you occasionally.
- Our logs record blocked requests only, so "few denials" and "few people trying" look identical from here. I can't measure how many uploads succeeded.
What would settle it: try an upload and, if it fails, note whether the browser's network tab shows 460 or 403. 460 points back at this parse failure; 403 is a different rule and belongs with #13286.
Worth flagging that this is not the same failure as #13286 despite both being cover uploads — that one reports an explicit "403 Forbidden" message, which is a different code from a different rule. I had initially assumed they were one issue; the logs say otherwise.