Secure code review

Reviewing multi-factor authentication control coverage

Secure implementation: code, settings, gate arranged to illustrate reviewing multi-factor authentication control coverage.

Authentication assurance includes the entire identity lifecycle, not only the primary login prompt. Understanding multi-factor authentication control coverage helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Authentication establishes who is making a request and the strength and freshness of that evidence. Enrolment, recovery, alternate channels and changes to authenticators are part of the same boundary. An impressive login screen provides little assurance if another path grants equivalent access with weaker checks.

Lookup secrets are pre-generated lists of secret codes, similar to Transaction Authorisation Numbers (TAN), social media recovery codes, or a grid containing a set of random values. This type of authentication mechanism is considered "something you have" because the codes are deliberately not memorable so will need to be stored somewhere.

Time based One-time Passwords (TOTPs) are physical or soft tokens that display a continually changing pseudo-random one-time challenge. This type of authentication mechanism is considered "something you have". Multi-factor TOTPs are similar to single-factor TOTPs, but require a valid PIN code, biometric unlocking, USB insertion or NFC pairing, or some additional value (such as transaction signing calculators) to be entered to create the final One-time Password (OTP).

Why it matters

Consider a realistic failure: a strong sign-in journey is bypassed through a weaker enrolment, recovery or alternative authentication path.

Account access can lead to disclosure, unwanted changes or misuse of a trusted identity. The consequence depends on the account's permissions and the actions available after authentication, rather than the appearance of the login mechanism.

A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.

How penetration testers check for it

Review the specific control expectations below against the code, deployment and observable application behaviour.

  • Confirm that lookup secrets, out-of-band authentication requests or codes, and time-based one-time passwords (TOTPs) are only successfully usable once.
  • Verify that, when being stored in the application's backend, lookup secrets with less than 112 bits of entropy (19 random alphanumeric characters or 34 random digits) are hashed with an approved password storage hashing algorithm that incorporates a 32-bit random salt. A standard hash function can be used if the secret has 112 bits of entropy or more.
  • Confirm that lookup secrets, out-of-band authentication code, and time-based one-time password seeds, are generated using a Cryptographically Secure Pseudorandom Number Generator (CSPRNG) to avoid predictable values.
  • Confirm that lookup secrets and out-of-band authentication codes have a minimum of 20 bits of entropy (typically 4 random alphanumeric characters or 6 random digits is sufficient).
  • Confirm that out-of-band authentication requests, codes, or tokens, as well as time-based one-time passwords (TOTPs) have a defined lifetime. Out of band requests must have a maximum lifetime of 10 minutes and for TOTP a maximum lifetime of 30 seconds.
  • Confirm that any authentication factor (including physical devices) can be revoked in case of theft or other loss.
  • Confirm that biometric authentication mechanisms are only used as secondary factors together with either something you have or something you know.
  • Confirm that time-based one-time passwords (TOTPs) are checked based on a time source from a trusted service and not from an untrusted or client provided time.
  • Check expiry, reuse and the binding of challenges to their intended action.
  • Follow successful authentication into the operation that trusts it.

How to fix it

Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.

  • Apply consistent verification at trusted boundaries.
  • Protect enrolment, replacement and recovery as carefully as login.
  • Require appropriate fresh evidence for sensitive changes.
  • Record important authentication events without retaining secrets.

Authentication and authorisation answer different questions. Establishing identity does not grant unrestricted permission to records or privileged functions.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss the security of your application code.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo