Update script.py
Browse files
script.py
CHANGED
|
@@ -84,7 +84,7 @@ print('💪🏆🎉 Pong! Model responded successfully. Use generate("<prompt>")
|
|
| 84 |
def vulnerability_injection(secure_code: str, CWE_vulnerability=None):
|
| 85 |
if CWE_vulnerability is None:
|
| 86 |
## introduce any vulnerability
|
| 87 |
-
prompt =
|
| 88 |
Modify the following secure code to introduce a vulnerability.
|
| 89 |
Secure Code:
|
| 90 |
{secure_code}
|
|
@@ -92,11 +92,9 @@ def vulnerability_injection(secure_code: str, CWE_vulnerability=None):
|
|
| 92 |
Return JSON with keys: '
|
| 93 |
code' (modified vulnerable code) and 'vulnerability' (list of CWE vulnerabilities if vulnerabilities introduced else empty).
|
| 94 |
"""
|
| 95 |
-
)
|
| 96 |
else:
|
| 97 |
## introduce specific vulnerability
|
| 98 |
-
prompt =
|
| 99 |
-
f"""
|
| 100 |
Modify the following secure code to introduce a {CWE_vulnerability} vulnerability.
|
| 101 |
|
| 102 |
Secure Code:
|
|
@@ -106,14 +104,12 @@ def vulnerability_injection(secure_code: str, CWE_vulnerability=None):
|
|
| 106 |
Return JSON with keys: 'code' (modified vulnerable code) and 'vulnerability' (list of CWE if vulnerabilities introduced else empty).
|
| 107 |
|
| 108 |
"""
|
| 109 |
-
)
|
| 110 |
return _model.generate(prompt)
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
def vulnerability_detection(input_code: str):
|
| 115 |
-
prompt =
|
| 116 |
-
f"""
|
| 117 |
Analyze the following code and detect security vulnerabilities.
|
| 118 |
|
| 119 |
Code:
|
|
@@ -123,13 +119,11 @@ def vulnerability_detection(input_code: str):
|
|
| 123 |
Identify potential vulnerabilities that could be introduced. Your task is to assess this script for potential vulnerabilities that could be introduced.
|
| 124 |
Return JSON with key: 'vulnerability' (list of detected CWE vulnerabilities or an empty list if none found).
|
| 125 |
"""
|
| 126 |
-
)
|
| 127 |
return _model.generate(prompt)
|
| 128 |
|
| 129 |
|
| 130 |
def vulnerability_fix(insecure_code: str):
|
| 131 |
-
prompt =
|
| 132 |
-
f"""
|
| 133 |
Fix the security vulnerabilities in the following code.
|
| 134 |
|
| 135 |
Vulnerable Code:
|
|
@@ -138,5 +132,4 @@ def vulnerability_fix(insecure_code: str):
|
|
| 138 |
Your task is to fix the security vulnerabilities in the code.
|
| 139 |
Return JSON with keys: 'code' (secure version) and 'vulnerability' (list of fixed CWE vulnerabilities if any else empty list).
|
| 140 |
"""
|
| 141 |
-
)
|
| 142 |
return _model.generate(prompt)
|
|
|
|
| 84 |
def vulnerability_injection(secure_code: str, CWE_vulnerability=None):
|
| 85 |
if CWE_vulnerability is None:
|
| 86 |
## introduce any vulnerability
|
| 87 |
+
prompt = f"""
|
| 88 |
Modify the following secure code to introduce a vulnerability.
|
| 89 |
Secure Code:
|
| 90 |
{secure_code}
|
|
|
|
| 92 |
Return JSON with keys: '
|
| 93 |
code' (modified vulnerable code) and 'vulnerability' (list of CWE vulnerabilities if vulnerabilities introduced else empty).
|
| 94 |
"""
|
|
|
|
| 95 |
else:
|
| 96 |
## introduce specific vulnerability
|
| 97 |
+
prompt = f"""
|
|
|
|
| 98 |
Modify the following secure code to introduce a {CWE_vulnerability} vulnerability.
|
| 99 |
|
| 100 |
Secure Code:
|
|
|
|
| 104 |
Return JSON with keys: 'code' (modified vulnerable code) and 'vulnerability' (list of CWE if vulnerabilities introduced else empty).
|
| 105 |
|
| 106 |
"""
|
|
|
|
| 107 |
return _model.generate(prompt)
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
def vulnerability_detection(input_code: str):
|
| 112 |
+
prompt = f"""
|
|
|
|
| 113 |
Analyze the following code and detect security vulnerabilities.
|
| 114 |
|
| 115 |
Code:
|
|
|
|
| 119 |
Identify potential vulnerabilities that could be introduced. Your task is to assess this script for potential vulnerabilities that could be introduced.
|
| 120 |
Return JSON with key: 'vulnerability' (list of detected CWE vulnerabilities or an empty list if none found).
|
| 121 |
"""
|
|
|
|
| 122 |
return _model.generate(prompt)
|
| 123 |
|
| 124 |
|
| 125 |
def vulnerability_fix(insecure_code: str):
|
| 126 |
+
prompt = f"""
|
|
|
|
| 127 |
Fix the security vulnerabilities in the following code.
|
| 128 |
|
| 129 |
Vulnerable Code:
|
|
|
|
| 132 |
Your task is to fix the security vulnerabilities in the code.
|
| 133 |
Return JSON with keys: 'code' (secure version) and 'vulnerability' (list of fixed CWE vulnerabilities if any else empty list).
|
| 134 |
"""
|
|
|
|
| 135 |
return _model.generate(prompt)
|