InnerWeb
Skip to main content

How to check that a QR pass code is a random token

A QR pass is only as secure as the string encoded in it is hard to guess. The purchasing or IT department can check this without access to the source code, if it asks the supplier the right questions and runs a few simple tests on a sample of printed codes.

256 bits
of randomness in the badge token
Source: feature card
20
minimum sample of codes for review
Source: guide recommendation

Why a sequence number in the code is a risk

If the code on a pass is another number, for example one increasing by one, a person who knows one valid pass can guess the others. In application security this is called a guessable identifier weakness: access control relies on someone not knowing the address, not on them having no right to it.

A random token closes this path. In InnerWeb the QR badge token is generated only from 32 random bytes of a cryptographic generator. This gives 64 hexadecimal characters, that is 256 bits, and no counter, personal number or date goes into the token. The steps below show how to check this property with any supplier.

Step 1: collect a sample of codes and read their content

Ask the supplier for at least twenty printed test badges issued within a short interval, preferably for different people. Read each code with a scanner or with an application that shows the content without opening the address, and record the full string of characters in a spreadsheet.

A code in InnerWeb encodes the address of the system instance with the token in the form of the /q/ path and a random string. The same address goes into the invitation e-mail and onto the guard's label print. What matters is the ending after the slash: its length, character set and variability.

  • Record each string in a separate row of the spreadsheet.
  • Count the length of each string: it should be constant.
  • Check the character set: for a hexadecimal token only digits and the letters a to f.

Strength of an identifier by length and type

Strength of an identifier by length and typeBar chart: 6 digits about 20 bits, 8 digits 27 bits, 16 hexadecimal characters 64 bits, 64 hexadecimal characters 256 bits.0100200300bits6 digits: 20 bits20 bits6 digits8 digits: 27 bits27 bits8 digits16 hex characters: 64 bits64 bits16 hex characters64 hex characters: 256 bits256 bits64 hex characters
Source: Calculation: the number of bits is the binary logarithm of the number of possible values, rounded; 64 hexadecimal characters result from 32 random bytes

Step 2: look for patterns

Sort the strings and compare neighbours. If they differ only in their last characters or grow by a constant value, it is not a random token. Also check whether the beginning of the string does not contain a date, a person number, a plant number or a fixed prefix outside the expected address scheme.

Twenty samples do not prove randomness, but they are enough to detect the most common errors: a counter, a date, a hash of a person number and a short string. Proof comes only from a description of the generator and the result of the supplier's code review.

What the length of the token means

The number of possible values grows exponentially with the length. A six-digit number is about 20 bits, an eight-digit one about 27, a sixteen-character hexadecimal string 64 bits, and a 64-character string 256 bits. The shorter the token, the easier it is to guess or to scan in bulk.

Step 3: check that the public address does not reveal validity

A random token is only half of the protection. The other half is what the system answers to a query about any token. If a valid, a revoked and an invented code give different answers, an attacker can check subsequent strings as if using a search engine.

In InnerWeb the public address with the token does not check the token: a valid, a revoked and an invented string of the right shape produce the same process and a redirect of the same form. At the gate there is one message "unknown code" for a code that is unknown, revoked or invented. Run an analogous test with the supplier: scan an active code, a revoked code and an invented string of the same length, then compare the server responses.

Step 4: ask about revocation and history

A token is safe as long as it can be disabled quickly. Ask whether after revocation the old code stays in the history or is overwritten. In InnerWeb revocation does not overwrite the old row: the system issues a new token and the old one stays in the history as revoked.

Also ask whether the security panel discloses the value of the token. In InnerWeb the token is not returned in any API response of the security panel, and the panel receives only derived facts, such as whether the person has an active badge and when it was printed. This limits the leak of the token through the browser or a screenshot of the panel.

What to keep as audit evidence

The verification should leave a short protocol: date, number of samples, result of the comparison, result of the test of three queries (active, revoked, invented), and the supplier's answers to questions about the generator and revocation. Such a document is useful at system acceptance and in an information security audit.

The document supports meeting audit requirements, but does not replace a code review or a penetration test, if the plant requires one under its security policy.

Checklist

Video

Frequently asked questions

Does a sample of twenty prove randomness?

No. It is enough to detect a counter, a date or a short string, but the proof is the description of the cryptographic generator and the supplier's confirmation.

Is it safe to scan someone else's code with a phone?

Run the tests on your own test badges. In InnerWeb the public address with the token does not check the token, so it does not reveal whether the code is valid.

Does the same test work for encrypted cards?

Partly. For cards the questions concern the keys and the medium technology, not the token in the address. The check of revocation and of the response to an unknown identifier remains the same.

Sources

Let's verify the token together with your IT department

We will prepare a sample of test badges and show what the response looks like for an active, a revoked and an invented code.

Let's talk