Summary
pgAdmin 4 contains a stored cross-site scripting vulnerability where text returned from a PostgreSQL server is rendered as HTML in multiple UI components without sufficient sanitization.
An attacker who controls or can influence server-side object names or error messages can inject arbitrary HTML into the pgAdmin interface, enabling phishing and potential credential theft when a victim connects or views crafted query plans.
Affected context
The vulnerability arises in pgAdmin 4 installations that connect to PostgreSQL servers whose error messages, object identifiers, or EXPLAIN output can be influenced by an attacker.
Affected paths include error toasts, form help and error areas, modal alerts, SQL editor confirmations, and the Explain visualiser, where backend-supplied text was passed directly through html-react-parser into the DOM.
It typically occurs when a user connects pgAdmin to an untrusted or shared database instance, or when low-privilege users can create objects with crafted names that later surface in administrative workflows.
Exploit preconditions
- Attack surface: Browser-based pgAdmin 4 web interface.
- Required access: Ability to control or influence PostgreSQL server text returned to pgAdmin, such as:
- Running a malicious or compromised PostgreSQL instance the victim connects to, or
- Holding low-privilege access on a shared database where crafted table/column/index names, constraints, or other identifiers will appear in errors or EXPLAIN output.
- Trigger point: Victim opens pgAdmin and:
- Connects to the attacker-influenced server, or
- Executes queries, EXPLAINs, or actions that surface crafted error messages or plan-node text in pgAdmin UI components.
- Why exploitation is possible: Backend-derived text is treated as HTML and parsed with
html-react-parserwithout robust sanitization or consistent escaping, allowing attacker-controlled markup (e.g., iframes) to be injected directly into the DOM.
Why this happens
This bug is rooted in rendering untrusted backend text as HTML in a rich client UI without enforcing a strict plain-text contract or robust sanitization.
Multiple React components in pgAdmin 4 used html-react-parser on strings received from PostgreSQL error messages and EXPLAIN metadata, effectively treating them as trusted HTML fragments.
Because these strings could contain attacker-controlled content such as crafted object names, the pattern matches CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), with CWE-116: Improper Encoding or Escaping of Output as a contributing factor.
The insecure pattern is the assumption that server-sent "messages" are safe for HTML rendering, instead of encoding them as plain text or sanitizing them before insertion into the DOM.
Potential impact
- Attackers can inject arbitrary HTML elements into the pgAdmin interface.
- Malicious iframes can render phishing pages that visually mimic pgAdmin dialogs and workflows.
- Users can be tricked into entering credentials or sensitive data into attacker-controlled pages displayed inside the pgAdmin tab.
- The injected content can redirect the top-level pgAdmin browser tab to attacker-controlled URLs, facilitating credential theft or broader account compromise.
- Users' trust in administrative output (errors, EXPLAIN plans, confirmations) can be abused to drive targeted social-engineering attacks.
General mitigation guidance
Effective mitigation focuses on treating all backend-derived text as untrusted and enforcing a strict separation between data and presentation:
- Prefer plain-text rendering contracts for error messages, plan metadata, and server-side messages; encode content so it cannot be interpreted as HTML or script.
- Use context-appropriate escaping on all output derived from database identifiers, error messages, or logs before they reach the UI layer, aligning with HTML escaping rules.
- Where HTML rendering is truly necessary, apply well-maintained sanitization libraries (e.g., DOMPurify-style filters) around every parse or injection point, with a conservative allowlist.
- Introduce UI components that distinguish between trusted HTML and untrusted text (e.g.,
SafeMessagevs.SafeHtmlMessage) and make the safe variant the default. - Reduce privileges and trust in connected database instances; avoid connecting administrative tools to untrusted or user-controlled servers without strong isolation.
- Apply defense-in-depth by sanitizing and escaping at both backend generators and frontend renderers, ensuring external consumers (logs, APIs, dashboards) never see raw markup.
How teams detect issues like this
Teams can identify similar vulnerabilities using layered detection approaches:
- Static analysis and code search:
- Scan for uses of HTML rendering helpers (
html-react-parser,dangerouslySetInnerHTML, or equivalent) that accept unvalidated or unescaped server data. - Flag UI components that render error messages, EXPLAIN output, or object names without explicit encoding or sanitization.
- Code review practices:
- Require reviewers to trace the origin of any string that reaches an HTML sink, verifying encoding and sanitization paths.
- Establish patterns where message rendering must go through safe abstractions (e.g.,
SafeMessagecomponents or escape helpers) and treat bypasses as security issues. - Security testing:
- Fuzz error messages and database object names with harmless HTML markers (e.g., unique tags or attributes) and verify whether they appear interpreted in the DOM.
- Use browser DevTools or automated UI tests to detect unescaped markup in rendered output.
- Policy and tooling:
- Integrate secure coding rules into CI to block unreviewed use of raw HTML rendering APIs.
- Optionally employ SAST/DAST tools capable of tracking tainted data from database responses into client-side HTML sinks.

