Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: use sufficient computational effort for password hash #3422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jsjoeio merged 27 commits into main from jsjoeio/fix-password-hash
Jun 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dd2cb16
chore: update CHANGELOG
jsjoeio May 19, 2021
cac6673
refactor: use bcrypt in hash function
jsjoeio May 19, 2021
17be8c5
refactor: use bcrypt in e2e setup
jsjoeio May 19, 2021
f35120c
feat: add unit test for hash function
jsjoeio May 19, 2021
aaf0447
refactor: add functions to check hash password
jsjoeio May 19, 2021
fc3326f
feat: add tests using real hashes
jsjoeio May 20, 2021
dc2db5c
chore: add argon2 package
jsjoeio Jun 2, 2021
51f8341
chore: update to argon2 in test
jsjoeio Jun 2, 2021
70197bb
refactor: use argon2 instead of bcrypt
jsjoeio Jun 2, 2021
fd3cb6c
refactor: update unit tests for hash fns
jsjoeio Jun 2, 2021
fcc3f0d
refactor: update login logic with new async hashing
jsjoeio Jun 2, 2021
0cdbd33
refactor: make authenticated async everywhere
jsjoeio Jun 2, 2021
91303d4
refactor: make ensureAuthenticated async
jsjoeio Jun 2, 2021
1134780
refactor: make wsProxy async
jsjoeio Jun 2, 2021
788b958
refactor: update hash fn in test config
jsjoeio Jun 2, 2021
ffa5c16
feat: update cli and test for hashed-password
jsjoeio Jun 2, 2021
7ff4117
feat: add getPasswordMethod & test for it
jsjoeio Jun 2, 2021
a14ea39
feat: add handlePasswordValidation + tests
jsjoeio Jun 2, 2021
409b473
refactor: rewrite password logic at /login
jsjoeio Jun 2, 2021
6020480
feat: add isCookieValid function and tests
jsjoeio Jun 3, 2021
923761c
refactor: password logic in http w/ isCookieValid
jsjoeio Jun 3, 2021
517aaf7
docs: update FAQ with new hashing instructions
jsjoeio Jun 3, 2021
531b7c0
feat: add splitOnFirstEquals function
jsjoeio Jun 3, 2021
8c2bb61
refactor: parse options with multiple = in cli
jsjoeio Jun 3, 2021
deaa224
feat: add npm_config_build_from_source to build scripts
jsjoeio Jun 7, 2021
3b50bfc
fix: sanitize password and cookie key
jsjoeio Jun 7, 2021
1e55a64
feat: check for empty str in isHashMatch
jsjoeio Jun 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: update login logic with new async hashing
This adds the proper await logic for the hashing of passwords.
  • Loading branch information
jsjoeio committed Jun 8, 2021
commit fcc3f0d951954159c711f79e145b6c0f973b8370
7 changes: 6 additions & 1 deletion src/node/routes/login.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ router.post("/", async (req, res) => {
? isHashLegacyMatch(req.body.password, req.args["hashed-password"])
: req.args.password && safeCompare(req.body.password, req.args.password)
) {
const hashedPassword = req.args["hashed-password"] ? hashLegacy(req.body.password) : hash(req.body.password)
// NOTE@jsjoeio:
// We store the hashed password as a cookie. In order to be backwards-comptabile for the folks
// using sha256 (the original hashing algorithm), we need to check the hashed-password in the req.args
// TODO all of this logic should be cleaned up honestly. The current implementation only checks for a hashed-password
// but doesn't check which algorithm they are using.
const hashedPassword = req.args["hashed-password"] ? hashLegacy(req.body.password) : await hash(req.body.password)
// The hash does not add any actual security but we do it for
// obfuscation purposes (and as a side effect it handles escaping).
res.cookie(Cookie.Key, hashedPassword, {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While hashing is a major step forward, the problem with this approach is that it still allows attackers who have access to the hash to just submit it as-is and gain access to code-server - effectively not very different from storing it in plaintext.

We should definitely look into replacing this with something more robust so that password hashing isn't just a placebo - now or in a future version is up to you, but IMO we should tackle this before asking users to upgrade to Argon2.

jsjoeio reacted with thumbs up emoji
Copy link
Contributor Author

@jsjoeio jsjoeio Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effectively not very different from storing it in plaintext.

I'm really glad you mention that and agree.

We should definitely look into replacing this with something more robust so that password hashing isn't just a placebo

Also agree!

now or in a future version is up to you, but IMO we should tackle this before asking users to upgrade to Argon2

I would argue that it falls out of the scope of this PR. If we close this PR without merging, we're in the same situation we're discussing right now (see code) because we're doing the same thing - hashing the password and storing as a cookie.

The scope of this PR was to replace the hashing algorithm (not to fix the problem with attackers who have the hash).

Therefore, I think it makes sense to separate the two concerns and tackle them in separate PRs. I will create a new issue to track that though!

RA80533 reacted with thumbs up emoji
Copy link
Contributor Author

@jsjoeio jsjoeio Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@RA80533 RA80533 Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally get it. Sometimes PRs bring in a lot of heat just because they touch an area that would otherwise have a lot of attention drawn towards. This one specifically has allowed us to become aware of other things in the codebase we want to change.

🙏

Expand Down

AltStyle によって変換されたページ (->オリジナル) /