[issue15061] hmac.secure_compare() leaks information about length of strings

Serhiy Storchaka report at bugs.python.org
Fri Jun 22 08:08:53 CEST 2012


Serhiy Storchaka <storchaka at gmail.com> added the comment:

> > > We could handle all bytes-compatible objects, using the buffer API.
> > It is timing unsafe.
> How so?

I checked myself, and I see that most likely I was wrong. At least for
bytes and bytearrays it is timing safe.

> I don't think that's the right answer, because people will instead e.g.
> encode('utf-8'), and suddently the encodingly will not be timing-safe.

And what of that? It is outside of the timingsafe_eq function. People
can also do other timing unsafe operations with the secret key (for
example reading it from file or from DB) or not to use timingsafe_eq at
all. The secret key should be pre-encoded.

The error will be if code works for developer from ASCII word, and then
on the other side of ocean it will no longer work with non-ASCII
strings. You are expected to be familiar with such issues. In any case,
the obvious (and simplest, and fastest) way to check that a string is
ASCII-only is try to encoded it to ASCII.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15061>
_______________________________________


More information about the Python-bugs-list mailing list