Skip to content

security: remove wildcard CORS and sanitize error responses - #1

Merged
ZeR020 merged 1 commit into
mainfrom
security/cors-error-sanitization
May 1, 2026
Merged

security: remove wildcard CORS and sanitize error responses#1
ZeR020 merged 1 commit into
mainfrom
security/cors-error-sanitization

Conversation

@ZeR020

@ZeR020 ZeR020 commented May 1, 2026

Copy link
Copy Markdown
Owner

Security Fixes

Addresses socket.dev operational security findings:

Changes

  • Removed wildcard CORS headers (, etc.) from web server JSON responses. The server binds to by default — wildcard CORS is unnecessary exposure.
  • Sanitized API error responses — replaced raw with generic / in all catch blocks across , , and .
  • Preserved server-side logging — actual errors are still logged internally for debugging.

Why

  • Prevents information leakage (stack traces, file paths, SQL details) to API clients
  • Removes unjustified cross-origin access from a localhost-only service

Verification

  • No new test regressions (12 pre-existing parallel-test failures unchanged)

- Remove Access-Control-Allow-Origin: * from web server responses
  (server binds to 127.0.0.1; wildcard CORS is unnecessary exposure)
- Replace raw String(error) in API responses with generic 'Internal error'
  (prevents info leakage: stack traces, file paths, SQL details)
- Log actual errors server-side for debugging while keeping client
  responses opaque

Fixes socket.dev operational security findings: medium-risk CORS
and error disclosure issues.
Copilot AI review requested due to automatic review settings May 1, 2026 10:06
@ZeR020
ZeR020 merged commit 2a18005 into main May 1, 2026
5 checks passed
@ZeR020
ZeR020 deleted the security/cors-error-sanitization branch May 1, 2026 10:15
@ZeR020
ZeR020 removed the request for review from Copilot May 1, 2026 10:30
ZeR020 added a commit that referenced this pull request Jun 30, 2026
…late dedup

Dead code removed (graph-confirmed zero callers):
- ensureShardTables, getShardByPath (shard-manager.ts)
- countVectors(containerTag) (vector-search.ts)
- getMessagesByRoleStmt prepared statement + field (ai-session-manager.ts)
- maxProfileItems config field + docs + test ref
- 6 duplicate FTS5 triggers in migrate-v1-to-v2.ts
- 6 dead i18n keys (en + zh)
- sessionIdleSweep speculative 10K-entry LRU guard (index.ts)

Stdlib replacements:
- Hand-rolled UserProfileValidator (107ln) → zod schema with matching error messages
- 3× dynamic `await import("zod")` → static top-level imports

Shrinks:
- fetchWithTimeout() + apiErrorResponse() hoisted to BaseAIProvider
- All 4 providers refactored to use shared HTTP boilerplate
- plugin.ts IIFE wrapper flattened
- Obsolete marked.setOptions headerIds/mangle removed (marked v8+)
- Broken lint-deepsource.sh rules #1 (awk) and #10 (complexity) fixed

22 files changed, net -92 lines (-434/+342)
All 730 tests + typecheck + build + format:check + lint-deepsource pass
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.

2 participants