fix(api): RFC1918 CORS reflection opt-in via STEM_CORS_ALLOW_PRIVATE (security) - #399
Merged
Merged
Conversation
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
enabled auto-merge (squash)
June 7, 2026 05:19
Contributor
License Compliance ReportAll dependencies pass license compliance checksGo Dependencies
npm DependenciesSee full report in workflow artifacts Allowed Licenses: MIT, Apache-2.0, BSD-*, ISC, CC0-1.0, MPL-2.0 |
This was referenced Jul 8, 2026
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.
stem security hardening (follow-up to #398).
Problem
corsMiddlewarereflected any RFC1918 private-network origin (192.168/16,10/8,172.16-31) and setAccess-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_RFC1918Originto the opt-in path and addedTestCorsMiddleware_RFC1918BlockedByDefault. Fullinternal/apisuite passes.