-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
skip-changelogThis PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.type/bug
Milestone
Description
Description
I get Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded when doing the FIDO2 authentication and cannot login.
Gitea Version
1.19.0+dev-320-gde484e86b
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
gitea:dev-rootless container
Database
MySQL
Metadata
Metadata
Assignees
Labels
skip-changelogThis PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.type/bug
Type
Projects
Relationships
Development
Select code repository
Activity
zeripath commentedon Jan 18, 2023
Are there any server logs associated?
wxiaoguang commentedon Jan 19, 2023
I can confirm the same bug on my instance. It could be either a server-side bug or a client-side (JS) bug.
lunny commentedon Jan 19, 2023
Maybe related #22400
silverwind commentedon Jan 19, 2023
There is only one
atob
case in our JS and it comes from https://github.com/WebReflection/uint8-to-base64/blob/ff5c87dd100dbf72d2ed9edf4b81a4ce23f1a8c1/index.js#L20.As for the reason, I can only guess. I know that
atob
andbtoa
are limited to ASCII characters when encoding/decoding, e.g. characters outside the ASCII set (UTF8) would fail.BTW shouldn't this error be caught using
window.onerror
and display on the page?wxiaoguang commentedon Jan 19, 2023
Invalid base64 chars all cause
atob
fail:The response of
/user/webauthn/assertion
is something like that on my side:wxiaoguang commentedon Jan 19, 2023
I guess the problem is caused by inconsitent base64 encoding standard.
Then the
atob
indeocde
tries to decode-_
base64 chars, then error occurs.(ps: just my guess, I am not using the webauthn now, so feel free to continue)
wxiaoguang commentedon Jan 19, 2023
And you see, I have questioned before:
"Unknown problems" always cause more problems. That's why I always insist to make things consistent and clear. But I doubt seldom people agree with me.
silverwind commentedon Jan 19, 2023
There is https://www.npmjs.com/package/base64url, I guess one solution would be to incorporate https://www.npmjs.com/package/uint8-to-base64 in our code and use that module instead to encode/decode the base64.
Fix Uncaught DOMException: Failed to execute 'atob' on 'Window'
[-]Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.[/-][+]Login with security keys no longer possible[/+]zeripath commentedon Jan 29, 2023
The problem is not to do with mis-encoding of base64 or otherwise. The issue is that the functions
btoa
andatob
are not available when they're called.The
The string to be decoded is not correctly encoded
is a red-herring and the error was written this way because it was assumed that that is the only way such a call could fail.The
uint8-to-base64
code does not importatob
orbtoa
fromwindow
and just expects them to be available. Something in our configuration or the browser has recently become a lot stricter and this no longer works. Although I could try to bisect the error to figure out if it was something that we changed it would be quite difficult, time consuming and frankly infuriating.@silverwind may know or be able to point to something where things were made more strict.
16 remaining items