fix: authentication check in path proxy (#5442)
`proxy` should `await` for result of `authenticated` call otherwise since otherwise it will always appear to be authenticated as the promise is truthy. Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
parent
c69f2c69f6
commit
2ec1e2de34
@ -94,8 +94,8 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
|
||||
app.router.use("/", domainProxy.router)
|
||||
app.wsRouter.use("/", domainProxy.wsRouter.router)
|
||||
|
||||
app.router.all("/proxy/(:port)(/*)?", (req, res) => {
|
||||
pathProxy.proxy(req, res)
|
||||
app.router.all("/proxy/(:port)(/*)?", async (req, res) => {
|
||||
await pathProxy.proxy(req, res)
|
||||
})
|
||||
app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => {
|
||||
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest)
|
||||
@ -103,8 +103,8 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
|
||||
// These two routes pass through the path directly.
|
||||
// So the proxied app must be aware it is running
|
||||
// under /absproxy/<someport>/
|
||||
app.router.all("/absproxy/(:port)(/*)?", (req, res) => {
|
||||
pathProxy.proxy(req, res, {
|
||||
app.router.all("/absproxy/(:port)(/*)?", async (req, res) => {
|
||||
await pathProxy.proxy(req, res, {
|
||||
passthroughPath: true,
|
||||
})
|
||||
})
|
||||
|
@ -14,14 +14,14 @@ const getProxyTarget = (req: Request, passthroughPath?: boolean): string => {
|
||||
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
|
||||
}
|
||||
|
||||
export function proxy(
|
||||
export async function proxy(
|
||||
req: Request,
|
||||
res: Response,
|
||||
opts?: {
|
||||
passthroughPath?: boolean
|
||||
},
|
||||
): void {
|
||||
if (!authenticated(req)) {
|
||||
): Promise<void> {
|
||||
if (!(await authenticated(req))) {
|
||||
// If visiting the root (/:port only) redirect to the login page.
|
||||
if (!req.params[0] || req.params[0] === "/") {
|
||||
const to = self(req)
|
||||
|
Reference in New Issue
Block a user