Skip to content

Commit ffa5c16

Browse files
committed
feat: update cli and test for hashed-password
1 parent 788b958 commit ffa5c16

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const options: Options<Required<Args>> = {
114114
"hashed-password": {
115115
type: "string",
116116
description:
117-
"The password hashed with SHA-256 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file). \n" +
117+
"The password hashed with argon2 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file). \n" +
118118
"Takes precedence over 'password'.",
119119
},
120120
cert: {

src/node/routes/login.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from "path"
55
import safeCompare from "safe-compare"
66
import { rootPath } from "../constants"
77
import { authenticated, getCookieDomain, redirect, replaceTemplates } from "../http"
8-
import { hash, hashLegacy, humanPath, isHashLegacyMatch } from "../util"
8+
import { hash, hashLegacy, humanPath, isHashLegacyMatch, isHashMatch } from "../util"
99

1010
export enum Cookie {
1111
Key = "key",
@@ -72,6 +72,14 @@ router.post("/", async (req, res) => {
7272
throw new Error("Missing password")
7373
}
7474

75+
// this logic below is flawed
76+
const theHash = await hash(req.body.password)
77+
const hashedPassword = req.args["hashed-password"] || ""
78+
const match = await isHashMatch(req.body.password, hashedPassword)
79+
// console.log(`The actual hash: ${theHash}`)
80+
// console.log(`hashed-password from config: ${hashedPassword}`)
81+
// console.log(theHash, hashedPassword)
82+
console.log(`is it a match??? ${match}`)
7583
if (
7684
req.args["hashed-password"]
7785
? isHashLegacyMatch(req.body.password, req.args["hashed-password"])
@@ -82,6 +90,7 @@ router.post("/", async (req, res) => {
8290
// using sha256 (the original hashing algorithm), we need to check the hashed-password in the req.args
8391
// TODO all of this logic should be cleaned up honestly. The current implementation only checks for a hashed-password
8492
// but doesn't check which algorithm they are using.
93+
console.log(`What is this? ${req.args["hashed-password"]}`, Boolean(req.args["hashed-password"]))
8594
const hashedPassword = req.args["hashed-password"] ? hashLegacy(req.body.password) : await hash(req.body.password)
8695
// The hash does not add any actual security but we do it for
8796
// obfuscation purposes (and as a side effect it handles escaping).

test/unit/cli.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ describe("parser", () => {
305305
})
306306
})
307307

308-
it("should use env var hashed password", async () => {
309-
process.env.HASHED_PASSWORD = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" // test
308+
it.only("should use env var hashed password", async () => {
309+
process.env.HASHED_PASSWORD =
310+
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY" // test
310311
const args = parse([])
311312
expect(args).toEqual({
312313
_: [],
@@ -316,7 +317,8 @@ describe("parser", () => {
316317
expect(defaultArgs).toEqual({
317318
...defaults,
318319
_: [],
319-
"hashed-password": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
320+
"hashed-password":
321+
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY",
320322
usingEnvHashedPassword: true,
321323
})
322324
})

0 commit comments

Comments
 (0)