Skip to content

fix(api): RFC1918 CORS reflection opt-in via STEM_CORS_ALLOW_PRIVATE (security) - #399

Merged
krisarmstrong merged 1 commit into
mainfrom
harden/stem-cors-private-optin
Jun 7, 2026
Merged

fix(api): RFC1918 CORS reflection opt-in via STEM_CORS_ALLOW_PRIVATE (security)#399
krisarmstrong merged 1 commit into
mainfrom
harden/stem-cors-private-optin

Conversation

@krisarmstrong

Copy link
Copy Markdown
Collaborator

stem security hardening (follow-up to #398).

Problem

corsMiddleware reflected any RFC1918 private-network origin (192.168/16, 10/8, 172.16-31) and set Access-Control-Allow-Credentials: true. On a shared/hostile LAN, a malicious origin could make credentialed cross-origin requests with the victim admin's cookies — a CSRF-bypass vector (the attacker origin can also read the CSRF-token response).

Fix

Secure by default: allow only localhost + same-origin (normal UI access is same-origin, so zero impact). RFC1918 reflection is now opt-in via STEM_CORS_ALLOW_PRIVATE (env), which logs a warning when enabled — for operators who genuinely need cross-origin LAN access.

Kept all the validated RFC1918 helper functions + their unit tests; just gated their use. Switched TestCorsMiddleware_RFC1918Origin to the opt-in path and added TestCorsMiddleware_RFC1918BlockedByDefault. Full internal/api suite passes.

The CORS middleware reflected ANY RFC1918 private-network origin with
Allow-Credentials: true — a cross-origin CSRF-bypass vector on a shared or
hostile LAN (a malicious LAN page could drive credentialed requests with the
victim admin's cookies). Default is now localhost + same-origin only (normal UI
access is same-origin, so no impact); RFC1918 reflection is opt-in via
STEM_CORS_ALLOW_PRIVATE (logs a warning when enabled).

Validated RFC1918 helpers + their unit tests are retained; switched the
RFC1918-allowed test to the opt-in path and added
TestCorsMiddleware_RFC1918BlockedByDefault. Full internal/api suite green.
@krisarmstrong
krisarmstrong enabled auto-merge (squash) June 7, 2026 05:19
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

License Compliance Report

All dependencies pass license compliance checks

Go Dependencies

  • Unknown: 31 package(s)
  • MIT: 26 package(s)
  • BSD-3-Clause: 16 package(s)
  • Apache-2.0: 11 package(s)
  • BSD-2-Clause: 1 package(s)

npm Dependencies

See full report in workflow artifacts

Allowed Licenses: MIT, Apache-2.0, BSD-*, ISC, CC0-1.0, MPL-2.0
Forbidden: GPL, AGPL, SSPL (strong copyleft)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant