[GH-ISSUE #8899] No maximum password length check before hashing (utils/password.ts) #11227

Closed
opened 2026-04-13 07:34:20 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @alavesa on GitHub (Apr 1, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8899

Neither validatePassword nor checkPassword enforces a maximum length before passing the password to the hashing function. Bcrypt is intentionally slow — feeding it a multi-megabyte string can monopolize CPU.

Impact: DoS via extremely long password submissions.

Note: #779 discusses password complexity rules but not maximum length as a DoS vector.

Found by PatchPilots security audit.

Originally created by @alavesa on GitHub (Apr 1, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8899 Neither `validatePassword` nor `checkPassword` enforces a maximum length before passing the password to the hashing function. Bcrypt is intentionally slow — feeding it a multi-megabyte string can monopolize CPU. **Impact:** DoS via extremely long password submissions. *Note: #779 discusses password complexity rules but not maximum length as a DoS vector.* Found by [PatchPilots](https://github.com/alavesa/patchpilots) security audit.
GiteaMirror added the securitybug labels 2026-04-13 07:34:20 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 1, 2026):

Better-auth already enforces a maximum password length before hashing. The default limit is 128 characters, configured via the maxPasswordLength option [1]. Passwords exceeding this limit are rejected with a PASSWORD_TOO_LONG error at sign-up, password reset, and password change endpoints [2].

Also worth noting: better-auth uses scrypt (not bcrypt) for password hashing [3], so the bcrypt-specific framing in the issue doesn't quite apply here — but the 128-char cap addresses the general DoS concern regardless of algorithm.

Both minPasswordLength (default 8) and maxPasswordLength (default 128) are configurable through the emailAndPassword auth options [4] [1].

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4172728312 --> @dosubot[bot] commented on GitHub (Apr 1, 2026): <!-- Answer --> Better-auth already enforces a maximum password length **before** hashing. The default limit is **128 characters**, configured via the `maxPasswordLength` option [[1]](https://github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts#L345). Passwords exceeding this limit are rejected with a `PASSWORD_TOO_LONG` error at sign-up, password reset, and password change endpoints [[2]](https://github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/api/routes/password.ts#L282-L289). Also worth noting: better-auth uses **scrypt** (not bcrypt) for password hashing [[3]](https://github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/crypto/password.ts#L4-L5), so the bcrypt-specific framing in the issue doesn't quite apply here — but the 128-char cap addresses the general DoS concern regardless of algorithm. Both `minPasswordLength` (default 8) and `maxPasswordLength` (default 128) are configurable through the `emailAndPassword` auth options [[4]](https://github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts#L344) [[1]](https://github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts#L345). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other#message_id=adde034d-5b62-471c-a1a2-6a280aa80178&feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Better-auth%20already%20enforces%20a%20maximum%20password%20length%20%2A%2Abefore%2A%2A%20hashing.%20The%20default%20limit%20is%20%2A%2A128%20characters%2A%2A%2C%20configured%20via%20the%20%60maxPasswordLength%60%20option%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts%23L345%29.%20Passwords%20exceeding%20this%20limit%20are%20rejected%20with%20a%20%60PASSWORD_TOO_LONG%60%20error%20at%20sign-up%2C%20password%20reset%2C%20and%20password%20change%20endpoints%20%5B%5B2%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/api/routes/password.ts%23L282-L289%29.%0A%0AAlso%20worth%20noting%3A%20better-auth%20uses%20%2A%2Ascrypt%2A%2A%20%28not%20bcrypt%29%20for%20password%20hashing%20%5B%5B3%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/crypto/password.ts%23L4-L5%29%2C%20so%20the%20bcrypt-specific%20framing%20in%20the%20issue%20doesn%27t%20quite%20apply%20here%20%E2%80%94%20but%20the%20128-char%20cap%20addresses%20the%20general%20DoS%20concern%20regardless%20of%20algorithm.%0A%0ABoth%20%60minPasswordLength%60%20%28default%208%29%20and%20%60maxPasswordLength%60%20%28default%20128%29%20are%20configurable%20through%20the%20%60emailAndPassword%60%20auth%20options%20%5B%5B4%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts%23L344%29%20%5B%5B1%5D%5D%28https%3A//github.com/better-auth/better-auth/blob/8682b9d8d2e6216e23ca6d5768627f9d8aa94748/packages/better-auth/src/context/create-context.ts%23L345%29.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8899)
Author
Owner

@alavesa commented on GitHub (Apr 1, 2026):

@dosu. The utility functions in password.ts don't enforce the limit themselves, but the upstream endpoint validation covers it. Closing this one.

<!-- gh-comment-id:4172742115 --> @alavesa commented on GitHub (Apr 1, 2026): @dosu. The utility functions in password.ts don't enforce the limit themselves, but the upstream endpoint validation covers it. Closing this one.
Author
Owner

@dosubot[bot] commented on GitHub (Apr 1, 2026):

That's exactly right — the maxPasswordLength validation happens at the endpoint level before the password ever reaches the hashing utilities, so the utility functions themselves don't need to duplicate that check. Thanks for confirming and closing this out!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4172745517 --> @dosubot[bot] commented on GitHub (Apr 1, 2026): <!-- Answer --> That's exactly right — the `maxPasswordLength` validation happens at the endpoint level before the password ever reaches the hashing utilities, so the utility functions themselves don't need to duplicate that check. Thanks for confirming and closing this out! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other#message_id=97523ec3-ac4c-493f-8101-3afb34428e54&feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=That%27s%20exactly%20right%20%E2%80%94%20the%20%60maxPasswordLength%60%20validation%20happens%20at%20the%20endpoint%20level%20before%20the%20password%20ever%20reaches%20the%20hashing%20utilities%2C%20so%20the%20utility%20functions%20themselves%20don%27t%20need%20to%20duplicate%20that%20check.%20Thanks%20for%20confirming%20and%20closing%20this%20out%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/8899)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11227