You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Task queue emulator incorrectly decodes base64 payload with atob(), should be Buffer.from(..., "base64") #8836
The emulator doesn't decode strings with non-ascii utf8 characters correctly, for example, emoji.
Enqueue a task using firebase-admin in one (http) function:
const taskData = {"key":"some value with a utf-8 character, such as emoji"}
const queue = getFunctions().taskQueue("someTask")
await queue.enqueue(taskData)
Receive it:
export default async function someTask(req: TaskRequest) {
// does not print the original character
console.log(req.data.key)
}
[REQUIRED] Steps to reproduce
Run the emulator, invoke the http function that enqueues task, watch the task print the unexpected value.
[REQUIRED] Expected behavior
It should print exactly the utf-8 string that was enqueued.
[REQUIRED] Actual behavior
It prints a "junk" decoding.
The problem is that the emulator uses the JavaScript atob() function to decode the base64 payload created by the Admin SDK. Here is what the Admin SDK does (correctly):
atob() uses the JavaScript native utf-16 internal encoding for strings, however, this incorrectly decodes anything with a codepoint above 256. What the emulator should do instead is use Buffer.from(data, "base64").toString("utf-8").
Here is a bit of node repl that illustrates the expected translation, including JSON parsing:
Activity
Use Buffer.from().toString() instead of atob() to decode task payload (…
Use Buffer.from().toString() instead of atob() to decode task payload (…
Use Buffer.from().toString() instead of atob() to decode task payload (…
aalej commentedon Jul 15, 2025
Thanks for reporting this and for submitting a PR @CodingDoug! I'm able to reproduce the issue. Let me raise this to our engineering team.
Sharing the mcve here
Use Buffer.from().toString() instead of atob() to decode task payload (…