Skip to content

Commit ceb7bfb

Browse files
committed
bump metadata; use buffer instead of btoa
1 parent c932ba0 commit ceb7bfb

3 files changed

Lines changed: 74 additions & 6 deletions

File tree

package-lock.json

Lines changed: 66 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"private": true,
99
"scripts": {
1010
"start": "wrangler dev",
11-
"deploy": "wrangler publish",
11+
"deploy": "wrangler publish"
12+
},
13+
"dependencies": {
14+
"buffer": "^6.0.3"
1215
}
1316
}

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Buffer } from "buffer";
2+
13
class BadRequestException extends Error {
24
constructor(reason) {
35
super(reason);
@@ -76,9 +78,8 @@ function requireHttps(request) {
7678

7779
function parseBasicAuth(request) {
7880
const Authorization = request.headers.get("Authorization");
79-
const [scheme, encoded] = Authorization.split(" ");
80-
const buffer = Uint8Array.from(Buffer.from(encoded, 'base64'), (c) => c.charCodeAt(0));
81-
const decoded = new TextDecoder().decode(buffer).normalize();
81+
const [scheme, data] = Authorization.split(" ");
82+
const decoded = Buffer.from(data, 'base64').toString('ascii');
8283
const index = decoded.indexOf(":");
8384

8485
if (index === -1 || /[\0-\x1F\x7F]/.test(decoded)) {

0 commit comments

Comments
 (0)