Conversation
…ersed password not checked in substrings Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/012529c1-279e-4947-8f12-65a470e1a382 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/d6637020-91e6-4b63-af37-189a7f99f6fb Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/f8f7e4f3-d40a-445a-9d64-2470d1ce0430 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes AttributeValuePasswordValidator substring matching so it correctly detects when attribute values contain password substrings (case-insensitive), and ensures the test-reversed-password option is applied to substring checks as well.
Changes:
- Correct substring comparison logic in
containsSubstring(attribute value contains password substring, not the inverse). - Apply reversed-password substring checks when
ds-cfg-test-reversed-passwordis enabled. - Expand unit tests to cover the full set of 20 substring/reversed-substring cases from the issue report.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
opendj-server-legacy/src/main/java/org/opends/server/extensions/AttributeValuePasswordValidator.java |
Fixes inverted substring logic and adds reversed-password substring evaluation. |
opendj-server-legacy/src/test/java/org/opends/server/extensions/AttributeValuePasswordValidatorTestCase.java |
Adds a dedicated data provider + test covering 10 BLOCK and 10 PASS substring scenarios for uid=USN123. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| Attribute substring = Attributes.create(a.getAttributeDescription().getAttributeType(), | ||
| password.substring(i, j)); | ||
| final String pwdSubstring = password.substring(i, j).toLowerCase(Locale.ROOT); |
There was a problem hiding this comment.
minSubstringLength can be 0 (the config property is an unconstrained integer), which makes j start at i and produces an empty pwdSubstring. Since every string contains "", this would cause containsSubstring to return true immediately and reject all passwords whenever substring checking is enabled. Consider clamping minSubstringLength to at least 1 (or treating non-positive values as “check whole password only”) before entering the loops.
| final String pwdSubstring = password.substring(i, j).toLowerCase(Locale.ROOT); | ||
| for (ByteString val : a) | ||
| { | ||
| if (substring.contains(val)) | ||
| if (val.toString().toLowerCase(Locale.ROOT).contains(pwdSubstring)) | ||
| { |
There was a problem hiding this comment.
In containsSubstring, val.toString().toLowerCase(Locale.ROOT) is recomputed for every password substring, resulting in a lot of repeated UTF-8 decoding + lowercasing in the nested loops. This can be made significantly cheaper by precomputing lowercased attribute values once per Attribute (outside the i/j loops) and by lowercasing the password once up-front (e.g., passwordLower) and taking substrings from that.
|
@copilot apply changes based on the comments in this thread |
… in containsSubstring Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/03d57c68-16a0-43e7-8a5f-045a080213af Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Applied both fixes in commit
|
getSubstringTestDatato include all 20 password test cases from the problem statement (10 BLOCK + 10 PASS)Original prompt
Bug: AttributeValuePasswordValidator — substring check logic is inverted and reversed password is ignored for substrings
Issue: #566
Problem 1 — Inverted logic in
containsSubstringIn
AttributeValuePasswordValidator.java, thecontainsSubstringmethod has inverted logic:What it currently does: checks whether a substring of the password (e.g.
"USN") contains the full attribute value (e.g."USN123") — which is almost alwaysfalse.What it should do: check whether the attribute value (e.g.
"USN123") contains the substring of the password (e.g."USN").The fix should compare the password substring against each attribute value using case-insensitive string matching, e.g.:
Problem 2 —
test-reversed-passwordhas no effect on substring checksIn
passwordIsAcceptable, thereversedstring is computed but never passed tocontainsSubstring:The fix should also call
containsSubstringwith the reversed password whenisTestReversedPassword()istrue:Expected behaviour after fix
For
uid=USN123, withcheck-substrings=true,min-substring-length=3,test-reversed-password=true:USN123aa→ REJECTED (forward substringUSNfound inUSN123)U1sn123b→ REJECTED (forward substring123found inUSN123)NsU321ab→ REJECTED (reversed password substring123found inUSN123)Sun3RiseA→ ACCEPTED (no substrings ofUSN123found)Files to change
opendj-server-legacy/src/main/java/org/opends/server/extensions/AttributeValuePasswordValidator.javaPlease also update or add test cases in:
opendj-server-legacy/src/test/java/org/opends/server/extensions/AttributeValuePasswordValidatorTestCase.javato cover:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: прокомментируй
Assistant: Баг подтверждён. Вот детальный анализ кода:
Баг подтверждён — и вот где именно он находится
Посмотрим на метод
containsSubstringвAttributeValuePasswordValidator.java:В чём проблема
Логика перевёрнута:
Это проверяет, содержит ли подстрока пароля значение атрибута — то есть спрашивает: «входит ли
USN123в подстрокуUSN?» — что всегда будетfalse, если подстрока пароля короче значения атрибута.Должно быть наоборот:
Нужно проверять: «содержит ли значение атрибута (например,
USN123) данную подстроку пароля (например,USN)?»Также есть второй баг —
test-reversed-passwordне работает для подстрок