security-review-openai
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSecurity Best Practices
安全最佳实践
Overview
概述
This skill provides a description of how to identify the language and frameworks used by the current context, and then to load information from this skill's references directory about the security best practices for this language and or frameworks.
This information, if present, can be used to write new secure by default code, or to passively detect major issues within existing code, or (if requested by the user) provide a vulnerability report and suggest fixes.
本Skill可识别当前场景中使用的语言和框架,并从本Skill的参考目录中加载对应语言及框架的安全最佳实践相关信息。
若存在相关信息,可用于编写默认安全的新代码,或被动检测现有代码中的重大问题,或(在用户请求时)提供漏洞报告并给出修复建议。
Workflow
工作流程
The initial step for this skill is to identify ALL languages and ALL frameworks which you are being asked to use or already exist in the scope of the project you are working in. Focus on the primary core frameworks. Often you will want to identify both frontend and backend languages and frameworks.
Then check this skill's references directory to see if there are any relevant documentation for the language and or frameworks. Make sure you read ALL reference files which relate to the specific framework or language. The format of the filenames is . You should also check if there is a which is agnostic to the framework you may be using.
<language>-<framework>-<stack>-security.md<language>-general-<stack>-security.mdIf working on a web application which includes a frontend and a backend, make sure you have checked for reference documents for BOTH the frontend and backend!
If you are asked to make a web app which will include both a frontend and backend, but the frontend framework is not specified, also check out . It is important that you understand how to secure both the frontend and backend.
javascript-general-web-frontend-security.mdIf no relevant information is available in the skill's references directory, think a little bit about what you know about the language, the framework, and all well known security best practices for it. If you are unsure you can try to search online for documentation on security best practices.
From there it can operate in a few ways.
-
The primary mode is to just use the information to write secure by default code from this point forward. This is useful for starting a new project or when writing new code.
-
The secondary mode is to passively detect vulnerabilities while working in the project and writing code for the user. Critical or very important vulnerabilities or major issues going against security guidance can be flagged and the user can be told about them. This passive mode should focus on the largest impact vulnerabilities and secure defaults.
-
The user can ask for a security report or to improve the security of the codebase. In this case a full report should be produced describe anyways the project fails to follow security best practices guidance. The report should be prioritized and have clear sections of severity and urgency. Then offer to start working on fixes for these issues. See #fixes below.
本Skill的初始步骤是识别所有要求使用的、或已存在于当前项目范围内的语言和框架。重点关注核心主框架。通常需要同时识别前端和后端的语言与框架。
随后检查本Skill的参考目录,查看是否有对应语言及框架的相关文档。请务必阅读所有与特定框架或语言相关的参考文件。文件名格式为 。同时也需检查是否存在与框架无关的通用指南文件 。
<language>-<framework>-<stack>-security.md<language>-general-<stack>-security.md若处理的是包含前端和后端的Web应用,请确保同时检查了前端和后端的参考文档!
若用户要求开发包含前后端的Web应用,但未指定前端框架,也请查阅 。了解如何同时保障前端和后端的安全至关重要。
javascript-general-web-frontend-security.md若参考目录中无相关信息,可结合你所了解的该语言、框架的通用安全最佳实践来处理。若用户要求生成报告,需告知用户暂无具体指导文档(但仍可生成报告或明确检测出严重漏洞)。
之后可通过以下几种方式开展工作:
-
主要模式:使用上述信息编写默认安全的代码。适用于新项目启动或编写新代码的场景。
-
次要模式:在项目开发和为用户编写代码时被动检测漏洞。对于违反安全指南的严重或极高优先级漏洞/重大问题,需标记并告知用户。该被动模式应聚焦于影响范围最大的漏洞和默认安全配置。
-
用户请求安全报告或提升代码库安全性:此时需生成完整报告,说明项目未遵循安全最佳实践的所有情况。报告需按严重程度和紧急程度划分优先级,并设置清晰的章节。随后可主动提出修复这些问题。详见下方#修复建议部分。
Workflow Decision Tree
工作流程决策树
- If the language/framework is unclear, inspect the repo to determine it and list your evidence.
- If matching guidance exists in , load only the relevant files and follow their instructions.
references/ - If no matching guidance exists, consider if you know any well known security best practices for the chosen language and or frameworks, but if asked to generate a report, let the user know that concrete guidance is not available (you can still generate the report or detect for sure critical vulnerabilities)
- 若语言/框架不明确,检查代码仓库以确定,并列出判断依据。
- 若目录中有匹配的指导文档,仅加载相关文件并遵循其说明。
references/ - 若无匹配的指导文档,可结合你所了解的该语言、框架的通用安全最佳实践处理;但如果用户要求生成报告,需告知用户暂无具体指导文档(仍可生成报告或明确检测出严重漏洞)。
Overrides
例外情况
While these references contain the security best practices for languages and frameworks, customers may have cases where they need to bypass or override these practices. Pay attention to specific rules and instructions in the project's documentation and prompt files which may require you to override certain best practices. When overriding a best practice, you MAY report it to the user, but do not fight with them. If a security best practice needs to be bypassed / ignored for some project specific reason, you can also suggest to add documentation about this to the project so it is clear why the best practice is not being followed and to follow that bypass in the future.
尽管参考文档中包含语言和框架的安全最佳实践,但客户可能存在需要绕过或覆盖这些实践的场景。请留意项目文档和提示文件中要求覆盖某些最佳实践的特定规则和说明。当覆盖最佳实践时,可告知用户,但无需与其争执。若因项目特定原因需绕过/忽略某安全最佳实践,可建议在项目中添加相关文档,明确说明不遵循该最佳实践的原因,以便后续统一执行该绕过规则。
Report Format
报告格式
When producing a report, you should write the report as a markdown file in or some other location if provided by the user. You can ask the user where they would like the report to be written to.
security_best_practices_report.mdThe report should have a short executive summary at the top.
The report should be clearly delineated into multiple sections based on severity of the vulnerability. The report should focus on the most critical findings as these have the highest impact for the user. All findings should be noted with an numeric ID to make them easier to reference.
For critical findings include a one sentence impact statement.
Once the report is written, also report it to the user directly, although you may be less verbose. You can offer to explain any of the findings or the reasons behind the security best practices guidance if the user wants more info on any findings.
Important: When referencing code in the report, make sure to find and include line numbers for the code you are referencing.
After you write the report file, summarize the findings to the user.
Also tell the user where the final report was written to
生成报告时,应将报告以Markdown格式写入,或用户指定的其他位置。可询问用户希望将报告保存至何处。
security_best_practices_report.md报告顶部需包含简短的执行摘要。
报告需按漏洞严重程度划分清晰的章节。应优先聚焦最严重的发现,因为这些对用户的影响最大。所有发现需标注数字ID,以便于引用。
对于严重发现,需包含一句影响说明。
报告完成后,需直接向用户汇报(可适当简化内容)。若用户希望了解任何发现或安全最佳实践指导的背后原因,可主动提供解释。
重要提示:在报告中引用代码时,务必找到并包含对应代码的行号。
报告文件编写完成后,需向用户总结发现的问题,并告知用户最终报告的保存位置。
Fixes
修复建议
If you produced a report, let the user read the report and ask to begin performing fixes.
If you passively found a critical finding, notify the user and ask if they would like you to fix this finding.
When producing fixes, focus on fixing a single finding at a time. The fixes should have concise clear comments explaining that the new code is based on the specific security best practice, and perhaps a very short reason why it would be dangerous to not do it in this way.
Always consider if the changes you want to make will impact the functionality of the user's code. Consider if the changes may cause regressions with how the project works currently. It is often the case that insecure code is relied on for other reasons (and this is why insecure code lives on for so long). Avoid breaking the user's project as this may make them not want to apply security fixes in the future. It is better to write a well thought out, well informed by the rest of the project, fix, then a quick slapdash change.
Always follow any normal change or commit flow the user has configured. If making git commits, provide clear commit messages explaining this is to align with security best practices. Try to avoid bunching a number of unrelated findings into a single commit.
Always follow any normal testing flows the user has configured (if any) to confirm that your changes are not introducing regressions. Consider the second order impacts the changes may have and inform the user before making them if there are any.
若已生成报告,需等待用户阅读报告后,再询问是否开始修复。
若被动检测到严重漏洞,需告知用户并询问是否需要修复该问题。
修复时,需一次聚焦于修复一个问题。修复代码中需添加简洁清晰的注释,说明新代码基于特定安全最佳实践,并简要解释不这样做的风险。
始终需考虑你所做的更改是否会影响用户代码的功能,是否可能导致项目现有功能出现回归。不安全的代码往往因其他原因被依赖(这也是不安全代码长期存在的原因)。避免破坏用户的项目,否则用户可能不愿再应用安全修复。相较于仓促的修改,结合项目整体情况精心设计的修复方案更为可取。
始终遵循用户配置的常规变更或提交流程。若进行Git提交,需提供清晰的提交信息,说明该提交是为了对齐安全最佳实践。尽量避免将多个不相关的问题修复合并到一个提交中。
始终遵循用户配置的常规测试流程(若有),以确认你的更改未引入回归问题。需考虑更改可能带来的间接影响,若存在此类影响,需在修改前告知用户。
General Security Advice
通用安全建议
Below is a few bits of secure coding advice that applies to almost any language or framework.
以下是适用于几乎所有语言或框架的安全编码建议。
Avoid Using Incrementing IDs for Public IDs of Resources
避免为资源的公开ID使用递增ID
When assigning an ID for some resource, which will then be used by exposed to the internet, avoid using small auto-incrementing IDs. Use longer, random UUID4 or random hex string instead. This will prevent users from learning the quantity of a resource and being able to guess resource IDs.
为将暴露在互联网上的资源分配ID时,应避免使用小型自动递增ID。建议使用更长的随机UUID4或随机十六进制字符串。这样可防止用户获悉资源数量并猜测资源ID。
A note on TLS
TLS相关说明
While TLS is important for production deployments, most development work will be with TLS disabled or provided by some out-of-scope TLS proxy. Due to this, be very careful about not reporting lack of TLS as a security issue. Also be very careful around use of "secure" cookies. They should only be set if the application will actually be over TLS. If they are set on non-TLS applications (such as when deployed for local dev or testing), it will break the application. You can provide a env or other flag to override setting secure as a way to keep it off until on a TLS production deployment. Additionally avoid recommending HSTS. It is dangerous to use without full understanding of the lasting impacts (can cause major outages and user lockout) and it is not generally recommended for the scope of projects being reviewed by codex.
尽管TLS在生产部署中至关重要,但大多数开发工作会禁用TLS,或由外部TLS代理提供TLS支持。因此,请勿将未启用TLS列为安全问题。同时需谨慎使用“secure”Cookie:仅当应用实际通过TLS运行时才应设置该Cookie。若在非TLS应用(如本地开发或测试环境部署)中设置,会导致应用无法正常运行。可通过环境变量或其他标志来控制是否设置secure Cookie,确保在TLS生产部署前保持禁用状态。此外,不建议使用HSTS:若未完全了解其长期影响(可能导致重大服务中断和用户无法访问),使用HSTS存在风险,且通常不在Codex审查的项目范围内推荐使用。