/g The Contract Codex ← 返回动态 Catalog

Unsafe innerHTML XSS Fix

Find and fix XSS caused by unsafe innerHTML rendering while preserving the user-visible text and adding a regression guard.

难度:advanced 分类:security-appsec 来源:GitHub Copilot Cookbook

完整 Prompt(可直接复制)

/goal
GOAL:
Complete Unsafe innerHTML XSS Fix for an application with security-sensitive code paths: Find and fix XSS caused by unsafe innerHTML rendering while preserving the user-visible text and adding a regression guard.

CONTEXT:
- Before editing, read the nearest AGENTS.md/CLAUDE.md, current issue or PLAN.md, and any failing logs already in the repo.
- Inspect auth, input handling, rendering, upload, and boundary tests.
- Establish a baseline by running or locating evidence for: `unsafe sink replaced, security or DOM test added, no sanitizer bypass, and UI output preserved`.

CONSTRAINTS:
- Keep the scope limited to this goal; do not expand into unrelated cleanup.
- Do not weaken tests, delete assertions, or mask errors to make verification pass.
- Respect the repository's AGENTS.md/CLAUDE.md instructions and existing patterns.
- Do not bypass authentication, authorization, validation, or audit checks.
- Do not use eval, unsafe HTML injection, shell string concatenation, or string-built SQL.

DONE WHEN:
- The implementation or documentation directly satisfies: Find and fix XSS caused by unsafe innerHTML rendering while preserving the user-visible text and adding a regression guard.
- The verification command or evidence path succeeds: `unsafe sink replaced, security or DOM test added, no sanitizer bypass, and UI output preserved`.
- The final diff is scoped to the relevant files and has no unrelated formatting churn.

VERIFY:
- Run `unsafe sink replaced, security or DOM test added, no sanitizer bypass, and UI output preserved` or the closest repo-local equivalent if the exact command is not available.
- Capture before/after evidence for the behavior, metric, report, or artifact involved.
- If verification cannot run locally, stop and report the missing dependency instead of guessing success.

OUTPUT:
- Summarize changed files, key decisions, verification output, and remaining risks.
- Include any follow-up that is required for production rollout or human review.

STOP RULES:
- Pause if secrets, production access, stakeholder decisions, or destructive data operations are required.
- Pause after three failed fix attempts on the same symptom and challenge the root-cause hypothesis.
- Do not mark the goal complete until the current repository state has been audited against DONE WHEN.

来源与证据

原始来源: GitHub Copilot Cookbook

证据摘要: innerHTML = `Showing results for "${name}"`; source: GitHub Copilot Cookbook; type: official-agent-task; verification: unsafe sink replaced, security or DOM test added, no sanitizer bypass, and UI output preserved