Skip to content

Commit 5ff120a

Browse files
committed
cli: hashedPassword -> hashed-password
Capital letters in the CLI are evil. cc @code-asher
1 parent 730a73e commit 5ff120a

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
@@ -162,7 +162,7 @@ Again, please follow [./guide.md](./guide.md) for our recommendations on setting
162162

163163
## Can I store my password hashed?
164164

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

167167
```
168168
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
@@ -105,7 +105,7 @@ const options: Options<Required<Args>> = {
105105
type: "string",
106106
description: "The password for password authentication (can only be passed in via $PASSWORD or the config file).",
107107
},
108-
hashedPassword: {
108+
"hashed-password": {
109109
type: "string",
110110
description:
111111
"The password hashed with SHA-256 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file). \n" +
@@ -276,8 +276,8 @@ export const parse = (
276276
throw new Error("--password can only be set in the config file or passed in via $PASSWORD")
277277
}
278278

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

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

458458
const usingEnvHashedPassword = !!process.env.HASHED_PASSWORD
459459
if (process.env.HASHED_PASSWORD) {
460-
args.hashedPassword = process.env.HASHED_PASSWORD
460+
args["hashed-password"] = process.env.HASHED_PASSWORD
461461
usingEnvPassword = false
462462
}
463463

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
@@ -301,7 +301,7 @@ describe("parser", () => {
301301
assert.deepEqual(await setDefaults(args), {
302302
...defaults,
303303
_: [],
304-
hashedPassword: "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
304+
"hashed-password": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
305305
usingEnvHashedPassword: true,
306306
})
307307
})

0 commit comments

Comments
 (0)