1

I was learning how antiforgery tokens work behind the scenes and wrote this article on the possible values a token can have.

When the byte array is converted to base64, there are four left over bits which have two zeros appended to get a group of 6 bits, which can then be converted to a base64 character.

The problem is that this limits the range of values for the last character.

Because the last two bits are always zeros, the last char can only have 16 possible values (A, E, I, M, Q, U, Y, c, g, k, o, s, w, 0, 4, 8) instead of 64.

Wouldn't this essentially make it easier for hackers to brute force?

Why wouldn't the designers have made the byte length two more than what it is? Ie. 117 instead of 115? 117*8 = 936 bits which is a common multiple of 6 and 8, which would mean no left over bits that need to be padded with zeros, and would mean the final char could be one of 64 values instead of one of 16. Thus increasing the security.

If your token is:

CfDJ8JeOl95vyt5Fl-pHZGf77Sm3JmKSHdO1PQpV74QafJuJKW3y-uSagKNSpzLHS4SBLkNoOov2RrbaJow-61gPO3CoQllu1D9qeqWIDciJzPXJGakA-boNPsC_9H7DgtClsFHz6lS-Qd9qFeQs3vskEsw

You could replace the last char w with x, y, or z and the app would consider them all to be the same token, seems like a bug to me.

I've done the maths at the end of that article if you're interested.

4
  • Decreasing the length of a token will always make it easier to brute force, never harder.
    – nobody
    Jan 27, 2021 at 9:58
  • @nobody I made a mistake with the maths. Please see my updated question. Jan 27, 2021 at 10:05
  • 1
    It should be noted that 920 bits is a lot, and brute forcing it is infeasible. Adding two bits makes it harder, but it's in the area of 'impossible before the heat death of the universe' anyway, if the tokens are randomly distributed.
    – vidarlo
    Jan 27, 2021 at 10:50
  • So basically they pulled that number out of thin air? I know it doesn't add much more security by using an extra 2 bytes, but it just seems strange to choose a number that results in people being able to replace the last char with any 4 consecutive chars in the base64 table. Seems almost a bit like a bug to me. Jan 27, 2021 at 11:47

0

You must log in to answer this question.

Browse other questions tagged .