Skip to content

nginx snippets: make GET public, keep writes archive.org-only - #13949

Merged
mekarpeles merged 1 commit into
masterfrom
mek/snippets-public-get
Oct 15, 2026
Merged

mekarpeles merged 1 commit into
masterfrom
mek/snippets-public-get

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

nginx snippets: make GET public, keep writes archive.org-only

GET /api/snippets currently 403s when called from openlibrary.org: a same-origin GET sends no Origin header, so the blanket if ($snippets_bad_origin) return 403 rejects it. (BookReader works only because it's cross-origin and sends Origin: archive.org.)

This gates writes only, leaving reads public:

  • GET / OPTIONS β€” unrestricted (BookReader, openlibrary.org same-origin, etc.).
  • POST / PUT β€” require an archive.org origin ($snippets_deny_write = POST/PUT Γ— non-archive.org).
  • DELETE β€” 405 (unchanged).
  • CORS Access-Control-Allow-Origin echoed for *.archive.org and *.openlibrary.org so cross-origin browser reads from both work.

iannotate already serves GET to anyone β€” this is purely the nginx gate, no app change.

Tested (nginx + iannotate, sqlite, across origins/methods)

GET archive.org/openlibrary.org/no-origin β†’ 200 (+ matching CORS header); GET from an unlisted origin β†’ 200 read but no CORS header; POST/PUT archive.org β†’ 200; POST/PUT openlibrary.org or no-origin β†’ 403; DELETE β†’ 405. nginx -t passes.

Note: GET returns private snippets too (nothing filters the model's private flag). If the public feed shouldn't expose those, that's a small follow-up in iannotate's GET.

GET /api/snippets was 403'd for openlibrary.org (same-origin GET sends no
Origin, so the blanket origin gate rejected it). Gate only writes now:
- GET/OPTIONS: unrestricted (BookReader, openlibrary.org, etc.)
- POST/PUT: archive.org origin required ($snippets_deny_write)
- DELETE: 405 (unchanged)
CORS Allow-Origin echoed for archive.org + openlibrary.org. Verified with
nginx + iannotate across origins/methods.
@mekarpeles
mekarpeles merged commit c4fe9ee into master Oct 15, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant