Skip to content

fix(dashboard-auth): reject passwords longer than bcrypt's 72-byte limit - #598

Merged
Soju06 merged 1 commit into
mainfrom
fix/password-bcrypt-72-byte-limit
May 13, 2026
Merged

Soju06 merged 1 commit into
mainfrom
fix/password-bcrypt-72-byte-limit

Conversation

@Soju06

@Soju06 Soju06 commented May 13, 2026

Copy link
Copy Markdown
Owner

Fixes #597.

Root cause

bcrypt.hashpw enforces a hard 72-byte input limit on the encoded password (bcrypt 5.x raises ValueError("password cannot be longer than 72 bytes ...")). _hash_password in app/modules/dashboard_auth/service.py calls bcrypt.hashpw directly, and the two API entry points that lead there only validate len(password) < 8 before hashing.

So a password whose UTF-8 encoded length exceeds 72 bytes propagated as an unhandled ValueError and surfaced as a 500 with a generic "Unexpected error" on the dashboard frontend (the symptom reported in #597).

Fix

  • Add a shared _validate_password_length helper in app/modules/dashboard_auth/api.py that enforces both the existing 8-character minimum and a new 72-UTF-8-byte maximum.
  • Route both POST /api/dashboard-auth/password/setup and POST /api/dashboard-auth/password/change through it, so the two endpoints validate identically before hashing.
  • On the new failure case, return DashboardValidationError (HTTP 422) with code password_too_long and a message that references the 72-byte limit, so the dashboard can render a clear, actionable error.

The limit is measured against the UTF-8 encoded byte length, not codepoint count, so multi-byte characters (emoji, non-ASCII letters) count for as many bytes as bcrypt itself counts. This matches bcrypt's own ceiling exactly.

Why 72 bytes specifically

bcrypt (the underlying password hashing primitive used by all major language bindings) silently truncates input after 72 bytes when hashing on most platforms, but the Python bcrypt 5.x package explicitly rejects oversize inputs with ValueError instead of silently truncating. Anything that exceeds bcrypt's 72-byte ceiling cannot be hashed at all, so the right place to surface that is at the API layer, not as an unhandled ValueError.

Tests

Added four integration tests in tests/integration/test_dashboard_password_auth.py:

tests/integration/test_dashboard_password_auth.py::test_password_setup_rejects_overlong_password PASSED
tests/integration/test_dashboard_password_auth.py::test_password_setup_accepts_72_byte_password PASSED
tests/integration/test_dashboard_password_auth.py::test_password_setup_counts_utf8_bytes_not_codepoints PASSED
tests/integration/test_dashboard_password_auth.py::test_password_change_rejects_overlong_new_password PASSED

Verification on this branch:

uv run ruff check app/modules/dashboard_auth/api.py tests/integration/test_dashboard_password_auth.py     # clean
uv run ruff format --check app/modules/dashboard_auth/api.py tests/integration/test_dashboard_password_auth.py  # clean
uv run ty check app/modules/dashboard_auth/api.py tests/integration/test_dashboard_password_auth.py        # clean
uv run pytest tests/integration/test_dashboard_password_auth.py tests/unit/test_dashboard_auth_api.py tests/unit/test_dashboard_auth_password_service.py -q   # 16 passed
npx @fission-ai/openspec validate validate-password-length                                                 # change is valid

OpenSpec

Added an OpenSpec change folder openspec/changes/validate-password-length/ capturing the new requirement under the admin-auth capability (length is bounded by bcrypt's input limit, measured in UTF-8 bytes, applied to both setup and change).

Migration / Compatibility

  • No schema or runtime migration.
  • No change to bcrypt behavior or to how passwords are stored.
  • Existing valid passwords are unaffected; the new check matches bcrypt's existing ceiling, so any password that could already be set is still accepted.

Hotfix candidate for v1.17.1

This is a small, scoped fix on the dashboard-auth API surface with no runtime impact. It is a good candidate for the next patch release.

Fixes #597.

`bcrypt.hashpw` enforces a hard 72-byte input limit on the encoded
password (bcrypt 5.x raises `ValueError("password cannot be longer than
72 bytes ...")`). `_hash_password` calls `bcrypt.hashpw` directly, and
the `/password/setup` and `/password/change` endpoints only validate the
8-character minimum before hashing. So a password whose UTF-8 encoded
length exceeds 72 bytes (long ASCII strings, emoji-only strings, etc.)
propagated as an unhandled `ValueError` and surfaced as a 500 with a
generic "Unexpected error" on the dashboard frontend.

Add a shared `_validate_password_length` helper that enforces both the
existing 8-character minimum and a new 72-UTF-8-byte maximum, and route
both endpoints through it. Failures now return HTTP 422 with code
`password_too_long` and a message that references the limit, so the
dashboard can render a clear, actionable error instead of swallowing the
failure as 'Unexpected error'.

The limit is measured against the UTF-8 encoded byte length to match
bcrypt's own ceiling exactly (multi-byte characters like emoji count for
more than one byte). Regression coverage exercises 73-byte ASCII
rejection, exact 72-byte acceptance, emoji-only multi-byte rejection,
and the `/password/change` `new_password` path.
@Soju06

Soju06 commented May 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Soju06
Soju06 merged commit d9b0493 into main May 13, 2026
18 checks passed
Soju06 added a commit that referenced this pull request May 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (#658 strict tool × chat valid/invalid/type-omitted + responses invalid, #650-652 trim replay markers, #516 prev-resp miss mask, #558 prolite plan, #600 token_expired, #635 device poll, #647 frontend 72B, #594 account selection, #640 alembic head, #653/#654 conv archive, #655/#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: #637 (unknown-key drop) + #658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (#600)
- drop-unknown-message-fields (#637)
- mask-single-http-previous-response-miss (#516)
- normalize-v1-responses-openai-sdk-stream (#639)
- start-device-oauth-polling (#635)
- support-prolite-plan-capacity (#558)
- treat-upstream-overloaded-as-retryable (#601)
- validate-password-length (#598)
- validate-strict-function-tool-schema (#658)
Soju06 added a commit that referenced this pull request May 17, 2026
Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md
"release 이후 archive" workflow. All 12 changes verified shipped in
production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d).

1.18.0 (9 changes):
- deactivate-on-token-expired (#600)
- drop-unknown-message-fields (#637)
- mask-single-http-previous-response-miss (#516)
- normalize-v1-responses-openai-sdk-stream (#639)
- start-device-oauth-polling (#635) [delta header fixed: MODIFIED -> ADDED]
- support-prolite-plan-capacity (#558) [delta header fixed: MODIFIED -> ADDED]
- treat-upstream-overloaded-as-retryable (#601)
- validate-password-length (#598)
- validate-strict-function-tool-schema (#658)

1.18.1 (3 changes):
- harden-long-codex-websocket-turns (#586)
- suppress-duplicate-side-effect-tool-calls (#586)
- hotfix-db-pool-pre-ping-and-firewall-cache-ttl (#679)

Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat,
chat-completions-extensions, database-backends, frontend-architecture,
responses-api-compat, usage-refresh-policy).

openspec validate --specs: 19/19 passed.

Co-authored-by: Hermes Agent <[email protected]>
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
…mit (Soju06#598)

Fixes Soju06#597.

`bcrypt.hashpw` enforces a hard 72-byte input limit on the encoded
password (bcrypt 5.x raises `ValueError("password cannot be longer than
72 bytes ...")`). `_hash_password` calls `bcrypt.hashpw` directly, and
the `/password/setup` and `/password/change` endpoints only validate the
8-character minimum before hashing. So a password whose UTF-8 encoded
length exceeds 72 bytes (long ASCII strings, emoji-only strings, etc.)
propagated as an unhandled `ValueError` and surfaced as a 500 with a
generic "Unexpected error" on the dashboard frontend.

Add a shared `_validate_password_length` helper that enforces both the
existing 8-character minimum and a new 72-UTF-8-byte maximum, and route
both endpoints through it. Failures now return HTTP 422 with code
`password_too_long` and a message that references the limit, so the
dashboard can render a clear, actionable error instead of swallowing the
failure as 'Unexpected error'.

The limit is measured against the UTF-8 encoded byte length to match
bcrypt's own ceiling exactly (multi-byte characters like emoji count for
more than one byte). Regression coverage exercises 73-byte ASCII
rejection, exact 72-byte acceptance, emoji-only multi-byte rejection,
and the `/password/change` `new_password` path.
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
Release 1.18.0 — v1.17.0 → main, 27 PR.

## Pre-merge verification (release-gate e2e)

- ✅ CI 18/18 (mergeStateStatus CLEAN)
- ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index)
- ✅ per-PR e2e extra: 14/14 (Soju06#658 strict tool × chat valid/invalid/type-omitted + responses invalid, Soju06#650-652 trim replay markers, Soju06#516 prev-resp miss mask, Soju06#558 prolite plan, Soju06#600 token_expired, Soju06#635 device poll, Soju06#647 frontend 72B, Soju06#594 account selection, Soju06#640 alembic head, Soju06#653/Soju06#654 conv archive, Soju06#655/Soju06#656 weekly pace)
- ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite)
- ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`)
- ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account
- ✅ ruff check + ruff format --check + uv run ty check — All clean
- ✅ prod parity probe: Soju06#637 (unknown-key drop) + Soju06#658 (strict tool 400) both confirmed fixed vs prod 1.17.0

## Behavior change to note in announcements

- **Soju06#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding.

OpenSpec changes shipped in this release (to be archived after tag publish):
- deactivate-on-token-expired (Soju06#600)
- drop-unknown-message-fields (Soju06#637)
- mask-single-http-previous-response-miss (Soju06#516)
- normalize-v1-responses-openai-sdk-stream (Soju06#639)
- start-device-oauth-polling (Soju06#635)
- support-prolite-plan-capacity (Soju06#558)
- treat-upstream-overloaded-as-retryable (Soju06#601)
- validate-password-length (Soju06#598)
- validate-strict-function-tool-schema (Soju06#658)
vitalNohj pushed a commit to vitalNohj/codex-lb that referenced this pull request Jul 17, 2026
…u06#682)

Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md
"release 이후 archive" workflow. All 12 changes verified shipped in
production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d).

1.18.0 (9 changes):
- deactivate-on-token-expired (Soju06#600)
- drop-unknown-message-fields (Soju06#637)
- mask-single-http-previous-response-miss (Soju06#516)
- normalize-v1-responses-openai-sdk-stream (Soju06#639)
- start-device-oauth-polling (Soju06#635) [delta header fixed: MODIFIED -> ADDED]
- support-prolite-plan-capacity (Soju06#558) [delta header fixed: MODIFIED -> ADDED]
- treat-upstream-overloaded-as-retryable (Soju06#601)
- validate-password-length (Soju06#598)
- validate-strict-function-tool-schema (Soju06#658)

1.18.1 (3 changes):
- harden-long-codex-websocket-turns (Soju06#586)
- suppress-duplicate-side-effect-tool-calls (Soju06#586)
- hotfix-db-pool-pre-ping-and-firewall-cache-ttl (Soju06#679)

Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat,
chat-completions-extensions, database-backends, frontend-architecture,
responses-api-compat, usage-refresh-policy).

openspec validate --specs: 19/19 passed.

Co-authored-by: Hermes Agent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error 500 when setting password

1 participant