soa-api-util: shared CORS origin allowlist + Datadog RUM header constant#114
Merged
Conversation
…onstant
Backends were each re-implementing the same two things: the 7-header Datadog
RUM tracing list (allowedHeaders) and an env-isolated origin allowlist
(prod=*.saga.org, dev=*.wootdev.com). Extract both into soa-api-util:
- DATADOG_RUM_TRACING_HEADERS — the 7-header constant.
- buildSagaOriginAllowlist({ env, devOrigins }) — env-isolated (NODE_ENV)
allowlist + CORS_ORIGIN; anchored https-only wildcards (suffix-attack safe);
localhost devOrigins added in non-prod only.
- originAllowed(list, origin) — matcher for cors origin + Origin/Referer CSRF.
iam-api/programs-api/scheduling-api/connectv3-api will adopt these, replacing
their inline copies. Minor bump 1.1.1 -> 1.2.0. Re hipponot/iac#358.
❌ Test Results
Package Results
Commits
LinksUpdated: 2026-06-02T17:55:30.891Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Four Saga backends (iam-api, programs-api, scheduling-api, connectv3-api) each re-implement the same two CORS bits, with subtle drift:
allowedHeaders, and*.saga.org, dev=*.wootdev.com).Extracting them into
@saga-ed/soa-api-utilgives one source of truth — one place to update if Datadog changes its header set, and consistent dev/prod isolation. (Part of the RUM/backend-CORS rollout, hipponot/iac#358.)What (new exports)
DATADOG_RUM_TRACING_HEADERS— readonly tuple of the 7 headers; spread into a service'sallowedHeaders.buildSagaOriginAllowlist({ env?, devOrigins? })— env-isolated allowlist: prod (NODE_ENV==='production') → explicitCORS_ORIGIN+https://*.saga.org; dev →CORS_ORIGIN+devOrigins(localhost, non-prod only) +https://*.wootdev.com. Wildcards are anchored + https-only (suffix-attack safe — adopts iam-api's stricter form).originAllowed(list, origin)— matcher for thecorsmiddleware origin callback and/or an Origin/Referer CSRF gate (keeps them in lockstep).Primitives only — each service keeps its own
cors()wiring (header sets differ slightly per service). No change tosoa-api-core's existing express-server CORS.Verification
pnpm --filter @saga-ed/soa-api-util build✓ (tsup ESM + dts typecheck) ·test✓ (10 tests).Minor bump 1.1.1 → 1.2.0.
Follow-up (after merge + publish)
Publish 1.2.0 to CodeArtifact (single-package workflow), then adopt in iam-api / programs-api / scheduling-api (wildcard model) and connectv3-api (header constant). Those service PRs replace the inline copies (superseding the interim inline-fix PRs: rostering#377, janus#40, program-hub#135, qboard#127).