-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de151c0
commit 9d5867d
Showing
3 changed files
with
30 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type {NextFunction, Request, Response} from 'express' | ||
import {basename} from 'path' | ||
import {Config} from '../config.js' | ||
import {checkSign} from '../util.js' | ||
|
||
export function AuthRouteFactory(config: Config) { | ||
return (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const oldUrl = req.get('x-original-uri') | ||
if (!oldUrl) return res.status(403).send('invalid sign') | ||
Check warning on line 10 in src/routes/auth.route.ts GitHub Actions / build (20)
|
||
|
||
const url = new URL(oldUrl, 'http://localhost') | ||
const hash = basename(url.pathname) | ||
const query = Object.fromEntries(url.searchParams.entries()) | ||
const signValid = checkSign(hash, config.clusterSecret, query) | ||
if (!signValid) { | ||
return res.status(403).send('invalid sign') | ||
Check warning on line 17 in src/routes/auth.route.ts GitHub Actions / build (20)
|
||
} | ||
res.sendStatus(204) | ||
Check warning on line 19 in src/routes/auth.route.ts GitHub Actions / build (20)
|
||
} catch (e) { | ||
return next(e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters