使用 GitHub Copilot 进行软件开发
Thalia Barrera
AI Engineering Curriculum Manager, DataCamp

def get_user(username):
query = f"SELECT * FROM users \
WHERE username = '{username}'"
return db.execute(query)
攻击者可注入 SQL:
users 表[录屏]
[录屏]
定向审查
检查
#selection是否存在 SQL 注入和 XSS 漏洞
全仓扫描
用
@workspace扫描硬编码凭据或 API 密钥
[录屏]

防御式代码生成
为此端点添加输入校验。拒绝异常类型并限制长度。
别只会发现漏洞——还要预防它们
.github/copilot-instructions.md
## Security standards
- Use parameterized queries
- Never hardcode credentials or API keys
- Validate and sanitize all user input
- Use bcrypt or argon2 for password hashing
.github/instructions/security.instructions.md
applyTo: "**/*.py"
- Use secrets module instead of random for tokens
- Escape all user input in Jinja2 templates
✅ 将安全变成你写代码的方式的一部分
使用 GitHub Copilot 进行软件开发