Skip to content
Account takeover Write-up Beginner

Easy Account Takeover via OTP in Response — A Developer’s Oops Moment

The application returned the one-time password (OTP) in the HTTP response to the browser, encrypted with a key and decryption logic that were hardcoded in the frontend JavaScript. An attacker who intercepted the response could decrypt the OTP and log in as the victim, taking over the account.

infosecwriteups.com

Published on infosecwriteups.com

In this blog, I’ll walk you through a real-world scenario where a seemingly harmless feature—OTP-based login—unintentionally opened the door to a serious security flaw. It was like hiding the house key under the doormat: convenient, but dangerously predictable.

Hack-Bat, on infosecwriteups.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The server included the OTP in the HTTP response and relied on client-side encryption whose key and algorithm were exposed in frontend JavaScript.

Impact

An attacker who intercepts the login response could decrypt the OTP and log in as the victim, resulting in account takeover.

What the attacker needed

Ability to intercept the login response; access to frontend JavaScript files

The fix

The OTP should never be sent in the HTTP response, and secrets or encryption keys should never be hardcoded in client-side code.

How it was found

  1. Enter a mobile number to log in and trigger the OTP request.
  2. Observe the server response, which contains the encrypted OTP.
  3. Read the frontend JavaScript files to find the hardcoded decryption key and logic.
  4. Use the decryption function with the encrypted OTP to recover the original OTP.
  5. Log in with the recovered OTP to take over the account.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When you log in with a one-time password (OTP), the server should send that code only to your phone. Here, the server also sent the code back to the browser, scrambled with encryption. But the key to unscramble it was written in the website's own code, which anyone can read. So an attacker who saw the response could unscramble the code and log in as you.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.