#13708·openlibrary

Write API: a bare 403 from nginx when a record's text contains a quote followed by "--"

Author: pillarsdotnetCreated Sep 22, 2026Updated Sep 23, 2026
LabelsType: BugTheme: Public APIsNeeds: BreakdownNeeds: TriageAffects: ServerNeeds: LeadNeeds: ResponseNeeds: Staff / Internal

A PUT to /books/OL…M.json is refused with a bare 403 from nginx — never reaching the application — when the body contains a double or single quote immediately followed by --.

That sequence is the SQL comment-injection signature, so presumably a WAF rule is matching it. The trouble is that it is also how a great many MARC-derived descriptions end, just before their source attribution. Since the write API takes the whole record on a PUT, the unchanged description is sent back on every edit — so no blank field on such a record can be filled through the API by anyone, however unrelated the edit.

Reproduction

Every request below targets /books/OL999999999999M.json, which does not exist, so nothing can be written either way. 400 bad_data / missing type means the request reached the application; 403 Forbidden (nginx's own page) means it did not.

PUT /books/OL999999999999M.json     {"key": "...", "description": <value>, "_comment": "probe"}

  "a harmless sentence about a book"      -> 400   reached the app
  "sacrifice along the way--"             -> 400
  "sacrifice along the way\"-"            -> 400
  "sacrifice along the way\"--x"          -> 400
  "sacrifice along the way\"--"           -> 403   BLOCKED
  "\"--"                                  -> 403   BLOCKED
  "'--"                                   -> 403   BLOCKED
  "x\" --"                                -> 403   BLOCKED

So the match is a quote, optional whitespace, then -- with nothing following it.

Response body for the blocked cases:

xml
<html><head><title>403 Forbidden</title></head>
<body><center><h1>403 Forbidden</h1></center><hr><center>nginx/1.30.5</center></body></html>

A real record this affects

OL27239756M ("The unprotected"). Its description ends:

…and wondered what they might have to sacrifice along the way"--

physical_dimensions and physical_format are both blank on that record. Filling either through the API fails with the 403 above, because the description goes back with the request. The same account, in the same session, successfully filled physical_dimensions on OL34834798M — a record with no such text — so it is neither authentication nor permissions.

Escaping the hyphens as - in the JSON does not help; the filter appears to decode JSON escapes before matching.

Suggested fix

Don't apply SQL comment-injection detection to JSON request bodies on the /books/*.json, /works/*.json and /authors/*.json write endpoints — or require a second injection indicator before blocking. These bodies are round-tripped catalogue text, and "-- in a book summary is ordinary prose rather than a payload. If the rule stays, the 403 would at least be much easier to diagnose if it were the application's own error page rather than nginx's.

Workaround for editors

Send the record with the trailing "-- removed from the description in the same PUT. The body then carries no matching sequence, the request goes through, and it incidentally cleans up a MARC artifact that was never meant to be displayed.

Worth noting that this is the only way to repair such a record: because every PUT carries the description back, a record whose description trips the rule cannot be edited at all until that description is the thing being edited.


Measured against openlibrary.org on 2026-09-22.

Source: internetarchive/openlibrary