test(electric-proxy): lock tenant filters and upstream auth stripping
Description
This PR adds executable security regression coverage for the Electric proxy. The new tests lock down the tenant-scoping and upstream-forwarding contracts that protect Electric shape requests:
- organization-owned tables include the requested organization filter
auth.organizationsis limited to JWT organization membershipsauth.apikeysuses the restricted organization column and sensitive column projection- unknown tables are rejected
- client-provided
where,secret, andcolumnsparams are not forwarded as trusted upstream params - bearer/cookie headers are stripped before forwarding to Electric
- invalid/missing auth and unauthorized organizations are rejected at the worker boundary
The PR also adds the missing test script and Bun test types for this workspace so the tests are discoverable through Turbo.
Related Issues
No existing issue. This was discovered during repository analysis.
Type of Change
- Bug fix
- New feature
- Documentation
- Refactor
- Other (please describe): security regression tests / test infrastructure
Testing
Commands run:
bun --cwd apps/electric-proxy test— passedbun run test --filter=electric-proxy— passedbun --cwd apps/electric-proxy typecheck— passedbunx @biomejs/biome@2.4.2 check apps/electric-proxy/package.json apps/electric-proxy/tsconfig.json apps/electric-proxy/src/where.test.ts apps/electric-proxy/src/electric.test.ts apps/electric-proxy/src/index.test.ts bun.lock— passedgit diff --check— passed
Screenshots (if applicable)
N/A.
Additional Notes
Risk level: low. This PR does not change production Electric proxy behavior; it adds regression coverage and a workspace test script for security-critical tenant filtering and auth-header stripping.
Summary by cubic
Adds executable security regression tests for the Electric proxy to lock tenant scoping, upstream auth stripping, and response header sanitization for shape requests, including source credential handling and sensitive column restrictions. Also locks stable handles by sorting JWT organization IDs and allows auth.organizations without an organizationId; adds a workspace test script and bun-types so tests run under Turbo.
Summary by CodeRabbit
-
Bug Fixes
- Improved proxy request handling for organization-scoped access, authorization checks, and upstream forwarding behavior.
- Tightened handling of query parameters and headers to make forwarded requests more consistent and secure.
-
Chores
- Added automated test coverage for core proxy behaviors.
- Updated project setup to support Bun-based testing and typings.