CORS allowedHeaders omits If-Overwritten-Version, so browser clients cannot use the conflict-safe overwrite path
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- express, javascript, node.js
Hướng nghiên cứu
Mở app.js và xem các tùy chọn cors() ở dòng 32-57, cụ thể là mảng allowedHeaders ở dòng 35-52, hiện đang liệt kê 16 tên và không có If-Overwritten-Version. Thêm mục đó sau 'X-HTTP-Method-Override' và giữ nguyên origin, methods, exposedHeaders và maxAge. Xác nhận bằng preflight curl -X OPTIONS trong issue rằng Access-Control-Allow-Headers phản hồi lại tên mới, sau đó thêm một assertion vào routes/__tests__/overwrite.test.js để danh sách không thể âm thầm làm mất nó. Hoàn thành nghĩa là preflight cho phép header và routes/__tests__/overwrite.test.js vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This was generated by AI during triage.
Problem
If-Overwritten-Version — the optimistic-locking guard header for PUT /v1/api/overwrite — is not in the CORS allowedHeaders list. A cross-origin browser client that sends it fails the preflight, so the conflict-safe overwrite path is reachable only from non-browser callers (curl, Node, server-to-server). The REST/server path works; the web path silently cannot use it.
Evidence (re-read from live default branch, origin/main @ 5c32e5d)
The single CORS configuration is app.js:32-57:
32: app.use(
33: cors({
34: "methods" : "GET,OPTIONS,HEAD,PUT,PATCH,DELETE,POST",
35: "allowedHeaders" : [
36: 'Content-Type',
37: 'Content-Length',
38: 'Allow',
39: 'Authorization',
40: 'Location',
41: 'ETag',
42: 'Connection',
43: 'Keep-Alive',
44: 'Date',
45: 'Cache-Control',
46: 'Last-Modified',
47: 'Link',
48: 'X-HTTP-Method-Override',
49: 'Origin',
50: 'Referrer',
51: 'User-Agent'
52: ],
53: "exposedHeaders" : "*",
54: "origin" : "*",
55: "maxAge" : "600"
56: })
57: )
The allowedHeaders array at app.js:35-52 holds 16 entries, quoted verbatim above. If-Overwritten-Version is not among them, and no other header in the list covers it (X-HTTP-Method-Override at :48 is unrelated — it is the method-override header). Because allowedHeaders is a fixed list, the Access-Control-Allow-Headers this server can ever return is those 16 names; the guard header can never appear in it. exposedHeaders : "*" (:53) is about response headers readable by JS and does not help.
The header is genuinely consumed:
controllers/overwrite.js:60—const expectedVersion = req.get('If-Overwritten-Version') ?? req.body.__rerum?.isOverwrittencontrollers/overwrite.js:63— the mismatch test,:64the409withcurrentVersionin the bodyroutes/overwrite.js:9-10—PUT /behindauth.checkJwt, mounted atroutes/api-routes.js:57(/api/overwrite) under the/v1mount atapp.js:81→PUT /v1/api/overwrite
And it is publicly documented: public/API.html:1232-1238 tells clients that including the "If-Overwritten-Version" header "will cause the request to fail if the record has been overwritten since that time." The docs advertise a channel browsers are blocked from using.
Why no test caught it: routes/__tests__/overwrite.test.js:59 and :117 set the header with supertest (.set('If-Overwritten-Version', …)), which issues a plain HTTP request with no CORS layer and no preflight, so those tests pass whether or not the header is browser-usable.
Consequence
If-Overwritten-Version is not a CORS-safelisted request header, so any cross-origin PUT carrying it triggers a preflight. The preflight response cannot list it, the browser aborts with "Request header field if-overwritten-version is not allowed by Access-Control-Allow-Headers in preflight response", and the real request is never sent.
Practical impact, stated precisely so nobody over- or under-fixes it:
- Browser clients lose the header channel entirely. They can still get conflict detection only through the
?? req.body.__rerum?.isOverwrittenfallback atcontrollers/overwrite.js:60, which forces a web client to inject RERUM's internal version field into the payload it is trying to store — the payload-identity problem tracked by #230, not a substitute for a conditional request header. - The fallback also weakens the intent: a header is transport metadata the stored object never carries, a body field is persisted into the record.
- This is the interaction with the deprecate-don't-break ruling on #259: clients are meant to migrate onto explicit opt-in conflict checking, and the browser half of the client base currently cannot.
Fix
Add one entry to the allowedHeaders array in app.js:35-52, e.g. after 'X-HTTP-Method-Override' (:48):
'If-Overwritten-Version',
Then confirm the preflight response actually echoes it in Access-Control-Allow-Headers (:55 maxAge: "600" means a cached preflight can mask the change for up to 10 minutes during testing — use a fresh origin or bump maxAge locally, not in the commit).
Nothing else is required: no change to overwrite semantics, the 409 shape, or the req.get(...) ?? body fallback order at controllers/overwrite.js:60.
Do not change
"origin" : "*"(app.js:54) — the open-wildcard question belongs to #164 (constants to.env) and to the tenant work; it is deliberately out of scope here. Touch onlyallowedHeaders."methods"(:34),"exposedHeaders"(:53),"maxAge"(:55) — leave as-is.controllers/overwrite.js(:58-70) — no behavioural change; do not make the header mandatory, that is a breaking public-API change under active discussion on #259.auth/index.js, includingcheckJwt(:44) and_tokenError(:3-23).- The documented behaviour in
public/API.html:1232-1238— it already describes the intended behaviour and becomes correct once the header is allowed.
Verification
-
Start the server (
npm start, expectLISTENING ON 3005) and issue a real preflight:curl -i -X OPTIONS 'http://localhost:3005/v1/api/overwrite' \ -H 'Origin: http://example.invalid' \ -H 'Access-Control-Request-Method: PUT' \ -H 'Access-Control-Request-Headers: content-type, authorization, if-overwritten-version'Expect
204/200withAccess-Control-Allow-HeaderscontainingIf-Overwritten-Version. Before the fix that response lists only the 16 configured names. Header field names are case-insensitive, so a lowercase request header still has to come back allowed. -
Negative control: the same preflight with
Access-Control-Request-Headers: x-not-a-real-headermust not cause the server to echo unknown names — the list stays the configured one. -
Browser check: from a page served on a different origin than the API (e.g.
http://localhost:8080againsthttp://localhost:3005), runawait fetch('http://localhost:3005/v1/api/overwrite', { method: 'PUT', headers: { 'Content-Type': 'application/ld+json', 'Authorization': 'Bearer <token>', 'If-Overwritten-Version': '2025-06-24T10:00:00' }, body: JSON.stringify({ '@context': 'http://localhost:3005/v1/context.json', '@id': 'http://localhost:3005/v1/id/TESTID#anno', body: 'x' }) })Before the fix the browser blocks it with the
Access-Control-Allow-Headersmessage and the request never leaves; after the fix it reaches the API and returns the object, or409withcurrentVersionwhen the version is stale. -
npm run runtest -- routes/__tests__/overwrite.test.jsstill passes (it exercises the guard over plain HTTP), andnpm run runtest -- __tests__/routes_mounted.test.jsfor the routing sanity check. -
Add a supertest assertion that an
OPTIONSon the overwrite route returnsAccess-Control-Allow-HeadersincludingIf-Overwritten-Version, so a future edit toapp.js:35-52that drops it fails CI.
Note for the browser step: a bare OPTIONS (no Access-Control-Request-Method) falls through cors to the .all() handler at routes/overwrite.js:11-13 and gets 405 with Allow: PUT. That is #318's scope, not this ticket's, and a genuine preflight is answered by cors before it reaches the router.
Related
- #230 — If-Overwritten-Version header not enforced when accessed via TinyNode — reopened; this repo is canonical for conflict-safe-update semantics. That issue covers the middleware/relay side of the same header; this one covers the browser reaching the header at all. Both must land for a web client to have working optimistic locking through TinyNode.
- TinyNode #106 — If-Overwritten-Version header not enforced on /overwrite endpoint, specifically this comment — the subordinate middleware side. If TinyNode forwards requests to RERUM from a browser origin, the relay must not strip the header either; that repo owns the fix.
- #259 — force-overwrite default is being deprecated, not broken; deprecated-but-usable means the blind path stays, which is exactly why the safe path needs to be reachable from browsers.
- #318 —
Allowheader accuracy /OPTIONSon single-verb routes. Adjacent in behaviour, different file; do not merge these two.
Workstream 1 (better data / modern core — programmatic APIs) and workstream 3 (interoperability / external workflows): a documented conditional-write guard that no browser can send is the kind of gap that surfaces the moment an external IIIF annotation client is wired up.
- Ngôn ngữ chính
- JavaScript
- Star
- 3
- Fork
- 7
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của CenterForDigitalHumanities/rerum_server_nodejs
-
enhancement ready-for-agent
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
-
bug documentation ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
CenterForDigitalHumanities/rerum_server_nodejs#311 · 1 bình luận ·
-
backend dependencies easy enhancement ready-for-human
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
CenterForDigitalHumanities/rerum_server_nodejs#294 · 2 bình luận ·
-
Switch obj.hasOwnProperty() to Object.hasOwn() where the receiver is untrustedCó thể đã có người làm @thehabes đã nhận 6 ngày trước. Đang mởbug ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
CenterForDigitalHumanities/rerum_server_nodejs#290 · 3 bình luận · 1 người được giao ·
-
enhancement ready-for-human
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
CenterForDigitalHumanities/rerum_server_nodejs#326 · 2 bình luận ·
Tất cả issue của CenterForDigitalHumanities/rerum_server_nodejs
Issue tương tự
-
flex-flow: wrap-reverse gets a vertical, reversed 2009 box fallbackCó thể đã có người làm @goranai đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
postcss/autoprefixer#1577 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
PranshulGG/WeatherMaster#1266 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FEATURE REQUEST
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
linuxmint/cinnamon-spices-applets#9356 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
opnsense/plugins#5976 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày