Skip to content

fix(Security\Hasher): Guard PASSWORD_ARGON2 constants with defined() check - #65791

Open
hiro-gj wants to merge 4 commits into
nextcloud:masterfrom
hiro-gj:fix/65780-hasher-argon2
Open

hiro-gj wants to merge 4 commits into
nextcloud:masterfrom
hiro-gj:fix/65780-hasher-argon2

Conversation

@hiro-gj

@hiro-gj hiro-gj commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

Guard PASSWORD_ARGON2ID and PASSWORD_ARGON2I constants with defined() checks in Hasher::hash().

On PHP environments compiled without Argon2 support (--with-password-argon2 not enabled), referencing these undefined constants results in a fatal error (Error: Undefined constant "OC\Security\PASSWORD_ARGON2ID") before the bcrypt fallback can be evaluated.

Follow-up to #64733
cc @provokateurin

Checklist

…check

Guard constant references with defined() checks so that systems without Argon2 support can safely fall back to bcrypt without fatal errors.

Follow-up to nextcloud#64733

Fixes nextcloud#65780

Signed-off-by: User Name <user@example.com>
@hiro-gj
hiro-gj requested a review from a team as a code owner October 22, 2026 13:13
@hiro-gj
hiro-gj requested review from Altahrim, icewind1991, leftybournes and provokateurin and removed request for a team October 22, 2026 13:13
Comment thread lib/private/Security/Hasher.php Outdated
Comment on lines 77 to 81

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The match (true) pattern is not verry readable, and also, I think this won't work as the message will contain a ref to an algo that is not used I think. Maybe best to revert to the old code logic.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My link is a diff, please check the left part of the link (4e0e711e247c08025433254c88e877244c7b854ee3746523b75e6598a8386808)

@hiro-gj hiro-gj Oct 27, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@artonge Ah, the red one! My apologies!

	#[\Override]
	public function hash(string $message): string {
		$alg = $this->getPrefferedAlgorithm();

		if (\defined('PASSWORD_ARGON2ID') && $alg === PASSWORD_ARGON2ID) {
					return 3 . '|' . password_hash($message, PASSWORD_ARGON2ID, $this->options);
				}

				if (\defined('PASSWORD_ARGON2I') && $alg === PASSWORD_ARGON2I) {
					return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options);
				}
		return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options);
	}

@solracsf solracsf added this to the Nextcloud 36 milestone Oct 24, 2026
Hasher.php
SHA-512 Hash:
`fcc70008dd3bdd28be13c1e457954b34acefe6796e0cd63a774cb916e7d798caced1842e922bbae106421400686a5ab96612bc35fa8000add77488d1a839e0d2`

Signed-off-by: hiro-gj <49264814+hiro-gj@users.noreply.github.com>
…1feb8

fix/Hasher-argon2_before_commit_ee1feb8
@artonge

artonge commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

/backport to stable35

@artonge

artonge commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@hiro-gj can you fix the conflicts?

…e line endings to LF

Keep the legacy hash validation fix from c0525c3 while applying the
defined() check for PASSWORD_ARGON2 constants in Hasher::hash().

Fixes nextcloud#65780

Signed-off-by: hiro-gj <49264814+hiro-gj@users.noreply.github.com>
Signed-off-by: User Name <user@example.com>
@hiro-gj

hiro-gj commented Oct 29, 2026

Copy link
Copy Markdown
Author

can you fix the conflicts?

@artonge Sorry! There was an issue with the line endings.
I’ve converted everything to LF and resolved the conflicts.

https://github.com/nextcloud/server/pull/65791/changes

Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: (35.0.2) Fix Undefined constant PASSWORD_ARGON2ID in OCSecurityHasher

3 participants