Repository navigation
fix(audio): sanitize upstream error bodies on /v1/audio/translations - #17844
Conversation
cheaper-inference#15159 moved audioSpeech and audioTranscription onto the shared upstreamErrorResponse helper, but the translation handler kept a local extractUpstreamErrorMessage that returned the raw upstream body when it was not JSON. An HTML error page, stack trace or echoed token therefore reached the client, and the error response carried no CORS headers. Use upstreamErrorResponse and drop the local helper.
|
Thanks a lot @AndresDiagoM, this is a clean, well-scoped fix. You spotted exactly the sibling that #15159 missed, and routing /v1/audio/translations through the shared upstreamErrorResponse (and dropping the local extractUpstreamErrorMessage) is the right call: opaque HTML or plaintext bodies now become What we will take care of in-place on your branch (you keep full credit): adding the changelog fragment One optional follow-up for a separate PR if you are interested: the fetch-failure |
5da1890 to
c29a6eb
Compare
|
Thanks for the detailed verification. The fragment was already on the branch ( On the fetch-failure |
…lations Carried over from cheaper-inference#17941: a JSON upstream message with a credential and a server path loses both but keeps its reason. Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com>
|
@diegosouzapw I carried the hostile-JSON case from #17941 over myself in 8c523be ( |
b423973
into
cheaper-inference:release/v3.8.53
Closes #17843.
Summary
open-sse/handlers/audioTranslation.tsreturnederrorResponse(res.status, extractUpstreamErrorMessage(errText, res.status)). That local helper passederrTextthrough verbatim whenever the body wasn't JSON or had no message field, so an HTML error page, stack trace or echoed credential reached the/v1/audio/translationsclient, and the error response had no CORS headers.upstreamErrorResponse(res, errText)fromopen-sse/utils/audioResponse.ts, asaudioSpeech.tsandaudioTranscription.tshave since fix(backend): whole-repository audit findings for v3.8.52 — 78 items (14 critical · 21 high · 29 medium · 14 keep) #15159, and delete the local helper. The handler shrinks by 16 lines.Client-visible change
Upstream error (N), no longer the provider's text.error.message, a stringerror, ormessage) is kept aftersanitizeErrorMessage. Plain prose such as "too many requests" is unchanged. A JSON body with no message field now givesUpstream error (N)where it used to return the raw JSON text.Validation (TDD)
New
tests/unit/audio-translations-upstream-error-sanitization.test.ts(2 tests, modelled onaudio-upstream-error-sanitization-15159.test.ts). Run against the original handler:With the fix, all
tests/unit/audio-*.test.tspass, 152/152, including the existingaudio-translations-route.test.tsJSON 429 case and the #15159 suite.typecheck:core, eslint on the changed files,check-file-size, andcheck-complexity-ratchets --base-ref origin/release/v3.8.53(new-code mode, both OK) all pass.