Skip to content

Commit 60c270a

Browse files
authored
cli: hashedPassword -> hashed-password (#2454)
Capital letters in the CLI are evil. cc @code-asher
1 parent 386af14 commit 60c270a

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

doc/FAQ.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Again, please follow [./guide.md](./guide.md) for our recommendations on setting
163163

164164
## Can I store my password hashed?
165165

166-
Yes you can! Use `hashedPassword` instead of `password`. Generate the hash with:
166+
Yes you can! Use `hashed-password` instead of `password`. Generate the hash with:
167167

168168
```
169169
echo "thisismypassword" | sha256sum | cut -d' ' -f1

doc/guide.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ and then restart `code-server` with:
297297
sudo systemctl restart code-server@$USER
298298
```
299299

300-
Alternatively, you can specify the SHA-256 of your password at the `hashedPassword` field in the config file.
301-
The `hashedPassword` field takes precedence over `password`.
300+
Alternatively, you can specify the SHA-256 of your password at the `hashed-password` field in the config file.
301+
The `hashed-password` field takes precedence over `password`.
302302

303303
### How do I securely access development web services?
304304

src/node/cli.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface Args extends VsArgs {
2929
config?: string
3030
auth?: AuthType
3131
password?: string
32-
hashedPassword?: string
32+
"hashed-password"?: string
3333
cert?: OptionalString
3434
"cert-host"?: string
3535
"cert-key"?: string
@@ -106,7 +106,7 @@ const options: Options<Required<Args>> = {
106106
type: "string",
107107
description: "The password for password authentication (can only be passed in via $PASSWORD or the config file).",
108108
},
109-
hashedPassword: {
109+
"hashed-password": {
110110
type: "string",
111111
description:
112112
"The password hashed with SHA-256 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file). \n" +
@@ -285,8 +285,8 @@ export const parse = (
285285
throw new Error("--password can only be set in the config file or passed in via $PASSWORD")
286286
}
287287

288-
if (key === "hashedPassword" && !opts?.configFile) {
289-
throw new Error("--hashedPassword can only be set in the config file or passed in via $HASHED_PASSWORD")
288+
if (key === "hashed-password" && !opts?.configFile) {
289+
throw new Error("--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD")
290290
}
291291

292292
const option = options[key]
@@ -466,7 +466,7 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
466466

467467
const usingEnvHashedPassword = !!process.env.HASHED_PASSWORD
468468
if (process.env.HASHED_PASSWORD) {
469-
args.hashedPassword = process.env.HASHED_PASSWORD
469+
args["hashed-password"] = process.env.HASHED_PASSWORD
470470
usingEnvPassword = false
471471
}
472472

src/node/entry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const main = async (args: DefaultedArgs): Promise<void> => {
9999
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
100100
logger.trace(`Using extensions-dir ${humanPath(args["extensions-dir"])}`)
101101

102-
if (args.auth === AuthType.Password && !args.password && !args.hashedPassword) {
102+
if (args.auth === AuthType.Password && !args.password && !args["hashed-password"]) {
103103
throw new Error(
104104
"Please pass in a password via the config file or environment variable ($PASSWORD or $HASHED_PASSWORD)",
105105
)

src/node/http.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export const authenticated = (req: express.Request): boolean => {
5454
// The password is stored in the cookie after being hashed.
5555
return !!(
5656
req.cookies.key &&
57-
(req.args.hashedPassword
58-
? safeCompare(req.cookies.key, req.args.hashedPassword)
57+
(req.args["hashed-password"]
58+
? safeCompare(req.cookies.key, req.args["hashed-password"])
5959
: req.args.password && safeCompare(req.cookies.key, hash(req.args.password)))
6060
)
6161
default:

src/node/routes/login.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ router.post("/", async (req, res) => {
6868
}
6969

7070
if (
71-
req.args.hashedPassword
72-
? safeCompare(hash(req.body.password), req.args.hashedPassword)
71+
req.args["hashed-password"]
72+
? safeCompare(hash(req.body.password), req.args["hashed-password"])
7373
: req.args.password && safeCompare(req.body.password, req.args.password)
7474
) {
7575
// The hash does not add any actual security but we do it for

test/cli.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe("parser", () => {
303303
assert.deepEqual(await setDefaults(args), {
304304
...defaults,
305305
_: [],
306-
hashedPassword: "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
306+
"hashed-password": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
307307
usingEnvHashedPassword: true,
308308
})
309309
})

0 commit comments

Comments
 (0)