Title: fix(v2): serve HEAD, advertise PATCH, and document the reachable 403 by waleedlatif1 · Pull Request #6623 · simstudioai/sim · GitHub
Open Graph Title: fix(v2): serve HEAD, advertise PATCH, and document the reachable 403 by waleedlatif1 · Pull Request #6623 · simstudioai/sim
X Title: fix(v2): serve HEAD, advertise PATCH, and document the reachable 403 by waleedlatif1 · Pull Request #6623 · simstudioai/sim
Description: What Three HTTP-semantics defects on the v2 surface, found by probing the published contract rather than the happy path. Follow-up to #6620, on top of the merged pagination/envelope work. In Was Now HEAD /api/v2/workflows (and every v2 endpoint) 500 200, no body CORS preflight for any of 17 PATCH ops rejected — PATCH not advertised allowed GET /knowledge/{id} + 5 siblings 403 undocumented but reachable documented HEAD returned 500 on every v2 endpoint Next implements a missing HEAD export by aliasing it straight onto GET (auto-implement-methods.ts: methods.HEAD = handlers.GET) and drops the body at send time (send-response.ts skips the stream when req.method === 'HEAD'). So a route's GET legitimately runs with request.method === 'HEAD'. Every route builder guards that the request method equals the contract's declared method — the check that makes a handler exported under the wrong verb fail loudly. It rejected the framework's own HEAD aliasing, threw, and withRouteHandler turned that into a 500. That is why the response carried our x-request-id and a JSON content-type: it reached our handler and threw. RFC 9110 §9.3.2 makes HEAD identical to GET but for the body, which is exactly what running the GET path and letting Next strip the body produces — so mirroring GET is right, and a 405 would be wrong for a read endpoint. Fixed once in methodMatchesContract and shared by all five builders (both v2 and internal — the internal builders carried the identical guard). Every other mismatch stays a hard error. Practical impact: health checkers, uptime monitors, link checkers, and some proxies/CDNs issue HEAD, and every one of them read the v2 API as hard-down. CORS omitted PATCH The default /api policy advertised GET,POST,OPTIONS,PUT,DELETE while the v2 spec has 17 PATCH operations, so a browser preflight for any of them was rejected. It also advertised PUT, which only two operations use — the shape of a hand-maintained list that its surface outgrew. Blast radius today is limited because access-control-allow-origin echoes only the site's own origin, so cross-origin browser use is not enabled; this becomes live the moment CORS is widened or a first-party client PATCHes cross-origin. The list stays hand-written on purpose — proxy.ts is edge middleware and importing lib/api/contracts would pull Zod and the whole contract tree into the middleware bundle. Instead it is pinned by a test that sweeps the real contracts and fails on any declared method the header omits, which is the check that would have caught this. HEAD is added too, now that it is genuinely served. Six operations omitted a reachable 403 GET /knowledge/{id}, GET /knowledge/{id}/documents, GET /knowledge/{id}/documents/{documentId}, and the three /files/uploads/{uploadId} operations omitted 403 while their siblings on the same paths documented it. Settled from the code, not by pattern-matching the spec. requirePermission throws two different failures: no workspace access at all → NoWorkspaceAccessError, which createV2ResourceConcealmentPolicy conceals as 404 access below the operation's minimumRole → InsufficientWorkspacePermissionsError, which is not in the concealment set and stays a 403 So the "reads conceal with 404 and can never 403" theory does not hold. The three upload operations are minimumRole: 'write', so a member with read hits a 403 directly. The three knowledge reads are minimumRole: 'read' — the floor of the read < write < admin ordering, so that path cannot 403 — but they are still reachable by PersonalApiKeysDisabledError (a personal API key against a workspace whose organization disabled them), which is also not concealed. 403 is reachable on all six. They now use the shared RESOURCE_ERRORS / RESOURCE_CONFLICT_ERRORS sets rather than hand-assembled lists, which is how the codes went missing. Two operations that spelled those same sets by hand (listAuditLogs, getAuditLog) were normalized onto them — byte-identical output, one fewer way to drift. All 128 documented operations now declare 403. Verification bun run type-check, bun run lint:check, bun run check:api-validation:strict, bun run check:openapi — pass 3926 tests pass across app/api, lib/api, lib/knowledge, lib/workspace-files Specs regenerated with bun run generate:openapi; never hand-edited Each fix was reverted and confirmed red first: the HEAD route test fails with expected 500 to be 200, reproducing the staging symptom exactly, and the CORS sweep fails with expected [ 'PATCH' ] to deeply equal [] Not verified locally: HEAD behaviour is asserted against the builder and one real route handler, but the framework's own body-stripping is not exercised by a unit test. A human should confirm on staging after deploy that HEAD /api/v2/workflows returns 200 with no body and the same headers as GET. Type of Change Bug fix Testing See Verification above. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
Open Graph Description: What Three HTTP-semantics defects on the v2 surface, found by probing the published contract rather than the happy path. Follow-up to #6620, on top of the merged pagination/envelope work. In Was...
X Description: What Three HTTP-semantics defects on the v2 surface, found by probing the published contract rather than the happy path. Follow-up to #6620, on top of the merged pagination/envelope work. In Was...
Opengraph URL: https://github.com/simstudioai/sim/pull/6623
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:488a8933-3854-f87d-eb91-3eb3033c160e |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D3AE:3BD2EB:257903:349903:6AFB5231 |
| html-safe-nonce | 8c121fa7122378cf55f18268a926964edcca98cb52fd5f26deabb399abfdf842 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0FFOjNCRDJFQjoyNTc5MDM6MzQ5OTAzOjZBRkI1MjMxIiwidmlzaXRvcl9pZCI6IjQ2NTUyOTU5MDY5NjUwNDk5MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 152f8546523f9a7eb18a43a20331f0919fc245067816c01d985e950aa2211ae0 |
| hovercard-subject-tag | pull_request:4264001232 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6623/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | What Three HTTP-semantics defects on the v2 surface, found by probing the published contract rather than the happy path. Follow-up to #6620, on top of the merged pagination/envelope work. In Was... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7122bb414b542dba14d71a3f0b9f6fd2abce715b9f5912d082800563e6c806d1 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cbf66c024bb6d10e6955baa7413c54cf13a201bb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width