fix: login with special characters not working on legacy browsers #630

Massimo Melina committed Jun 20, 2024 at 18:33 UTC dec63df26d4924eab32732d8e60cc49ec45476ac
3 files changed +8 -5
frontend/src/UserPanel.ts
+1 -1
@@ -49,7 +49,7 @@ export default function showUserPanel() {
49 label: t`Logout`,
50 id: 'logout',
51 onClick() {
52 - if (fallbackToBasicAuth())
52 + if (fallbackToBasicAuth()) // this is effective on ff52, but not on chrome125
53 return location.href = `//LOGOUT%00:@${location.host}/?get=logout` // redirect, to execute the body content
54 logout().then(closeDialog, alertDialog)
55 }
package.json
-1
@@ -73,7 +73,6 @@
73 "@node-rs/crc32": "^1.6.0",
74 "@rejetto/kvstorage": "^0.10.2",
75 "acme-client": "^5.2.0",
76 - "basic-auth": "^2.0.1",
76 "buffer-crc32": "^0.2.13",
77 "fast-glob": "^3.2.7",
78 "find-process": "^1.4.7",
src/middlewares.ts
+7 -3
@@ -8,7 +8,6 @@ import { Readable } from 'stream'
8 import { applyBlock } from './block'
9 import { Account, accountCanLogin, getAccount } from './perm'
10 import { Connection, normalizeIp, socket2connection, updateConnectionForCtx } from './connections'
11 -import basicAuth from 'basic-auth'
11 import { invalidateSessionBefore, setLoggedIn, srpCheck } from './auth'
12 import { constants } from 'zlib'
13 import { getHttpsWorkingPort } from './listen'
@@ -117,8 +116,13 @@ export const prepareState: Koa.Middleware = async (ctx, next) => {
116 }
117
118 function getHttpAccount() {
120 - const credentials = basicAuth(ctx.req)
121 - return doLogin(credentials?.name||'', credentials?.pass||'')
119 + const b64 = ctx.get('authorization')?.split(' ')[1]
120 + if (!b64) return
121 + try {
122 + const [u, p] = atob(b64).split(':')
123 + return doLogin(u!, p||'')
124 + }
125 + catch {}
126 }
127
128 async function doLogin(u: string, p: string) {