Skip to content

fix(audio): strict base64 body input decoding #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oOraph
Copy link
Contributor

@oOraph oOraph commented Aug 20, 2025

context:

javascripts libs tend to send as base64 what is not base64: it's <rfc-2397-prefix>,<base64-payload>

https://stackoverflow.com/questions/20517429/parse-base64-string-coming-fron-javascript-front-end-data-uri-rfc2397

data:audio/mpeg;base64,ENCODEDDATA

-> this is not valid base64 and we should just raise a bad request to that

what happened so far is that the python ends up sending the whole data into
https://docs.python.org/3/library/binascii.html#binascii.a2b_base64

and somehow manages to "decode" even non valid b64 string (how ? discarding non valid chars ? or just by taking the data byte by byte and stripping the 4 upper bits that should be null - but are not necessarily for non valid b64 chars - in every byte and concatenating the kept bits altogether to get the decoded data ? I don't know -> would need to reverse the hexdump)

so we ended up injecting decoded tainted data (garbage header + audio data) into the transformers lib

and somehow the python lib used by this one to parse audio data sometimes managed to recognize the data as proper audio (eg discard the garbage). For example it worked for mp3 but not flac data (don't know the mp3 struct but there must be some header that the lib expected, discarding all padding/garbage before)

in short the data injected into inference was not the same as the data originally sent by the user and we were lucky it answered sth (and even more it answered something relevant to what had been requested)

An (imo bad) alternative to this fix could be to be more flexible and parse rfc 2397 properly when found but there is no reason to call b64 what is not

@oOraph oOraph requested review from alvarobartt and ErikKaum August 20, 2025 09:42
Copy link
Member

@ErikKaum ErikKaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find, thank you 👍

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