סקיל Security Best Practices
security-best-practices הוא סקיל רשמי של OpenAI שמבצע סקירות אבטחה ספציפיות לשפה ול-framework, ומציע שיפורים. הוא מזהה את כל השפות והפריימוורקים בפרויקט, טוען הנחיות אבטחה רלוונטיות מתוך ספריית הייחוס שלו, ופועל בשלושה מצבים: כתיבת קוד מאובטח-כברירת-מחדל, זיהוי פסיבי של פגיעויות תוך כדי עבודה, או הפקת דוח אבטחה מלא עם דירוג חומרה והצעות תיקון. הוא מקפיד לתקן בזהירות בלי לשבור את הפרויקט. בפרויקטי הפיתוח שאני מוביל, אבטחה מובנית מההתחלה זולה בהרבה מתיקון פרצה אחרי שעלתה לאוויר. במדריך תקבלו את כל ההנחיות, ארבעה תרחישי שימוש, וצ'קליסט איכות.
פקודת התקנה
npx skills add openai/skills@security-best-practices -g -y
ההתקנה מתבצעת דרך מנהל החבילות הרשמי של הסקילים בפקודה אחת. זהו סקיל רשמי של OpenAI, קובץ Markdown פתוח מהמאגר שלהם, ומופעל כשמבקשים סקירת אבטחה או קוד מאובטח. אפשר להוריד ולבדוק את הקוד דרך הכפתורים שבראש העמוד.
מה הסקיל כולל?
הסקיל מתעד סקירת אבטחה לפי שפה ו-framework: זיהוי הסטאק, טעינת הנחיות ייחוס, כתיבת קוד מאובטח-כברירת-מחדל, זיהוי פסיבי של פגיעויות, ודוח אבטחה מדורג עם תיקונים.
קוד הסקיל המלא
---
name: "security-best-practices"
description: "Perform language and framework specific security best-practice reviews and suggest improvements. Trigger only when the user explicitly requests security best practices guidance, a security review/report, or secure-by-default coding help. Trigger only for supported languages (python, javascript/typescript, go). Do not trigger for general code review, debugging, or non-security tasks."
---
# Security 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.
## 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 `<language>-<framework>-<stack>-security.md`. You should also check if there is a `<language>-general-<stack>-security.md` which is agnostic to the framework you may be using.
If 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 `javascript-general-web-frontend-security.md`. It is important that you understand how to secure both the frontend and backend.
If 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.
1. 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.
2. 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.
3. 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.
## Workflow Decision Tree
- If the language/framework is unclear, inspect the repo to determine it and list your evidence.
- If matching guidance exists in `references/`, load only the relevant files and follow their instructions.
- 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)
# 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 `security_best_practices_report.md` or some other location if provided by the user. You can ask the user where they would like the report to be written to.
The 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
# 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.
# 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
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.
### A note on 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.
מה זה security-best-practices ולמה הסקיל הזה שונה?
security-best-practices פותר בעיה יקרה: אבטחה נדחקת לסוף, ופרצות מתגלות רק אחרי שהקוד בייצור. סקירה ידנית דורשת מומחיות, וכלים גנריים מפספסים את ההקשר של השפה והפריימוורק. הסקיל מביא הנחיות אבטחה ספציפיות לסטאק שלכם, ומשלב אותן בעבודה היומיומית.
מה שמייחד אותו הוא ההתאמה לשפה ול-framework. הסקיל לא מחיל כללים גנריים, אלא מזהה את הסטאק, טוען הנחיות ייחוס רלוונטיות לפרונטאנד ולבקאנד, ומיישם אותן. הוא פועל בשלושה מצבים: כתיבת קוד מאובטח מההתחלה, זיהוי פסיבי של פגיעויות חמורות תוך כדי עבודה, או הפקת דוח אבטחה מלא עם דירוג חומרה, מזהי ממצא, והצעות תיקון. כך אבטחה הופכת לחלק טבעי מהפיתוח, לא למשימה נפרדת.
ההבדל מורגש ברמת האבטחה. במקום קוד פגיע שמחכה לתקלה, מקבלים קוד מאובטח-כברירת-מחדל. בשילוב עם סקיל diagnosing-bugs לאיתור בעיות, אפשר לחזק גם את האבטחה וגם את היציבות, וזה צירוף חזק לקוד אמין.
מה security-best-practices נותן לקלוד קוד?
הסקיל מוסיף לקלוד מומחיות אבטחה לפי סטאק: זיהוי השפה והפריימוורק, הנחיות ייחוס, קוד מאובטח-כברירת-מחדל, וזיהוי פגיעויות עם דוח מדורג.
זיהוי הסטאק והנחיות
הסקיל מזהה את כל השפות והפריימוורקים בפרויקט, פרונטאנד ובקאנד, וטוען מספריית הייחוס שלו הנחיות אבטחה רלוונטיות לכל אחד. כך הסקירה מותאמת לטכנולוגיה האמיתית של הפרויקט, ולא כללים גנריים שמפספסים את ההקשר.
קוד מאובטח כברירת מחדל
המצב המרכזי הוא כתיבת קוד מאובטח מההתחלה. כשבונים פרויקט חדש או מוסיפים קוד, הסקיל מיישם את ההנחיות כך שהקוד מאובטח-כברירת-מחדל. זה זול ובטוח בהרבה מתיקון פרצה אחרי שהיא כבר נכנסה למערכת.
דוח אבטחה מדורג
כשמבקשים, הסקיל מפיק דוח אבטחה מלא: תקציר מנהלים, ממצאים מחולקים לפי חומרה, מזהי ממצא, ומשפט השפעה לכל ממצא קריטי, כולל מספרי שורות. כך מקבלים תמונה ברורה וממוקדת של מה הכי דחוף לתקן.
תיקון זהיר בלי רגרסיות
הסקיל מתקן ממצא אחד בכל פעם, עם הסבר קצר למה התיקון חשוב, ושוקל את ההשפעה על תפקוד הקוד הקיים. הוא נמנע משבירת הפרויקט ועוקב אחר תהליך ה-commit והבדיקות שלכם, כך שתיקוני אבטחה לא יוצרים תקלות חדשות.
ארבע היכולות הופכות את קלוד ליועץ אבטחה צמוד. בעבודות שלי, קוד מאובטח-כברירת-מחדל וזיהוי פגיעויות מוקדם חסכו טיפול יקר בפרצות אחרי עלייה לאוויר.
למי הסקיל הזה מתאים?
מפתחים שבונים אפליקציות ווב: זה הקהל המובהק. אבטחת פרונטאנד ובקאנד דורשת ידע ספציפי לכל שכבה. הסקיל מביא הנחיות מותאמות לסטאק, כך שהקוד מאובטח-כברירת-מחדל בלי להיות מומחה אבטחה.
צוותים בלי איש אבטחה ייעודי: כשאין מומחה אבטחה בצוות, הסקיל ממלא פער: הוא מזהה פגיעויות ומסביר אותן, כך שכל מפתח יכול לכתוב קוד בטוח יותר ולהבין את הסיכונים.
מי שמכין מערכת לעלייה לייצור: לפני שמשחררים, דוח אבטחה מדורג מראה מה הכי דחוף לתקן. בשילוב עם סקיל systematic-debugging, אפשר לסגור גם פרצות וגם באגים לפני ההשקה.
בוני אוטומציות שמעבדות נתונים: אוטומציה שנוגעת בנתונים רגישים חייבת להיות מאובטחת. גם בעבודות אוטומציה שלי, אבטחה מובנית מההתחלה מונעת דליפות ותקלות בהמשך.
פרילנסרים שמוסרים פרויקטים: קוד מאובטח הוא חלק מאיכות המסירה. הסקיל מאפשר לספק ללקוח פרויקט שעבר סקירת אבטחה ותועד בדוח, מה שמעלה את הערך ואת האמון.
מי שפחות יתאים: הסקיל מתמקד כרגע בשפות נתמכות מסוימות כמו פייתון, ג'אווהסקריפט וגו. מי שעובד בשפה אחרת לגמרי יקבל פחות הנחיות ייחוס ספציפיות, אם כי עדיין יוכל ליהנות מהעקרונות הכלליים.
איך security-best-practices עזר לי בפרויקטים אמיתיים
קוד מאובטח מההתחלה
התחלתי פרויקט חדש והפעלתי את הסקיל. הוא זיהה את השפה והפריימוורק, טען הנחיות מתאימות, וכתב קוד מאובטח-כברירת-מחדל. במקום לתקן פרצות אחר כך, הקוד נבנה בטוח מההתחלה, וזה חסך טיפול יקר בהמשך.
דוח אבטחה שתיעדף את הדחוף
רציתי לדעת היכן הפרויקט חשוף. הסקיל הפיק דוח מדורג לפי חומרה, עם מזהי ממצא ומשפט השפעה לכל ממצא קריטי. ידעתי בדיוק מה לתקן קודם, והתמקדתי בממצאים בעלי ההשפעה הגבוהה ביותר במקום לנחש.
פגיעות שנתפסה תוך כדי עבודה
באמצע פיתוח רגיל, הסקיל זיהה פסיבית פגיעות חמורה בקוד שכתבתי והתריע. תיקנתי אותה במקום, לפני שהמשיכה הלאה. הזיהוי הפסיבי תפס בעיה שהייתי מפספס, בלי שאצטרך לבקש סקירה מפורשת.
תיקון שלא שבר את הפרויקט
חששתי שתיקון אבטחה ישבור פונקציונליות קיימת. הסקיל תיקן ממצא אחד בכל פעם, שקל את ההשפעה על הקוד הקיים, ועקב אחר תהליך הבדיקות שלי. הפרצה נסגרה בלי רגרסיות, והפרויקט המשיך לעבוד כרגיל.
ארבעת המקרים מראים שאבטחה מובנית משנה את התוצאה. כשהקוד מאובטח מההתחלה, פגיעויות נתפסות מוקדם, ותיקונים נעשים בזהירות, מקבלים מערכת בטוחה בלי לשלם את המחיר היקר של פרצה שהתגלתה מאוחר.
סיכום
סקיל security-best-practices הוא כלי רשמי מצוין לכל מי שרוצה קוד מאובטח. הוא מזהה את הסטאק, טוען הנחיות אבטחה ספציפיות, כותב קוד מאובטח-כברירת-מחדל, מזהה פגיעויות תוך כדי עבודה, ומפיק דוח מדורג עם תיקונים זהירים.
אם אתם מתחילים, בפעם הבאה שתכתבו קוד או לפני עלייה לייצור, בקשו מקלוד סקירת אבטחה עם הסקיל. תראו אילו פגיעויות נחשפות ואיך לסגור אותן. משם, אבטחה הופכת לחלק טבעי מהפיתוח.
בפוסטים הבאים אמשיך לסקור את הסקילים החזקים ביותר לאבטחה ולפיתוח. האתר של דביר נעמן מרכז את כל הכלים, השיטות והליווי שאני מציע לעסקים שרוצים נוכחות דיגיטלית מנצחת עם בינה מלאכותית.
שיתוף הסקיל
שאלות ותשובות
מה זה בעצם הסקיל security-best-practices?
זה סקיל רשמי של OpenAI שמבצע סקירות אבטחה ספציפיות לשפה ול-framework. הוא מזהה את הסטאק של הפרויקט, טוען הנחיות אבטחה רלוונטיות, ופועל בשלושה מצבים: כתיבת קוד מאובטח-כברירת-מחדל, זיהוי פסיבי של פגיעויות, או הפקת דוח אבטחה מלא עם דירוג חומרה והצעות תיקון.
במה הסקיל שונה מסקירת אבטחה גנרית?
במקום כללים גנריים, הסקיל מתאים את הסקירה לשפה ולפריימוורק האמיתיים של הפרויקט. הוא טוען הנחיות ייחוס ספציפיות לפרונטאנד ולבקאנד, כך שהוא תופס בעיות בהקשר הנכון. סקירה גנרית מפספסת פגיעויות ספציפיות לטכנולוגיה, והסקיל הזה ממוקד בדיוק בהן.
איך מתקינים את הסקיל בקלוד קוד?
בפקודה אחת דרך מנהל החבילות הרשמי של הסקילים, כפי שמופיע בקופסת ההתקנה למעלה. זהו סקיל רשמי של OpenAI, קובץ Markdown פתוח מהמאגר שלהם. אחרי ההתקנה בקשו סקירת אבטחה או קוד מאובטח, והסקיל יזהה את הסטאק ויפעל בהתאם.
מהם שלושת מצבי הפעולה של הסקיל?
הראשון: כתיבת קוד מאובטח-כברירת-מחדל, שימושי לפרויקט חדש או קוד חדש. השני: זיהוי פסיבי של פגיעויות חמורות תוך כדי עבודה רגילה, עם התרעה למשתמש. השלישי: הפקת דוח אבטחה מלא לפי בקשה, מדורג לפי חומרה עם הצעות תיקון. אפשר להשתמש בכל מצב לפי הצורך.
איך נראה דוח האבטחה שהסקיל מפיק?
הדוח נכתב כקובץ Markdown ומכיל תקציר מנהלים בראש, ואז ממצאים מחולקים לסקשנים לפי חומרה. לכל ממצא יש מזהה מספרי, ולממצאים קריטיים גם משפט השפעה ומספרי שורות. כך קל להבין מה הכי דחוף, להתייחס לכל ממצא בנפרד, ולהתחיל בתיקונים בעלי ההשפעה הגבוהה ביותר.
האם הסקיל יכול לשבור את הקוד כשהוא מתקן?
הסקיל מקפיד לא לשבור את הפרויקט. הוא מתקן ממצא אחד בכל פעם, שוקל את ההשפעה על הקוד הקיים, ועוקב אחר תהליך ה-commit והבדיקות שהגדרתם. לעיתים קוד לא מאובטח נשען עליו קוד אחר, ולכן הסקיל מעדיף תיקון מושכל ובדוק על פני שינוי מהיר שעלול ליצור רגרסיה.
אילו שפות הסקיל תומך בהן?
הסקיל מתמקד בשפות נתמכות עם הנחיות ייחוס מפורטות, כמו פייתון, ג'אווהסקריפט וטייפסקריפט וגו. עבור שפות אלה הוא טוען הנחיות ספציפיות לפריימוורקים. לשפות אחרות הוא עדיין יכול ליישם עקרונות אבטחה כלליים מוכרים, אך עם פחות הנחיות ייחוס ספציפיות לטכנולוגיה.
האם הסקיל מתאים גם למי שאינו מומחה אבטחה?
במיוחד. הסקיל נועד להנגיש אבטחה למפתחים רגילים. הוא מזהה את הסטאק, מיישם הנחיות, ומסביר את הפגיעויות, כך שגם בלי רקע באבטחה אפשר לכתוב קוד בטוח יותר. זה שימושי במיוחד לצוותים בלי איש אבטחה ייעודי, שצריכים להעלות את רמת האבטחה בעצמם.