fix(insight): keep the local API same-origin by default#294
Open
shaun0927 wants to merge 2 commits intomksglu:mainfrom
Open
fix(insight): keep the local API same-origin by default#294shaun0927 wants to merge 2 commits intomksglu:mainfrom
shaun0927 wants to merge 2 commits intomksglu:mainfrom
Conversation
Insight serves a same-origin local dashboard, but its API advertised\npermissive cross-origin headers. That allowed a different localhost\norigin to read session events in both runtimes and to preflight +\nissue DELETE requests in the Node runtime.\n\nThis change removes permissive CORS headers from Insight API responses\nwhile keeping the local dashboard behavior unchanged. A focused Node\nregression test boots Insight against fixture SQLite DBs and asserts\nthat sensitive endpoints and DELETE preflights no longer advertise\naccess-control headers.\n\nConstraint: Preserve same-origin Insight dashboard behavior\nRejected: Add a launch-time auth token now | broader product-policy decision\nRejected: Restrict only DELETE while keeping cross-origin GET | privacy-first README framing still conflicts\nConfidence: medium\nScope-risk: narrow\nDirective: Keep Insight same-origin by default unless an explicit sharing mode is designed\nTested: npm run build; npm run typecheck; npx vitest run tests/analytics/insight-cors.test.ts\nNot-tested: Full npm test in local env (unrelated existing failures in security/hook suites)
The initial regression test verified the right behavior, but it rewrote\ninsight/dist inside the repository during execution. That adds avoidable\nshared-state risk under parallel test runs and creates noise unrelated to\nthe policy change itself.\n\nThis follow-up makes the test self-contained by copying the server entry\ninto a temporary insight directory, writing a stub dist/index.html there,\nand symlinking the repo node_modules for package resolution. The runtime\nbehavior under test stays the same while the fixture becomes isolated and\nless brittle.\n\nConstraint: Keep the PR scope limited to the Insight CORS fix and its regression test\nRejected: Leave the repo-mutation approach in place | unnecessary test brittleness\nRejected: Add a Bun-spawned test in this follow-up | wider CI/runtime assumption than needed here\nConfidence: high\nScope-risk: narrow\nDirective: Prefer temp-workspace fixtures over mutating checked-in runtime assets during tests\nTested: npm run typecheck; npx vitest run tests/analytics/insight-cors.test.ts\nNot-tested: Full npm test in local env (same unrelated failures noted in PR mksglu#294)
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.
What / Why / How
Fixes #293
What: remove permissive cross-origin headers from Insight API responses and add a focused regression test for same-machine cross-origin access.
Why: the verified issue is not “remote internet access”, but a local trust-boundary problem: a different localhost origin can read Insight session data in both runtimes, and the Node runtime also permits DELETE preflight + DELETE requests. That conflicts with the README’s privacy-first / local-only framing for Insight.
How:
Access-Control-Allow-*tests/analytics/insight-cors.test.ts, which boots Insight against fixture SQLite DBs and asserts that sensitive session endpoints and DELETE preflights no longer advertise cross-origin access headersinsight/server.mjsagainst fixture DBs while temporarily stubbinginsight/dist/index.htmlAffected platforms
Test plan
npm run buildnpm run typechecknpx vitest run tests/analytics/insight-cors.test.tsnpm testLocal verification before the patch:
Local verification after the patch:
Checklist
npm testpassesnpm run typecheckpassesnextbranch (unless hotfix)Notes:
mainbecause that is the current default branch and the recent merged fixes around this area also landed there.server.mjstree that would losebetter-sqlite3resolution.Cross-platform notes
This patch only changes Insight API response headers and adds a Node-based regression test.