Brain Storm
Brain Storm

Reputation: 59

Different YouTube URLs points to the same video

I found some bug in youtube when I reverse engineering it's video id generator. If I change last characther of the video id, it redirects to same video. How is this possible?

Example:

https://www.youtube.com/watch?v=9bZkp7q19f0
https://www.youtube.com/watch?v=9bZkp7q19f1
https://www.youtube.com/watch?v=9bZkp7q19f2
https://www.youtube.com/watch?v=9bZkp7q19f3

But this url isn't work:

https://www.youtube.com/watch?v=9bZkp7q19f4

Upvotes: 2

Views: 387

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45432

The videoId is 8 Bytes (64 bit) base64 encoded. From this post :

For the videoId, it is an 8-byte (64-bit) integer. Applying Base64-encoding to 8 bytes of data requires 11 characters. However, since each Base64 character conveys exactly 6 bits, this allocation could actually hold up to 11 × 6 = 66 bits--a surplus of 2 bits over what our payload needs. The excess bits are set to zero, which has the effect of excluding certain characters from ever appearing in the last position of the encoded string. In particular, the videoId will always end with one of the following: { A, E, I, M, Q, U, Y, c, g, k, o, s, w, 0, 4, 8 }

In your case, your videoId is 9bZkp7q19f0 :

enc.  | 9      b      Z      k      p      7      q      1      9      f      | 0
value | 61     27     25     36     41     59     42     53     61     31     | 52
bin.  | 111101 011011 011001 100100 101001 111011 101010 110101 111101 011111 | 1101  00

If you modify the last character, the 64 bit id will change if the 4 most significative bit (MSB) are modified :

9bZkp7q19f1 :

enc.  | 9      b      Z      k      p      7      q      1      9      f      | 1
value | 61     27     25     36     41     59     42     53     61     31     | 53
bin.  | 111101 011011 011001 100100 101001 111011 101010 110101 111101 011111 | 1101  01

9bZkp7q19f2 :

enc.  | 9      b      Z      k      p      7      q      1      9      f      | 2
value | 61     27     25     36     41     59     42     53     61     31     | 54
bin.  | 111101 011011 011001 100100 101001 111011 101010 110101 111101 011111 | 1101  10

9bZkp7q19f3 :

enc.  | 9      b      Z      k      p      7      q      1      9      f      | 3
value | 61     27     25     36     41     59     42     53     61     31     | 55
bin.  | 111101 011011 011001 100100 101001 111011 101010 110101 111101 011111 | 1101  11

This will give a different video id (note the 4 MSB of the last Byte are modified 1101 to 1110) :

enc.  | 9      b      Z      k      p      7      q      1      9      f      | 4
value | 61     27     25     36     41     59     42     53     61     31     | 56
bin.  | 111101 011011 011001 100100 101001 111011 101010 110101 111101 011111 | 1110  00

9bZkp7q19f4 will give a different 64 bit id. Note that if such an id exists 9bZkp7q19f4, 9bZkp7q19f5, 9bZkp7q19f6 and 9bZkp7q19f7 will give the same id.

You can check the base64 encoding/values here

Upvotes: 1

Related Questions