[CLIENT-3518]: Validate username/password length - #1187
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1187 +/- ##
==========================================
+ Coverage 85.39% 85.43% +0.03%
==========================================
Files 101 101
Lines 14614 14654 +40
==========================================
+ Hits 12479 12519 +40
Misses 2135 2135 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
juliannguyen4
left a comment
There was a problem hiding this comment.
Just one point I wanted to mention, but otherwise LGTM!
| OP_MAP_CREATE: Literal[1144] | ||
| OP_MAP_SET_POLICY: Literal[1101] | ||
| OP_MAP_SIZE: Literal[1106] | ||
| PASSWORD_SIZE: Literal[64] |
There was a problem hiding this comment.
We might not need to expose the max PASSWORD_SIZE and USER_SIZE if we can just document the max length in the API docs. Here's the current documentation for client config's "user" and "password" options: https://aerospike-python-client.readthedocs.io/en/latest/aerospike.html#:~:text=server’s%20CA%20certificate.-,user,-(str
I think it would help to add the max lengths for those options' descriptions. They're in doc/aerospike.rst
There was a problem hiding this comment.
Yes, that is not required, have removed that.
Summary
Fixes CLIENT-3518. The Python client silently ignores
as_config_set_user()'s return value whenconfig["user"]/config["password"](or the positional args toclient.connect()) are too long, so an oversized username/password gets silently truncated by the C client with no error surfaced to the caller.Changes
src/main/client/type.c— in theaerospike.client(config)constructor, validateusername/passwordlength againstAS_USER_SIZE/AS_PASSWORD_SIZEbefore callingas_config_set_user. RaisesParamErrorwith a precise message ("Username/Password length exceeds the maximum of 63 characters") if either is too long.src/main/client/connect.c— same validation added toclient.connect(username, password).src/main/aerospike.c— exposedaerospike.USER_SIZEandaerospike.PASSWORD_SIZE(both64, the raw C buffer size including the null terminator) as public module constants, following the existingmodule_constants[]pattern, so callers can introspect the limit.aerospike-stubs/aerospike.pyi— added type stub entries for the two new constants.test/new_tests/test_connect.py— added test coverage (see below).Why this approach
as_config_set_user'sboolreturn value — this makes the fix self-contained and not dependent on the separateaerospike-client-cfix (atomic reject) landing first.AS_USER_SIZE/AS_PASSWORD_SIZEare used directly from the C header (already transitively included viaas_config.h) for the validation itself; the new module constants are for external callers who want to introspect the limit, not used internally for the check.Testing
test_connect_invalid_configs— added two new parametrized cases (username too long,password too long) covering the constructor path.test_connect_call_with_too_long_credentials— new parametrized test covering theclient.connect(username, password)path.test_user_and_password_size_constants— assertsaerospike.USER_SIZE == 64andaerospike.PASSWORD_SIZE == 64.ParamError; the 63-char boundary is accepted without a false-positive rejection.test_connect.pysuite passes (25 passed, 2 pre-existing skips) with no regressions.