mirror of
https://github.com/coder/code-server.git
synced 2026-09-02 08:30:17 +02:00
Require auth for mint key endpoint (#7923)
The client combines the key from this endpoint to then encrypt secrets into browser storage.
This commit is contained in:
@@ -210,7 +210,7 @@ router.get("/manifest.json", async (req, res) => {
|
||||
})
|
||||
|
||||
let mintKeyPromise: Promise<Buffer> | undefined
|
||||
router.post("/mint-key", async (req, res) => {
|
||||
router.post("/mint-key", ensureAuthenticated, async (req, res) => {
|
||||
if (!mintKeyPromise) {
|
||||
mintKeyPromise = new Promise(async (resolve) => {
|
||||
const keyPath = path.join(req.args["user-data-dir"], "serve-web-key-half")
|
||||
|
||||
@@ -4,11 +4,19 @@ import * as integration from "../../../utils/integration"
|
||||
|
||||
describe("vscode", () => {
|
||||
let codeServer: httpserver.HttpServer | undefined
|
||||
// TODO: Support setting this as an argument for tests.
|
||||
const previousEnvPassword = process.env.PASSWORD
|
||||
beforeEach(() => {
|
||||
process.env.PASSWORD = "test"
|
||||
mockLogger()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
if (typeof previousEnvPassword !== "undefined") {
|
||||
process.env.PASSWORD = previousEnvPassword
|
||||
} else {
|
||||
delete process.env.PASSWORD
|
||||
}
|
||||
if (codeServer) {
|
||||
await codeServer.dispose()
|
||||
codeServer = undefined
|
||||
@@ -27,4 +35,10 @@ describe("vscode", () => {
|
||||
})
|
||||
}).rejects.toThrow()
|
||||
})
|
||||
|
||||
it("should require auth", async () => {
|
||||
codeServer = await integration.setup(["--auth=password"], "")
|
||||
let resp = await codeServer.fetch("/mint-key", { method: "POST" })
|
||||
expect(resp.status).toBe(401)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user