skills/secure-code-review/SKILL.md
安全代码审查的专业技能和方法论
npx skillsauth add ed1s0nz/cyberstrikeai secure-code-reviewInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
安全代码审查是识别代码中安全漏洞的重要方法。本技能提供安全代码审查的方法、工具和最佳实践。
检查项目:
检查项目:
检查项目:
检查项目:
使用SAST工具:
# SonarQube
sonar-scanner
# Checkmarx
# 使用Web界面
# Fortify
sourceanalyzer -b project build.sh
sourceanalyzer -b project -scan
# Semgrep
semgrep --config=auto .
审查清单:
危险函数:
# Python危险函数
eval()
exec()
pickle.loads()
os.system()
subprocess.call()
// Java危险函数
Runtime.exec()
ProcessBuilder()
Class.forName()
// PHP危险函数
eval()
exec()
system()
passthru()
危险代码:
String query = "SELECT * FROM users WHERE id = " + userId;
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
安全代码:
String query = "SELECT * FROM users WHERE id = ?";
PreparedStatement stmt = connection.prepareStatement(query);
stmt.setInt(1, userId);
ResultSet rs = stmt.executeQuery();
危险代码:
document.innerHTML = userInput;
element.innerHTML = "<div>" + userInput + "</div>";
安全代码:
element.textContent = userInput;
element.setAttribute("data-value", userInput);
// 或使用编码库
element.innerHTML = escapeHtml(userInput);
危险代码:
import os
os.system("ping " + user_input)
安全代码:
import subprocess
subprocess.run(["ping", "-c", "1", validated_input])
危险代码:
String filePath = "/uploads/" + fileName;
File file = new File(filePath);
安全代码:
String basePath = "/uploads/";
String fileName = Paths.get(fileName).getFileName().toString();
String filePath = basePath + fileName;
File file = new File(filePath);
if (!file.getCanonicalPath().startsWith(basePath)) {
throw new SecurityException("Invalid path");
}
危险代码:
String apiKey = "1234567890abcdef";
String password = "admin123";
安全代码:
String apiKey = System.getenv("API_KEY");
String password = keyStore.getPassword("db_password");
# 启动SonarQube
docker run -d -p 9000:9000 sonarqube
# 运行扫描
sonar-scanner \
-Dsonar.projectKey=myproject \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000
# 安装
pip install semgrep
# 运行扫描
semgrep --config=auto .
# 使用规则
semgrep --config=p/security-audit .
# 创建数据库
codeql database create database --language=java --source-root=.
# 运行查询
codeql database analyze database security-and-quality.qls --format=sarif-latest
tools
满配示例技能包:SKILL.md + scripts/、references/、assets/ 等可选目录;验证 Eino skill 与 HTTP 包内路径(仅授权安全测试与教学)。
testing
XXE XML外部实体注入测试的专业技能和方法论
testing
XSS跨站脚本攻击测试的专业技能
testing
XPath注入漏洞测试的专业技能和方法论