Summary
Gophish versions up to and including 0.12.1 expose each administrator's long-lived API key directly in the HTML/JavaScript of the admin dashboard after login.
Any script executing in the browser context, including those introduced via XSS or malicious extensions, can access and exfiltrate these permanent API credentials, enabling unauthorized control over the Gophish instance.
Affected context
This vulnerability affects Gophish deployments using the web-based administrative dashboard in versions up to and including 0.12.1.
When an administrator logs in, their long-lived API key is embedded in the rendered page and exposed to the entire browser context.
The issue is particularly relevant in environments where browser security is shared or untrusted (e.g., shared workstations, unmanaged browser plugins, or potential XSS injection points), as it broadens who or what can access these sensitive credentials.
Exploit preconditions
- Attack surface: Browser context of the authenticated Gophish administrative dashboard.
- Required access: Ability to run JavaScript in the victim admin's browser session, which could stem from:
- Existing or future XSS vulnerabilities in Gophish or related domains
- Malicious or compromised browser extensions
- Local workstation compromise or shared-browser misuse
- Social engineering that convinces the admin to execute arbitrary scripts in the console or load untrusted content
- Trigger point: Admin logs in to the Gophish dashboard, causing the application to render the API key in the DOM or JavaScript variables.
- Why exploitation is possible: The system treats the browser environment as trusted and embeds long-lived API credentials in client-side code, creating an unnecessary exposure of secrets to any script with access to the page.
Why this happens
The core issue is a design-level sensitive information exposure problem where server-side secrets are unnecessarily propagated to the client.
Instead of confining API keys to secure server-side storage and using short-lived session tokens or scoped credentials, the application injects permanent API keys into HTML/JavaScript as part of the page rendering process.
This behavior maps to CWE-200: Exposure of Sensitive Information to an Unauthorized Actor and relates to CWE-922: Insecure Storage of Sensitive Information in that sensitive authentication material is stored and delivered in a context where it can be trivially read by arbitrary scripts.
The bug pattern can be abstracted as: "Long-lived credentials used for administrative APIs are embedded in client-side code, assuming the browser and everything running inside it is equally trusted."
Potential impact
- Attackers may obtain long-lived admin API keys and impersonate the administrator.
- Compromised keys can be used to programmatically create, modify, or delete campaigns, templates, and targets.
- Gophish data, including phishing results and target lists, can be exfiltrated via unauthorized API calls.
- The Gophish instance may be abused as part of a broader phishing or social engineering campaign.
- Persistence of unauthorized access, as the keys are long-lived and may remain valid beyond a single session.
General mitigation guidance
Mitigation focuses on limiting where and how high-value credentials are exposed and used:
- Avoid embedding long-lived API keys or other high-privilege secrets in HTML, JavaScript, or other client-side artifacts.
- Prefer server-side session management and short-lived, scoped tokens for browser-based interactions instead of permanent API keys.
- Implement strict separation of concerns between user interface sessions and automation/API credentials; treat API keys as back-end or machine-to-machine secrets.
- Apply least privilege for any tokens that must reach the client, restricting them to minimal scopes and lifetimes necessary for UI functionality.
- Consider additional controls around administrative access, such as dedicated hardened browsers, reduced plugin surfaces, or workstation hardening, to reduce exposure from untrusted scripts.
How teams detect issues like this
Detection approaches generally focus on surfacing secret leakage and validating client-server trust boundaries:
- Use automated scans or content security review tools to search for API keys, tokens, or other credentials in rendered HTML, JavaScript bundles, and browser network traces.
- Incorporate static analysis or linters that flag server-side code paths which serialize sensitive credentials into templates or API responses intended for browsers.
- During code review, explicitly check views, templates, and JSON endpoints for unnecessary inclusion of API keys, secrets, or administrative tokens.
- Implement security policies that treat any client-delivered secret as suspect and require justification and scoping, with automated checks in CI to prevent accidental inclusion.
- Monitor server logs and API usage for anomalous access patterns tied to API keys, which may indicate that credentials have been exposed or reused from unexpected sources.

