Exploit databaseDownload repository ZIP
GH-7d3555c60f1701cb78c608defcf27547
abhayclasher/cve-2026-33331
Sources for CVE-2026-33331
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files3
abhayclasher/cve-2026-33331Revision ecd1e1ec0d1a
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
app/server.js
JavaScript · 5,282 bytes// server.js — local lab for CVE-2026-33331
// Two pages:
// /docs — vulnerable (mimics orpc < v1.13.9)
// /docs/safe — patched (uses escapeJsonForHtml)
const express = require('express');
const app = express();
const PORT = 3000;
const spec = {
openapi: '3.1.0',
info: {
title: 'Example API',
version: '1.0.0',
description: 'An example API.</script><script>alert("CVE-2026-33331 — stored XSS executed")</script>',
},
paths: {
'/api/users': {
get: { summary: 'List users', responses: { '200': { description: 'OK' } } },
},
},
};
// Vulnerable: embeds spec with raw JSON.stringify
function renderVuln(s) {
const esc = (str) => str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
const endpoints = Object.entries(s.paths).flatMap(([path, methods]) =>
Object.entries(methods).map(([method, info]) =>
`<code>${method.toUpperCase()} ${path}</code> — ${esc(info.summary || '')}`
)
).join('<br>');
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>${esc(s.info.title)} — API Docs</title>
<style>
body { font-family: system-ui, -apple-system, sans-serif; max-width: 760px; margin: 3rem auto; padding: 0 1.5rem; color: #1a1a2e; }
.badge { display: inline-block; background: #fee2e2; color: #991b1b; padding: 3px 10px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; }
.warn { background: #fef2f2; border-left: 3px solid #dc2626; padding: 12px 16px; margin: 1rem 0; }
code { background: #1e1e2e; color: #cdd6f4; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
pre code { display: block; padding: 16px; overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
</style>
</head>
<body>
<h1>${esc(s.info.title)}</h1>
<span class="badge">VULNERABLE LAB</span>
<div class="warn">
An alert fires on this page — the description field broke out of the script tag.
</div>
<p><strong>${esc(s.info.title)}</strong> v${esc(s.info.version)}</p>
<p>${s.info.description}</p>
<script id="spec" type="application/json">${JSON.stringify(spec)}</script>
<script>
try { JSON.parse(document.getElementById('spec').textContent); console.log('spec loaded'); }
catch (e) { console.log('XSS confirmed:', e.message); }
</script>
<h3>Endpoints</h3>
<p>${endpoints}</p>
<h3>Root cause</h3>
<pre><code><script id="spec">${'${JSON.stringify(spec)}'}</script></code></pre>
<p>JSON.stringify does not encode <code><</code> or <code>></code>.</p>
<p><a href="/docs/safe">Patched version →</a></p>
</body>
</html>`;
}
// Patched: escapeJsonForHtml before embedding
function renderPatched(s) {
const esc = (str) => str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
const escapeJson = (obj) => JSON.stringify(obj)
.replace(/&/g, '\\u0026').replace(/'/g, '\\u0027')
.replace(/</g, '\\u003C').replace(/>/g, '\\u003E').replace(/\//g, '\\u002F');
const endpoints = Object.entries(s.paths).flatMap(([path, methods]) =>
Object.entries(methods).map(([method, info]) =>
`<code>${esc(method.toUpperCase())} ${esc(path)}</code> — ${esc(info.summary || '')}`
)
).join('<br>');
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>${esc(s.info.title)} — API Docs (Patched)</title>
<style>
body { font-family: system-ui, -apple-system, sans-serif; max-width: 760px; margin: 3rem auto; padding: 0 1.5rem; color: #1a1a2e; }
.badge { display: inline-block; background: #dcfce7; color: #166534; padding: 3px 10px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; }
.ok { background: #f0fdf4; border-left: 3px solid #22c55e; padding: 12px 16px; margin: 1rem 0; }
code { background: #1e1e2e; color: #cdd6f4; padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
pre code { display: block; padding: 16px; overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
</style>
</head>
<body>
<h1>${esc(s.info.title)}</h1>
<span class="badge">PATCHED v1.13.9</span>
<div class="ok">No alert fires. The payload is escaped with Unicode and renders as text.</div>
<p><strong>${esc(s.info.title)}</strong> v${esc(s.info.version)}</p>
<p>${esc(s.info.description)}</p>
<script>
const parsed = JSON.parse(${escapeJson(spec)});
console.log('parsed safely:', parsed.info.title);
</script>
<h3>Endpoints</h3>
<p>${endpoints}</p>
<h3>The fix</h3>
<pre><code>JSON.stringify(obj)
.replace(/&/g, '\\\\u0026')
.replace(/</g, '\\\\u003C')
.replace(/>/g, '\\\\u003E')
.replace(/\\//g, '\\\\u002F');</code></pre>
<p><a href="/docs">Vulnerable version →</a></p>
</body>
</html>`;
}
app.get('/docs', (req, res) => res.send(renderVuln(spec)));
app.get('/docs/safe', (req, res) => res.send(renderPatched(spec)));
app.get('/spec.json', (req, res) => res.json(spec));
app.get('/', (req, res) => res.redirect('/docs'));
app.listen(PORT, () => {
console.log(`\n CVE-2026-33331 lab server running`);
console.log(` Vulnerable : http://localhost:${PORT}/docs`);
console.log(` Patched : http://localhost:${PORT}/docs/safe`);
console.log(` Spec JSON : http://localhost:${PORT}/spec.json\n`);
});