Repository navigation
fix(auth): 用户名和用户ID校验拒绝末尾换行 - #1158
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更说明
validate_usernameand the two uid checks usedre.match(r"^...$", value).In Python
$also matches before a final\n, so"admin\n"passed.get_by_usernamecompares exactly, so"admin\n"passed the uniqueness check and was stored next to"admin".It renders the same as
"admin", for example in the share picker.This PR uses
re.fullmatchwith the same character class at the three sites:backend/yuxi/modules/identity/services/usernames.pyvalidate_usernamebackend/yuxi/api/routers/identity/auth.pyinitialize_adminuidbackend/yuxi/modules/identity/services/administration.pycreate_department_with_adminadmin_uidIt adds
backend/test/unit/identity/test_usernames.py.bug-fix\n, which the error message and the frontend rule already say are not allowed.Behavior change: the only change is that a username or uid ending in one
\nis now rejected with the existing error message. Every other input gets the same result as before (checked by a 200000-string fuzz and a 5000-example hypothesis run, see below). Existing rows that already end in\nare not touched.工程主张与 Owner
_, with no hidden trailing newline.validate_usernamein usernames.py owns the username rule. The inline checks ininitialize_adminandcreate_department_with_adminown the uid rule. Observable as the 400 / InvalidOperationError response and as the storedusers.username/users.uid.implementedrecord if you want one.验证情况
Trailing newline is rejected
validate_username("admin\n")returned(True, "")andupdate_profilestored"admin\n"next to"admin".validate_username, uid checks in auth.py and administration.pypytest test/unit/identity -q-> 28 passed (10 new). With usernames.py reverted, the new testtest_validate_username_rejects_whitespace_and_symbols[admin\n]fails (1 failed, 9 passed).\r,\r\n, inner or leading newline,\n\n, U+2028, U+0085, VT, FF, NUL, fullwidth letters, spaces,-,., empty, length 1 and 21: rejected before and after.No valid name is newly rejected
validate_username, uid checksst.text, 5000 examples: old and new differ only on a trailing\n.ad, 20 chars,Admin,ADMIN,张三,龥龥,a_1,__,01still accepted.Lint and repo guards
ruff check yuxipassed,ruff format yuxi --check448 files already formatted,ruff check --select I yuxipassed, same on the new test file.python scripts/ci/verify_engineering_contracts.pypassed.Integration and full unit suite
pytest test/unit,make test简化 / 删除验收
不涉及
独立语义 Review
A fresh-context reviewer read the full diff (three one-line regex changes and the new test file) and the traced request-to-storage path. It checked every number and command in this body against the validation run. Conclusion: the change is correct and small, and the impact is low (display-name lookalike, no login or access change). No unresolved items. This review does not replace the test evidence above.
未验证范围与风险
Usermodel andupdate_profile.\nstay as they are. No migration.事故反馈
Not a high-impact escape. Display-name lookalike only, no login or access change. No postmortem.
界面变更
不涉及
关联事项
Closes #1157
补充说明
The same
^...$pattern is inmodules/knowledge/evaluation/service.pyfor run_id. It is followed by an exact DB lookup, so it is harmless and left out of this PR.Validated with Claude Opus 5.5.
🤖 Generated with Claude Code