Skip to content

Commit 25b1340

Browse files
authored
revert: @node-rs/argon2 -> node-argon2 (#4829)
* revert: partial revert of 723469a This reverts part of the changes introduced in refactor: migrate from argon2 -> @node-rs/argon2 (#4733) Switching to @node-rs/argon2 introduced bugs that we couldn't solve due to limitations in npm. see here #4804 (comment)
1 parent 00224fa commit 25b1340

File tree

8 files changed

+369
-102
lines changed

8 files changed

+369
-102
lines changed

ci/build/build-standalone-release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
5+
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
6+
export npm_config_build_from_source=true
7+
48
main() {
59
cd "$(dirname "${0}")/../.."
610

ci/build/npm-postinstall.sh

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ detect_arch() {
1818
}
1919

2020
ARCH="${NPM_CONFIG_ARCH:-$(detect_arch)}"
21+
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
22+
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
23+
export npm_config_build_from_source=true
2124

2225
main() {
2326
# Grabs the major version of node from $npm_config_user_agent which looks like

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
},
8686
"dependencies": {
8787
"@coder/logger": "1.1.16",
88-
"@node-rs/argon2": "^1.0.5",
88+
"argon2": "^0.28.0",
8989
"compression": "^1.7.4",
9090
"cookie-parser": "^1.4.5",
9191
"env-paths": "^2.2.0",

src/node/util.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { logger } from "@coder/logger"
2-
import * as argon2 from "@node-rs/argon2"
1+
import * as argon2 from "argon2"
32
import * as cp from "child_process"
43
import * as crypto from "crypto"
54
import envPaths from "env-paths"
@@ -167,12 +166,7 @@ export const isHashMatch = async (password: string, hash: string) => {
167166
if (password === "" || hash === "" || !hash.startsWith("$")) {
168167
return false
169168
}
170-
try {
171-
return await argon2.verify(hash, password)
172-
} catch (error: any) {
173-
logger.error(error)
174-
return false
175-
}
169+
return await argon2.verify(hash, password)
176170
}
177171

178172
/**

test/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@types/node-fetch": "^2.5.8",
99
"@types/supertest": "^2.0.11",
1010
"@types/wtfnode": "^0.7.0",
11+
"argon2": "^0.28.0",
1112
"jest": "^27.3.1",
1213
"jest-fetch-mock": "^3.0.3",
1314
"jsdom": "^16.4.0",
@@ -19,6 +20,7 @@
1920
},
2021
"resolutions": {
2122
"ansi-regex": "^5.0.1",
23+
"argon2/@mapbox/node-pre-gyp/tar": "^6.1.9",
2224
"set-value": "^4.0.1",
2325
"tmpl": "^1.0.5",
2426
"path-parse": "^1.0.7",

test/unit/node/util.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ describe("isHashMatch", () => {
141141
const actual = await util.isHashMatch(password, _hash)
142142
expect(actual).toBe(false)
143143
})
144-
it("should return false if the hash doesn't start with a $", async () => {
144+
it("should return false and not throw an error if the hash doesn't start with a $", async () => {
145145
const password = "hellowpasssword"
146146
const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
147+
expect(async () => await util.isHashMatch(password, _hash)).not.toThrow()
147148
expect(await util.isHashMatch(password, _hash)).toBe(false)
148149
})
149-
it("should return false if the password and hash don't match", async () => {
150+
it("should reject the promise and throw if error", async () => {
150151
const password = "hellowpasssword"
151152
const _hash = "$ar2i"
152-
const actual = await util.isHashMatch(password, _hash)
153-
expect(actual).toBe(false)
153+
expect(async () => await util.isHashMatch(password, _hash)).rejects.toThrow()
154154
})
155155
})
156156

0 commit comments

Comments
 (0)