Skip to content

feat: proxy API key injection + per-source TTL (#70)#102

Merged
alohays merged 3 commits intomainfrom
feat/proxy-key-injection
Mar 19, 2026
Merged

feat: proxy API key injection + per-source TTL (#70)#102
alohays merged 3 commits intomainfrom
feat/proxy-key-injection

Conversation

@alohays
Copy link
Owner

@alohays alohays commented Mar 19, 2026

Summary

  • Add server-side API key injection to Edge Function proxy: sources can configure authEnvVar and authHeader to inject credentials at the proxy layer, keeping keys off the client
  • Add per-source cache TTL (cacheTtl field) with runtime override via ?ttl= query parameter; resolution order: query param > source config > default 300s
  • Add forge validate warning when rate limiting is enabled on stateless Edge Functions (no external state store)
  • New build artifact api/_shared/proxy-config.ts generated at build time with domain-to-auth and source-to-TTL mappings

Changes

  • Schema (forge/src/config/schema.ts): authEnvVar, authHeader, cacheTtl on SourceSchema
  • Build (forge/src/commands/build.ts, forge/src/generators/manifest-generator.ts): generateProxyConfig() produces api/_shared/proxy-config.ts
  • Proxy (api/proxy/v1/index.ts): imports injectAuthHeader + proxyConfig/sourceTtl, injects auth headers, resolves TTL
  • Key injection (api/_shared/key-injection.ts): pure function, bearer vs plain scheme
  • Validation (forge/src/commands/validate.ts): rate-limit warning on stateless edge
  • Frontend type (src/core/sources/SourceBase.ts): aligned with schema additions

Test plan

  • api/_shared/key-injection.test.ts — 6 unit tests for bearer/plain/missing/no-config scenarios
  • api/proxy/v1/index.test.ts — key injection with/without env var, custom header, TTL override tests
  • forge/src/commands/validate.test.ts — rate-limit warning present/absent
  • forge/src/generators/manifest-generator.test.tsgenerateProxyConfig domain mapping, scheme, TTL
  • npx tsc --noEmit — zero errors
  • npx vitest run — 764 tests passed (39 test files)

🤖 Generated with Claude Code

alohays and others added 3 commits March 20, 2026 03:14
Add server-side API key injection and per-source cache TTL to the
Edge Function proxy, enabling secure upstream authentication without
exposing keys to the browser.

Schema:
- Add authEnvVar, authHeader, cacheTtl fields to SourceSchema

Build:
- Generate api/_shared/proxy-config.ts with domain-to-auth mapping
  and source-to-TTL mapping at build time

Proxy:
- New api/_shared/key-injection.ts for header-based auth injection
- Proxy handler injects auth headers based on target domain
- TTL resolution: ?ttl= query param > source cacheTtl > default 300

Validation:
- Warn when rate limiting is enabled on stateless Edge Functions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Strip authEnvVar and authHeader from source configs in client-side
  manifests (source-manifest.ts and config-resolved.ts) to prevent
  leaking secrets to the browser bundle
- Validate and clamp ?ttl= query param (positive, finite, max 86400s)
- Include authEnvVar in .env.example generation
- Add UPPER_SNAKE_CASE regex validation for authEnvVar in schema
- Only warn about rate-limit on stateless edge functions when cache
  provider is memory (not when Upstash is configured)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Only strip authEnvVar (the secret reference) from client bundles.
authHeader and cacheTtl are non-sensitive config values safe to include.
Update preset snapshots for new source schema fields.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alohays alohays force-pushed the feat/proxy-key-injection branch from ddf6705 to 3f1f679 Compare March 19, 2026 18:22
@alohays alohays merged commit 66dfb35 into main Mar 19, 2026
1 check passed
@alohays alohays deleted the feat/proxy-key-injection branch March 19, 2026 18:23
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