flawopen.com/क्रॉस-साइट स्क्रिप्टिंग/Javascript

क्रॉस-साइट स्क्रिप्टिंग in Javascript

उच्च CWE-79 Draft — pending review
Language: English Português (Brasil) Español Français Deutsch Русский 简体中文 日本語 हिन्दी 한국어 Bahasa Indonesia
सरल व्याख्या (ELI5)

Imagine a guestbook where a visitor writes a note containing hidden script tags that execute in the browser of the next person who opens the page.

इस पृष्ठ पर मुख्य शर्तें
output encoding
Converting special markup characters into safe entities so browsers display them as text rather than script.

क्या हो रहा है

Cross-site scripting happens when untrusted user input is inserted into the DOM without proper HTML output encoding.

वास्तविक दुनिया का प्रभाव

In 2005, the Samy XSS worm infected over 1 million user profiles on MySpace in under 20 hours, forcing the platform offline.

Documented historical AppSec case study.

असुरक्षित बनाम सुरक्षित कोड

VULNERABLE
// comment text parsed directly as HTML
function renderComment(el, comment) {
  el.innerHTML =
    `

${comment}

`; }
FIXED
// comment text inserted as safe plain text
function renderComment(el, comment) {
  const p = document.createElement('p');
  p.textContent = comment;
  el.appendChild(p);
}

समाधान कैसे काम करता है

textContent inserts values strictly as plain text, preventing the browser from parsing markup into executable elements.

भाषा-विशिष्ट सावधानियां

React dangerouslySetInnerHTML

Explicitly disables React auto-escaping. Must be paired with DOMPurify if used.

आम गलतफहमियां

"Frameworks prevent all XSS"

Template escape hatches and direct DOM APIs (innerHTML, outerHTML) bypass framework defenses.

प्रभावित होने की जांच कैसे करें

grep -rn "\.innerHTML\s*=" --include="*.js" --include="*.ts" . grep -rn "dangerouslySetInnerHTML" --include="*.jsx" --include="*.tsx" .
Configure ESLint rule react/no-danger and DOMPurify for cases where HTML formatting is genuinely required.

रोकथाम चेकलिस्ट

अक्सर पूछे जाने वाले प्रश्न

Does Content Security Policy (CSP) replace escaping?

No. CSP provides defense-in-depth, but output encoding remains the primary defense.

संदर्भ

इस भाषा में देखें: Javascript Python JavaScript Java Go PHP C# Rust
यह भी देखें: SQL Injection Command InjectionPath Traversal