fix: gracefully handle base64 decoding error in case of invalid access token (#1302)

This commit is contained in:
Laurin Quast 2023-02-08 10:20:58 +01:00 committed by GitHub
parent efae22e7b6
commit f01c25efce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,7 +38,14 @@ export function decodeCdnAccessTokenSafe(token: string) {
token = token.slice(keyPrefix.length);
const str = globalThis.atob(token);
let str: string;
try {
str = globalThis.atob(token);
} catch (error) {
return decodeError;
}
const [keyId, privateKey] = str.split(':');
if (keyId && privateKey) {
return { type: 'success', token: { keyId, privateKey } } as const;