You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
uuid() accepts nil, v1, and max UUIDs despite documenting UUID-v4 validation #600
uuid() is documented as validating a UUID-v4, but it currently accepts UUIDs of any version, including the nil and max UUIDs.
Repro
With validators 0.35.0:
>>>importvalidators>>>validators.uuid("00000000-0000-0000-0000-000000000000") # nil UUIDTrue>>>validators.uuid("2bc1c94f-0deb-13e9-92a1-4775189ec9f8") # version 1True>>>validators.uuid("2bc1c94f-0deb-43e9-92a1-4775189ec9f8") # version 4True>>>validators.uuid("ffffffff-ffff-ffff-ffff-ffffffffffff") # max UUIDTrue
UUID objects are also accepted without checking their version:
If uuid() is intended to be UUID-v4-specific, only version-4 values should return True; nil, v1, and other versions should return ValidationError.
Actual behavior
Every value that uuid.UUID(...) can parse returns True. For string input this happens because the UUID(value) object is truthy, so the version is never checked. For UUID objects, the function returns True immediately.
Why this matters
Callers may use this validator specifically to enforce random v4 identifiers. Accepting v1 UUIDs can admit timestamp/node-based identifiers, while nil and max UUIDs are sentinel values rather than normal generated identifiers.
Possible resolution
Either:
enforce parsed_uuid.version == 4 for both string and UUID inputs, or
if accepting all UUID versions is intentional, update the documentation so callers do not rely on v4-only validation.
I would be happy to implement whichever direction you prefer, with regression tests.
Activity