> I can't see any, but then I couldn't see the security consequences of
> predictable string hashes until they were pointed out to me. So it would
> be really good to have some security experts comment on whether this is
> safe or not.

I can't either. I can point out that the complexity attack via hash collisions 
is not possible on None specifically because it is a singleton, so:
1. There may only be one None in a dict at most, 
2. For composite types that depend on None and other things, like say a tuple 
of string and an optional int, they become as resistant to attack as the same 
types without None, in this case string and int.
3. Python only explicitly added this security (hash randomization) feature to 
string and bytes hashes, and if your composite key type depends on those types, 
it will still be protected regardless of what None does


> Because this entire discussion is motivated by the OP who wants
> consistent set order across multiple runs of his Python application.
> That's what he needs; having None hash to a constant value is just a
> means to that end.

Not entirely. I do explain in my doc why there is a foundational reason why, 
once the choice was made to have None represent the `None` of Optional[T], it 
entered the family of types that you would expect to have deterministic 
behavior. And as the hashing function is intrinsic to types in Python, it is 
included in that.


> Even if we grant None a constant hash, that still does not guarantee
> consistent set order across runs. At best, we might get such consistent
> order as an undocumented and changeable implementation detail, until we
> change the implementation of hashing, or of sets, or of something
> seemingly unrelated like address randomisation.

ASLR will not cause any trouble so long as I keep objects with identity based 
hashing out of my sets. Or at least, any sets I later iterate on and run 
imperative code with side-effects under the loop.
The possibility of disabling ASLR is not a reason to dismiss this change. No 
one guarantees a user of Python is in a position to make infosec related 
decisions on the computer system they are working on.

Regarding the possibilities of hashes changing for the worse (in this regard) - 
sure. Anything is possible.

Regarding sets - the set implementation is deterministic, and always has been 
(for decades).
Yes, in theory it is possible that a new version or implementation of Python 
will make sets non-deterministic - shuffle themselves in the background 
independently from their history of operations, or what have you, and then my 
change loses all of its value.
Like I said, anything is possible. But I think these last two points are 
essentially FUD.

I made my proposal because I believe the FUD scenarios are strongly unlikely. 
(and even then, at worst we end up with a "practically useless" behavior on 
None, that can also be freely reverted along with such other changes anyway)
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/GD3N4DZQXISYM6UQQLMKJC6Z52N54IO3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to