From a Hidden Directory to Admin Account Takeover: A Password Reset Story
A production web application left debug mode enabled, so when the password-reset email failed to send, the error page exposed the reset token, session cookies, server file paths and database details for the queried account. Because the tested account was an administrator, an unauthenticated attacker could use the leaked token to set a new admin password and take over the account.
Published on medium.com
Cybersecurity
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.
Context
This is an account of a security assessment of a web application, focused on its authentication flows. The feature at the centre of the story is the password-reset flow: the "forgot password" option that sits next to a login page, takes an email address, generates a reset token and asks the mail server to send a link containing that token to the account owner.
The application was running in production with framework debug mode enabled. That single configuration choice is what turns an ordinary failure into the finding described here. The write-up withholds the identity of the application, the actual token, the cookie values and the server paths.
Setup
The assessment started with routine reconnaissance and directory enumeration against the web application. No special tooling, versions or account privileges are described beyond that: the researcher submitted a known, valid email address belonging to an administrator into the reset form. The account's role matters because the leaked account object carried a "role": "admin" flag, which is what raised the practical severity to critical.
In this case the application could not reach its mail server, so the attempt to send the reset email failed, and debug mode was enabled in production, so the failure was rendered to the client rather than handled quietly.
Finding it
Early recon turned up a directory that was not linked anywhere obvious on the site. Poking around it led to a login page, which, like most login pages, had a "forgot password" option next to it.
The researcher's reasoning is worth restating because it is the reason the bug was found at all: password-reset flows sit right at the edge of the authentication boundary, and they get less scrutiny than the login form itself. So the reset form was tested directly.
A known, valid email address was submitted into the reset form and the response was observed. Instead of the expected "check your email" message, the application briefly stumbled: it tried to reach its mail server to send the reset email, and that connection failed. Most applications would catch that failure quietly and show a generic error. This one did not. Because debug mode was left enabled on the production server, the failure surfaced as a full framework stack trace rendered directly in the browser, to an unauthenticated request.
The stack trace contained:
- the password-reset token itself, generated moments earlier for the account that had been queried;
- the account's live session and CSRF cookie values;
- the absolute server file path, exposing the hosting account's internal directory structure;
- a dump of internal database information tied to the account, exposing more than just the account's own data.
The account object in that dump carried "role": "admin", and the email address that had been tested happened to belong to an administrator.
Exploitation
Step 1: Reach the hidden login page and its reset form
Directory enumeration surfaced a directory that was not linked from anywhere obvious on the site. Inside it was a login page with a "forgot password" option. No request or response is reproduced for this step in the write-up.
Step 2: Submit a valid administrator email address
The reset form was submitted with a known, valid email address belonging to an administrator. The application attempted to send the reset email, the connection to its mail server failed, and, because debug mode was enabled, the framework stack trace was returned in the browser to the unauthenticated request.
Step 3: Harvest the reset token from the stack trace
The stack trace contained the reset token generated moments earlier for the queried account, along with the account's live session and CSRF cookie values, the absolute server file path and a dump of internal database information. The account object showed "role": "admin".
Step 4: Redeem the token through the application's own reset page
A leaked token is only as dangerous as what it can actually do, so the researcher tested it the way an attacker would: the token was taken straight from the debug output and submitted through the application's own password-reset page. The application accepted it and allowed a new password to be set for the admin account. No access to the email inbox was required, and no authentication was needed at any point in the chain.
From an unauthenticated starting point, a single misconfigured error handler led directly to full administrative control of the application.
Root cause
The mistake is a combination of two things. First, debug mode was left enabled on the production server, so an unhandled exception was rendered to the client as a full framework stack trace instead of being caught and replaced with a generic error. Second, the stack trace rendered by the debug mode contained sensitive material: the reset token, the live session and CSRF cookie values, the absolute file path and internal database information. The failure of the mail server connection was the trigger that pushed that material into the response.
Existing defences did not stop it because the error path bypassed the normal handling: the request was unauthenticated, the token was valid by design, and the reset page accepted it exactly as it would accept a token delivered by email. The write-up does not describe any additional control that should have caught the leak.
Impact
The practical severity was as high as it gets, because the account in question was an administrator. The concrete consequences described are:
- Account takeover: the reset token bypassed email-based verification entirely, allowing a new password to be set on the admin account.
- Session hijacking potential: the exposed cookies could have been reused to impersonate an active session.
- Infrastructure mapping: the leaked file path revealed the server's directory layout and hosting username. On its own this is informational, but combined with any secondary vulnerability it significantly lowers the bar for escalation, for example toward remote code execution or a persistent backdoor.
The exposure was reachable by anyone who could trigger the same error condition. Because of the infrastructure-mapping concern, the researcher recommended a follow-up file-integrity check as part of remediation, to rule out any tampering during the window in which the exposure was live.
Fix
The finding was reported immediately and remediation followed fast:
- Debug mode was disabled in production (
APP_DEBUG=false). - The application's encryption key was rotated, invalidating existing sessions and any outstanding reset tokens.
- The affected account's password was reset directly, closing the specific exposure.
- Logs containing residual sensitive data were cleared.
The same failure condition was re-tested afterwards to confirm the fix held: the application now returns a generic error with none of the previously exposed data.
Variants to test
- Force dependency failures on other flows. Break the mail server connection, the SMS gateway or any other outbound dependency and watch the response. A positive result is a stack trace or any internal detail rendered to an unauthenticated client instead of a generic error.
- Look for debug mode in production. Trigger an unhandled exception on any endpoint and check whether the framework's debug page appears. A positive result is a full trace with file paths, environment values or request context.
- Check what the exception context carries. On reset, invitation and verification flows, inspect whether tokens, session identifiers or CSRF values appear in error output. A positive result is a token that can be redeemed through the application's own page.
- Enumerate unlinked directories. Look for directories that are not referenced from the site and check what sits behind them, such as login pages and their adjacent reset forms. A positive result is a reachable authentication surface that normal crawling misses.
- Test the edges of a feature. Ask what happens when a feature's dependencies fail, rather than only testing the happy path. A positive result is any behaviour change that leaks state, data or control.
What happened, in plain words
A security researcher was testing a website to see how safe its login system was. While looking around, they found a hidden part of the site that was not linked from any normal page. Behind it was a login page, and next to the login form was a "forgot password" link, the kind you click when you cannot remember your password.
The researcher typed in a known, valid email address, and it happened to belong to an administrator, someone with full control over the site. They expected the site to say "check your email". Instead, the site tried to send that email and failed, because it could not reach its mail server. Normally a website would hide that kind of failure and show a polite error. This one did not. It had a setting called debug mode switched on, which is meant for developers building the site, not for a live public site. With debug mode on, the site showed a long, detailed error message in the browser, and that message contained secrets: a special code that lets someone reset the password, the administrator's login cookies, the location of files on the server, and a chunk of the site's internal database.
The researcher copied the password-reset code out of that error message and used it on the site's own reset page. The site accepted it and let them set a new password for the administrator account. No email was needed, and they never logged in. From a completely anonymous starting point, they had taken over the most powerful account on the site.
This article walks through that story step by step, explaining every technical idea from scratch as it comes up.
Some background ideas first
Before the steps, a few everyday ideas will make the rest easier to follow.
A web application is a program that runs on a server (a computer somewhere in the world) and that you use through your browser. When you type an address or click a button, your browser sends a request to that server, and the server sends back a response, usually a page or some data. Think of it like ordering at a restaurant: you (the browser) ask the kitchen (the server) for a dish, and the kitchen sends it back.
Authentication is simply proving who you are. Logging in with an email and password is authentication. The "authentication boundary" is the line between being a stranger and being a known user. Anything that sits near that line deserves careful checking, because if it can be tricked, a stranger can cross the line.
A password-reset flow is the "forgot password" feature. You give the site your email address, the site creates a special one-time code called a token, and it emails you a link containing that token. When you click the link, the site sees the token, checks it is valid, and lets you choose a new password. The token is like a temporary key that proves you own the email address. It is supposed to reach only you, through your inbox.
A cookie is a small piece of text that a website asks your browser to store and send back with every request. Cookies are how a site remembers that you are logged in. One kind, a session cookie, is like a wristband at an event: show it at the door and you are let in without showing your ticket again. Another kind, a CSRF cookie, is a guard against a trick where a malicious site makes your browser send requests you did not intend. CSRF stands for Cross-Site Request Forgery. If someone steals your cookies, they can often pretend to be you.
A stack trace is the detailed error report a programming framework produces when something goes wrong. It lists the chain of internal steps that led to the failure, often including file names, paths and values the program was handling at the time. To a developer it is a helpful map. To an attacker it is a map too, just of the wrong kind.
Debug mode is a setting that makes a framework show those detailed errors. It is useful while building a site and dangerous on a live site, because it can reveal internals to anyone who triggers an error.
Directory enumeration means guessing and checking names of folders on a website, like trying door handles along a corridor, to find pages that are not linked from the menu. A hidden folder is not necessarily secret; it is just not advertised.
Severity is how serious a finding is. This one was rated Critical, the highest level, because it led to full control of an administrator account.
The setup
The assessment began with routine reconnaissance: looking around the site to understand what it is made of. Part of that was directory enumeration, trying to find folders and pages that were not linked from anywhere obvious.
The researcher then used the password-reset form with a known, valid email address that belonged to an administrator. The account's role matters a great deal here. The leaked information included a field reading "role": "admin", which is what turned a serious bug into a critical one. An administrator can do far more than an ordinary user.
Two things lined up for the whole chain to work. First, the application could not reach its mail server, so the attempt to send the reset email failed. Second, debug mode was switched on in production, meaning on the live public site rather than a private development copy, so the failure was shown to the visitor instead of being handled quietly.
Finding it
Early recon turned up a directory that was not linked anywhere obvious on the site. Poking around it led to a login page, which, like most login pages, had a "forgot password" option next to it.
The researcher's reasoning is worth repeating, because it is the reason the bug was found at all. Password-reset flows sit right at the edge of the authentication boundary, and they get less scrutiny than the login form itself. Everyone tests the login box; fewer people test what happens when the reset feature misbehaves. So the reset form was tested directly.
A known, valid email address was submitted into the reset form, and the response was observed. Instead of the expected "check your email" message, the application briefly stumbled. It tried to reach its mail server to send the reset email, and that connection failed. Most applications would catch that failure quietly and show a generic error. This one did not. Because debug mode was left enabled on the production server, the failure surfaced as a full framework stack trace rendered directly in the browser, to an unauthenticated request, meaning a request from someone who had not logged in at all.
The stack trace contained:
- the password-reset token itself, generated moments earlier for the account that had been queried;
- the account's live session and CSRF cookie values;
- the absolute server file path, exposing the hosting account's internal directory structure;
- a dump of internal database information tied to the account, exposing more than just the account's own data.
The account object in that dump carried "role": "admin", and the email address that had been tested happened to belong to an administrator.
In plain terms: the site meant to send a secret key to the administrator's inbox, but instead printed the key on the screen for anyone to read, along with the administrator's login wristband and a map of the server's insides.
Exploitation
Step 1: Reach the hidden login page and its reset form
Directory enumeration surfaced a directory that was not linked from anywhere obvious on the site. Inside it was a login page with a "forgot password" option. No request or response is reproduced for this step in the write-up.
Why this step matters: the hidden folder was the entrance. If the researcher had only looked at the pages linked in the menu, they would never have found this login page and its reset form. Hidden does not mean safe; it only means less visited.
Step 2: Submit a valid administrator email address
The reset form was submitted with a known, valid email address belonging to an administrator. The application attempted to send the reset email, the connection to its mail server failed, and, because debug mode was enabled, the framework stack trace was returned in the browser to the unauthenticated request.
Why this step matters: the address tested happened to belong to an administrator, which is what made the impact so severe. The failed mail connection was the trigger. Without it, the site would have quietly sent an email and shown nothing interesting. The failure is what opened the door to the detailed error page.
Step 3: Harvest the reset token from the stack trace
The stack trace contained the reset token generated moments earlier for the queried account, along with the account's live session and CSRF cookie values, the absolute server file path and a dump of internal database information. The account object showed "role": "admin".
Why this step matters: this is where the secrets were collected. The reset token is the temporary key that proves ownership of the email address. The session cookie is the wristband that proves you are already logged in. The file path is a map of the server's folders. The database dump is internal information that should never leave the server. All of it was sitting in an error message shown to a stranger.
Step 4: Redeem the token through the application's own reset page
A leaked token is only as dangerous as what it can actually do, so the researcher tested it the way an attacker would: the token was taken straight from the debug output and submitted through the application's own password-reset page. The application accepted it and allowed a new password to be set for the admin account. No access to the email inbox was required, and no authentication was needed at any point in the chain.
Why this step matters: finding a secret is not the same as proving it works. The researcher used the site's own reset page, exactly as a legitimate user would, and the site treated the stolen token as valid. That is the moment the bug became a real account takeover rather than a worrying error message.
From an unauthenticated starting point, a single misconfigured error handler led directly to full administrative control of the application.
Root cause
The mistake is a combination of two things. First, debug mode was left enabled on the production server, so an unhandled exception was rendered to the client as a full framework stack trace instead of being caught and replaced with a generic error. An unhandled exception is simply an error the program did not plan for; "rendered to the client" means it was displayed in the visitor's browser.
Second, the detailed error report contained sensitive material: the reset token, the live session and CSRF cookie values, the absolute file path and internal database information. In other words, the error report was built in a way that included the very secrets the feature was supposed to protect.
The failure of the mail server connection was the trigger that pushed that material into the response. Think of it as a safe that is fine as long as nobody slams the door, combined with a door that, when slammed, pops open and spills its contents onto the pavement.
Existing defences did not stop it because the error path bypassed the normal handling. The request was unauthenticated, the token was valid by design, and the reset page accepted it exactly as it would accept a token delivered by email. The write-up does not describe any additional control that should have caught the leak.
Impact
The practical severity was as high as it gets, because the account in question was an administrator. The concrete consequences described are:
- Account takeover: the reset token bypassed email-based verification entirely, allowing a new password to be set on the admin account. In everyday terms, someone changed the locks on the most important door in the building and kept the new key.
- Session hijacking potential: the exposed cookies could have been reused to impersonate an active session. If the administrator was logged in at the time, a stolen session cookie could let an attacker act as them without ever knowing the password.
- Infrastructure mapping: the leaked file path revealed the server's directory layout and hosting username. On its own this is informational, but combined with any secondary vulnerability it significantly lowers the bar for escalation, for example toward remote code execution or a persistent backdoor. Remote code execution means running your own commands on the server; a backdoor is a way to get back in later without being noticed.
The exposure was reachable by anyone who could trigger the same error condition. Because of the infrastructure-mapping concern, the researcher recommended a follow-up file-integrity check as part of remediation, to rule out any tampering during the window in which the exposure was live. A file-integrity check means comparing the server's files against a known-good copy to see whether anything was quietly changed.
Fix
The finding was reported immediately and remediation followed fast:
- Debug mode was disabled in production (
APP_DEBUG=false). - The application's encryption key was rotated, invalidating existing sessions and any outstanding reset tokens.
- The affected account's password was reset directly, closing the specific exposure.
- Logs containing residual sensitive data were cleared.
Here is the configuration line that was changed:
APP_DEBUG=false
Line by line: APP_DEBUG is the name of a setting that controls whether the application shows detailed debugging information. false means off. With this setting off, the application no longer prints internal error details to visitors.
Rotating the encryption key means replacing the secret the application uses to sign and protect things like sessions and tokens. Once the key changes, old sessions and old reset tokens stop working, which is exactly what you want after they may have leaked. Resetting the affected account's password closes the specific door the attacker walked through. Clearing logs removes leftover copies of the sensitive data.
The same failure condition was re-tested afterwards to confirm the fix held: the application now returns a generic error with none of the previously exposed data.
Variants to test
These are the general lessons to try on other sites, written for someone starting out.
- Force dependency failures on other flows. Break the mail server connection, the SMS gateway or any other outbound dependency and watch the response. A positive result is a stack trace or any internal detail rendered to an unauthenticated client instead of a generic error. In everyday terms: see what the site does when the phone line it depends on is dead.
- Look for debug mode in production. Trigger an unhandled exception on any endpoint and check whether the framework's debug page appears. A positive result is a full trace with file paths, environment values or request context.
- Check what the exception context carries. On reset, invitation and verification flows, inspect whether tokens, session identifiers or CSRF values appear in error output. A positive result is a token that can be redeemed through the application's own page.
- Enumerate unlinked directories. Look for directories that are not referenced from the site and check what sits behind them, such as login pages and their adjacent reset forms. A positive result is a reachable authentication surface that normal crawling misses.
- Test the edges of a feature. Ask what happens when a feature's dependencies fail, rather than only testing the happy path. A positive result is any behaviour change that leaks state, data or control.
Glossary
- Web application: a program running on a server that you use through your browser.
- Server: the computer that stores and runs a website and answers requests from browsers.
- Request: a message your browser sends to a server, for example asking for a page or submitting a form.
- Response: the message the server sends back, such as a page, an error or some data.
- Authentication: the process of proving who you are, usually by logging in.
- Authentication boundary: the line between being an anonymous visitor and a known, logged-in user.
- Password-reset flow: the "forgot password" feature that emails a one-time link so you can choose a new password.
- Token: a temporary code that proves you are allowed to do something, such as reset a password.
- Cookie: a small piece of text a site asks your browser to store and send back with each request.
- Session cookie: a cookie that proves you are already logged in, like a wristband at an event.
- CSRF cookie: a cookie used to stop malicious sites from making your browser send requests you did not intend; CSRF stands for Cross-Site Request Forgery.
- Session hijacking: stealing someone's session cookie so you can act as them without their password.
- Stack trace: a detailed error report listing the internal steps, files and values involved in a failure.
- Debug mode: a setting that makes a framework show detailed error information, useful in development and dangerous in production.
- Production: the live, public version of a site that real users visit.
- Framework: the collection of ready-made code a site is built on, which produces things like error pages.
- Unhandled exception: an error the program did not plan for and did not catch.
- Directory enumeration: trying names of folders and pages on a site to find ones that are not linked publicly.
- Reconnaissance: the early information-gathering phase of a security test.
- Unauthenticated: not logged in; a request from an anonymous visitor.
- Absolute server file path: the full location of a file on the server, such as its folder structure and name.
- Database: the organised store where a site keeps its data, such as user accounts.
- Role: a label on an account that says what it is allowed to do;
adminmeans full control. - Account takeover: gaining control of someone else's account, often by changing its password.
- Severity: how serious a security finding is; here it was rated Critical.
- Remote code execution: an attack that lets someone run their own commands on a server.
- Backdoor: a hidden way to get back into a system later without being noticed.
- Encryption key: a secret value a site uses to protect and sign things like sessions and tokens.
- Key rotation: replacing that secret so old sessions and tokens stop working.
- File-integrity check: comparing a server's files against a known-good copy to detect unauthorised changes.
- Remediation: the fix applied to close a security problem.
- Endpoint: a specific address or function on a server that a request can be sent to.