Reject overlong user names in dropUser and updateUser by GodfredArhinful · Pull Request #748 · documentdb/documentdb · GitHub
Skip to content

Reject overlong user names in dropUser and updateUser - #748

Open
GodfredArhinful wants to merge 1 commit into
documentdb:mainfrom
GodfredArhinful:fix-drop-update-user-name-length
Open

GodfredArhinful wants to merge 1 commit into
documentdb:mainfrom
GodfredArhinful:fix-drop-update-user-name-length

Conversation

@GodfredArhinful

Copy link
Copy Markdown

Description

Fixes #734.

PostgreSQL truncates identifiers to 63 bytes. dropUser and updateUser passed user names of 64 bytes or more through, so the request acted on the existing user whose name is the 63-byte prefix. Before this change, dropUser with a 64-character name dropped an existing 63-character user and returned ok: 1.

Both commands now reject names of NAMEDATALEN (64) bytes or more before any role lookup or SQL generation, with the same BadValue error that createUser already returns (#730).

Tests added to user_crud_commands:

  • dropUser and updateUser with a 64-byte name, with enableUsernamePasswordConstraints on and off
  • a name of 32 two-byte characters (64 bytes in UTF-8), to show the limit is in bytes
  • the 63-byte user still exists afterwards, its rolpassword is unchanged, and its exact name can still drop it

Without the fix, the same test shows the 63-byte user dropped by the first 64-byte request.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring / code cleanup
  • DevOps / tooling
  • Test improvement
  • Other: ___________

AI Disclosure

  • No AI tools were used substantially in this PR
  • AI tools were used to assist with this PR (please complete below)
    • Tool(s) used: Claude (Claude Code)
    • How it was used: Located the missing checks, wrote the change and regression tests, and ran them in the devcontainer image, including a run against the unfixed code to confirm the test catches the bug.

Checklist

  • I can explain every change in this PR if asked during review
  • I have tested these changes locally
  • I have added or updated tests as appropriate
  • All commits are signed off (DCO: git commit -s)
  • I have read the CONTRIBUTING.md guidelines

PostgreSQL truncates identifiers to 63 bytes, so dropUser and updateUser
with a name of 64 bytes or more acted on the existing user whose name is
its 63-byte prefix. For example, dropUser with a 64-byte name dropped the
63-byte user and reported success.

Both commands now reject names of NAMEDATALEN bytes or more before any
role lookup or SQL generation, with the same error createUser already
returns. The regression test covers both commands with username
constraints enabled and disabled, a 64-byte name of two-byte characters,
and checks that the 63-byte user and its password are left unchanged.

Fixes documentdb#734

Signed-off-by: Godfred Arhinful <102437752+GodfredArhinful@users.noreply.github.com>
@GodfredArhinful
GodfredArhinful requested a review from a team as a code owner September 30, 2026 05:00
@documentdb-triage-tool documentdb-triage-tool Bot added bug documentation Improvements or additions to documentation performance write-operations labels Sep 30, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

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

Labels

bug documentation Improvements or additions to documentation performance write-operations

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Reject overlong dropUser and updateUser names before PostgreSQL identifier truncation

1 participant