Repository navigation
fix(api): enforce API key policy on ElevenLabs proxy routes (#12574) - #13244
Merged
Merged
Conversation
Githab-capibara
added a commit
to Githab-capibara/OmniRoute
that referenced
this pull request
Sep 17, 2026
…inference#12574) (cheaper-inference#13244) Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on cheaper-inference#13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for cheaper-inference#13278 and cheaper-inference#13276, annotated and landed on cheaper-inference#13243⚠️ base-red inherited: cheaper-inference#12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…inference#12574) (cheaper-inference#13244) Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on cheaper-inference#13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for cheaper-inference#13278 and cheaper-inference#13276, annotated and landed on cheaper-inference#13243⚠️ base-red inherited: cheaper-inference#12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
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.
Closes #12574
Root cause
The three ElevenLabs-backed
/v1/*routes (speech-to-text,text-to-speech/[voiceId],voices) all funnel through the sharedproxyElevenLabsRequest()insrc/app/api/v1/_shared/elevenLabsProxy.ts, which went straight from credential lookup tothe upstream
fetch()and never calledenforceApiKeyPolicy(). Every other billable/v1/*route (images, audio, videos, music, ocr, rerank, moderations, embeddings, search,etc.) calls
enforceApiKeyPolicybefore dispatch. Because theclientApiPolicymiddlewareonly validates key validity/ban/expiry (not budget, custom rate limits, schedule windows, or
allowedEndpoints), any valid API key could call these three routes completely unconstrainedby an operator's budget caps or rate limits.
A second, related gap: even with
enforceApiKeyPolicy()added,allowedEndpointsscopingwould still no-op on these three routes because
ENDPOINT_CATEGORIES(
src/shared/constants/endpointCategories.ts) only mapped/v1/audioto theaudiocategory —
resolveEndpointCategory()returnednullfor/v1/speech-to-text,/v1/text-to-speech, and/v1/voices, sovalidateEndpointAccess()never fired for them.Fix
src/app/api/v1/_shared/elevenLabsProxy.ts: callenforceApiKeyPolicy(request, null)atthe top of
proxyElevenLabsRequest(), before the credential lookup, matching the patternused by 21 sibling
/v1/*routes (e.g.src/app/api/v1/images/upscale/route.ts). Arejected key never touches ElevenLabs credentials or issues an upstream request.
src/shared/constants/endpointCategories.ts: added a newelevenlabscategory withprefixes
/v1/speech-to-text,/v1/text-to-speech,/v1/voices— a dedicated categoryrather than extending
audio, so existing keys already scoped toaudio(expecting only/v1/audio/*) are not silently widened.tests/unit/elevenlabs-policy.test.ts(new): budget-exceeded key gets 429 on all threeroutes without reaching upstream; a key scoped away from the
elevenlabscategory gets403 on all three routes; an unrestricted key still proxies through successfully.
tests/unit/endpoint-categories.test.ts: added 3 cases assertingresolveEndpointCategory()now maps the three ElevenLabs paths toelevenlabsinstead ofnull.Regression test — RED → GREEN
node --import tsx/esm --test tests/unit/elevenlabs-policy.test.tsRED (on unfixed code, verified by temporarily reverting the two production files):
GREEN (with the fix):
Gates run (all green)
node scripts/check/check-file-size.mjs— OK, no frozen file grownnode scripts/check/check-complexity.mjs— OK (2799 violations vs baseline 3218)node scripts/check/check-cognitive-complexity.mjs— OK (1265 violations vs baseline 1437)npm run typecheck:core— exit 0npx eslint --suppressions-location config/quality/eslint-suppressions.json <changed files>— exit 0tests/unit/elevenlabs-policy.test.ts(new) — 3/3 passtests/unit/endpoint-categories.test.ts(existing + 3 new cases) — 29/29 passtests/unit/endpoint-restrictions-policy.test.ts(existing) — 11/11 passtests/unit/api-key-policy.test.ts(existing) — 41/41 passtests/unit/elevenlabs-native-routes.test.ts(existing) — 6/6 pass, no regressionnode scripts/check/check-changelog-integrity.mjs— OK