openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Modsecurity: Book Cover 403 Forbidden

Open Marla-1913 opened this issue 3 months ago • 12 comments

Problem

As requested by @mekarpeles at https://github.com/internetarchive/openlibrary/issues/12718, I'm creating a new issue. More than once (most recently today), I've gotten a "Book Cover 403 Forbidden" message when I tried to upload book covers from my computer to the following editions:

https://openlibrary.org/books/OL62382445M/Addicted_to_Anxiety https://openlibrary.org/books/OL33666561M/Ten_Times_Happier

Image Image

Reproducing the bug

  1. Go to edition OL62382445M [ISBN 9781250439970] or OL33666561M (ISBN 9780008378240);
  2. Click "Edit";
  3. Click "Add Cover Image";
  4. Click "Choose File";
  5. Navigate to and select the appropriate cover;
  6. Click "Upload."
  • Expected behavior: The cover should have been uploaded to the edition.
  • Actual behavior: Received a "Book Cover 403: Forbidden" message (see screenshots above).

Context

  • Browser (Chrome, Safari, Firefox, etc): DuckDuckGo and Google Chrome
  • OS (Windows, Mac, etc): Windows 11
  • Logged in (Y/N): Yes
  • 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.

Marla-1913 avatar Aug 08 '26 10:08 Marla-1913

Thank you @Marla-1913 for submitting this issue!

[!WARNING] This issue requires access to internal infrastructure, production systems, or institutional knowledge unavailable to community contributors. It can only be resolved by a maintainer or staff member.

⚠️ Contributors, this issue will be ready to work on once:

  • [ ] Triage — maintainers will add Priority: * and Lead: @*
  • [ ] Needs: Investigation — root cause or approach unknown; research required first
  • [ ] Needs: Staff / Internal — requires production access or institutional knowledge

Context

  • add_cover.POST() in covers.py#L61-L68 only raises an application-level 403 (web.forbidden) when the authenticated user is flagged read-only. Nothing else in this file returns a 403, which points away from an app-layer cause and toward the WAF/nginx layer sitting in front of the app — consistent with the ModSecurity pattern already tracked elsewhere (see below). The same upload code path is shared by edition, work, and author cover routes (add_cover, add_work_cover, add_photo).
  • Likely related/duplicate: #13232 "modsec: Can't upload cover art" (open) — same symptom (cover upload fails on prod). A contributor there traced the root cause to ModSecurity's SecRequestBodyNoFilesLimit (~1MB default), which blocks file uploads over that size with an HTTP 460 before the request reaches the app. This issue reports an HTTP 403 rather than 460, so it may be the same WAF layer tripping a different rule, rather than the exact same defect — worth confirming either way.
  • #12718 "Modsecurity: 403 Forbidden" (closed 2026-07-28 as completed) was the general-purpose ModSecurity false-positive tracking issue. It was closed specifically so that new false positives would be filed as individual, narrowly-scoped issues going forward — this issue is exactly that pattern, and cover uploads were called out there as a known problem area.
  • #13225 "ModSecurity: Automated Daily Review & Rule-Update Pipeline" (open) is the active epic for systematically catching and fixing these WAF false positives.

Issue Assessment

Open questions

  • What is the file size of the covers being uploaded to these two editions? (Determines whether this is the same SecRequestBodyNoFilesLimit/460 issue as #13232, or a distinct rule producing a genuine 403.)
  • Does the browser's Network tab show the 403 response coming back with an nginx-style body (WAF/server layer) or an OpenLibrary-rendered page (app layer)? This is the fastest way to confirm the layer at fault.
  • Is the failure consistent on every attempt for these two editions, or intermittent (as with most reports in #12718)?

Action items

  • [x] Determine whether the app-level read-only check could be the cause (Answer: unlikely — that check only fires for accounts flagged read-only, which wouldn't explain a logged-in editor failing on arbitrary editions; the pattern matches the WAF-layer issue tracked in #13232/#12718 instead).

🔔 Stakeholders @jimchamp — Lead on both #13232 (near-duplicate cover-upload ModSecurity report) and #13225 (the ModSecurity automated review pipeline epic).


Full triage checklist
  • [x] Triage — correct labels applied or removed
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; does not try to do too many things
  • [ ] Justification — reasoning and impact stated; sufficient for leads to prioritize
  • [ ] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
  • [ ] Proposal & breakdown — concrete plan present; checklist actionable for a contributor
  • [x] If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
  • [x] Risks, concerns, open questions — identified and surfaced
  • [ ] Richy context — relevant code, commits, PRs reviewed; no duplicate found
  • [x] References — screenshots, designs, docs, and links present where needed

[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.

openlibrary-bot avatar Aug 08 '26 10:08 openlibrary-bot

I tried reproducing this issue on the affected edition and was able to successfully upload the book cover for edition OL62382445M [ISBN 9781250439970] and OL33666561M [ISBN 9780008378240] already had successfully uploaded book cover

However, I repeatedly encountered 503 Service Unavailable errors when:

  • Trying to edit the cover again after the upload.
  • Simply accessing the book page normally.

The server was also noticeably slow to respond during these attempts.

I tried accessing the edition again after some time, and the page was working normally. This makes me suspect that the 503 Service Unavailable responses may be related to temporary server/backend availability or resource issues rather than the specific edition itself.

The cover upload itself eventually succeeded, so I was unable to reproduce the original 403 Forbidden on the upload. However, I was able to reproduce the intermittent 503 responses when accessing/editing the edition.

I've attached screenshots from my device showing the 503 Service Unavailable responses.


Image Image Image Image Image

CipherZ3r0 avatar Aug 15 '26 20:08 CipherZ3r0

Thank you, @CipherZ3r0, for uploading the covers to the books. Unfortunately, I don't understand what the rest of the comments on this issue mean :-(. In response to the first and third "Open questions" above, the covers I tried to upload were 58 KB and 55 KB, and I tried repeatedly to upload the covers over the course of two weeks or so, so the issue was not intermittent. If, however, you want to know if I could upload covers to unrelated editions, the answer is "yes" (which could be taken to mean the issue was intermittent - you decide!).

Marla-1913 avatar Aug 16 '26 06:08 Marla-1913

Thanks for the clarification! @Marla-1913 That helps.

From my testing, I was able to upload the cover to the affected edition successfully. However, I encountered repeated 503 Service Unavailable errors when trying to access or edit the edition afterward, along with unusually slow server responses.

So my results seem to differ from yours: the cover upload itself worked for me, but I did experience intermittent server-side 503 errors afterward which i am not so sure about the root cause. would like to ask @mekarpeles @openlibrary-bot for looking into it.

Hopefully this additional information helps with narrowing down the cause.

CipherZ3r0 avatar Aug 16 '26 06:08 CipherZ3r0

@Marla-1913, any chance you still have the files you were attempting to upload? I am wondering if the filenames might somehow be triggering ModSecurity. Worth exploring, at least, if you still have the files and can share the filenames involved.

scottbarnes avatar Aug 22 '26 19:08 scottbarnes

As requested, @scottbarnes, the covers I tried to upload are below. I don't see a reference to how I named them, so they're "Owen O'Kane_Addicted to Anxiety ISBN 9781250439970.jpg" [55 KB] and "Owen O'Kane_Ten Times Happier ISBN 9780008378240.jpg" [58 KB]. I'm consistent with my naming conventions, so these same elements are in most covers I upload. Good luck and thanks for your help.

Image Image

Marla-1913 avatar Aug 24 '26 22:08 Marla-1913

Upon seeing the filename I thought maybe the ' (or ’) was a problem, but I was able to upload a cover using Owen O’Kane_Addicted to Anxiety ISBN 9781250439970.jpg as the filename, as well as Owen O'Kane_Addicted to Anxiety ISBN 9781250439970.jpg, so I guess it wasn't that. 🤔

scottbarnes avatar Aug 25 '26 00:08 scottbarnes

Edit blocked by modsecurity. https://openlibrary.org/works/OL33802190W.yml?m=edit

seabelis avatar Sep 02 '26 12:09 seabelis

@doc-furcations reports being blocked when trying to edit https://openlibrary.org/developers/api. I am getting the same result when saving edits.

seabelis avatar Sep 02 '26 12:09 seabelis

For what it's worth, @scottbarnes, I tried to upload the author photo "Kristin Gore_Sammy's House.jpg" [29 KB] on August 28th and got the "Author Photos 403 Forbidden" error attached below (exactly the same, only different, right? :-). When I renamed it as "Kristin Gore_Sammys House" it uploaded beautifully. Maybe you were on the right track after all, so I'll try to remember not to use apostrophes going forward.

Image

Marla-1913 avatar Sep 03 '26 20:09 Marla-1913

Update from the WAF logs, and a correction to an assumption I'd made.

The explicit 403 you're seeing is a different failure from #13232, despite both being cover uploads. That one is a 460 caused by the upload body failing to parse. Yours is a 403 from a rule that inspects the filename, and the recorded matches are filenames containing an apostrophe — things like Portrait_d'…jpg and Owen_O'….

That fits your reports: it would hit some covers and not others, with nothing obviously different about the files from your side, depending entirely on whether the filename happened to contain one.

An exemption for that is already in place. Denials on cover-upload routes have dropped from 33–37/day in early September to the last one on Sept 16.

I'm not closing this yet — our logs only record blocked requests, so from here "fixed" and "nobody uploaded a cover with an apostrophe this week" look the same. I can't see successes.

What would settle it: try uploading a cover whose filename contains an apostrophe. If it goes through, that's the confirmation. If it fails, the browser's network tab showing 403 vs 460 tells us which of the two failures you hit, and either way the filename is the detail worth including.

mekarpeles avatar Sep 23 '26 23:09 mekarpeles

https://openlibrary.org/collections.en?m=edit

seabelis avatar Nov 18 '26 14:11 seabelis