"""
XSS (跨站脚本) 漏洞知识
"""
from ..base import KnowledgeDocument, KnowledgeCategory
XSS_REFLECTED = KnowledgeDocument(
id="vuln_xss_reflected",
title="Reflected XSS",
category=KnowledgeCategory.VULNERABILITY,
tags=["xss", "reflected", "javascript", "html", "injection"],
severity="high",
cwe_ids=["CWE-79"],
owasp_ids=["A03:2021"],
content="""
反射型XSS:恶意脚本来自当前HTTP请求,服务器将用户输入直接反射到响应中。
## 危险模式
### Python/Flask
```python
# 危险 - 直接返回用户输入
@app.route('/search')
def search():
query = request.args.get('q')
return f"
搜索结果: {query}
"
# 危险 - 禁用自动转义
return render_template_string(user_input)
return Markup(user_input)
```
### JavaScript/Express
```javascript
// 危险
res.send(`Hello ${req.query.name}
`);
res.write(req.body.content);
```
### PHP
```php
// 危险
echo "Hello " . $_GET['name'];
print($_POST['content']);
```
## 攻击载荷
```html