-
Notifications
You must be signed in to change notification settings - Fork 5
Semgrep files #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Semgrep files #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
files: | ||
include: | ||
- "**/*.yml" | ||
- "**/*.yaml" | ||
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||||||||||||||||||||
import os | ||||||||||||||||||||||||||||
import sys | ||||||||||||||||||||||||||||
import hashlib | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# Hardcoded credentials | ||||||||||||||||||||||||||||
USERNAME = "admin" | ||||||||||||||||||||||||||||
PASSWORD = "secret123" | ||||||||||||||||||||||||||||
Comment on lines
+6
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical security issue: Hardcoded credentials detected. Hardcoded credentials pose a significant security risk as they can be easily discovered in source code and cannot be rotated without code changes. -USERNAME = "admin"
-PASSWORD = "secret123"
+# Use environment variables or secure configuration management
+USERNAME = os.getenv("APP_USERNAME")
+PASSWORD = os.getenv("APP_PASSWORD") 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def dangerous_eval(): | ||||||||||||||||||||||||||||
user_input = input("Enter a Python expression: ") | ||||||||||||||||||||||||||||
result = eval(user_input) | ||||||||||||||||||||||||||||
print("Evaluated result:", result) | ||||||||||||||||||||||||||||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical security vulnerability: Code injection via eval(). Using -def dangerous_eval():
- user_input = input("Enter a Python expression: ")
- result = eval(user_input)
- print("Evaluated result:", result)
+def safe_calculation():
+ try:
+ user_input = input("Enter a mathematical expression: ")
+ # Use ast.literal_eval() for safe evaluation of literals only
+ # or implement a proper expression parser
+ result = ast.literal_eval(user_input)
+ print("Evaluated result:", result)
+ except (ValueError, SyntaxError) as e:
+ print("Invalid input:", e) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def delete_data(path): | ||||||||||||||||||||||||||||
os.system("rm -rf " + path) # Semgrep: shell injection | ||||||||||||||||||||||||||||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical security vulnerability: Shell injection detected. Direct concatenation of user input into shell commands allows command injection attacks. -def delete_data(path):
- os.system("rm -rf " + path) # Semgrep: shell injection
+def delete_data(path):
+ import shutil
+ # Validate and sanitize the path
+ if os.path.exists(path) and os.path.abspath(path).startswith('/safe/directory/'):
+ shutil.rmtree(path)
+ else:
+ raise ValueError("Invalid or unsafe path") 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def hash_password(password): | ||||||||||||||||||||||||||||
hashed = hashlib.md5(password.encode()).hexdigest() # Semgrep: weak hash | ||||||||||||||||||||||||||||
return hashed | ||||||||||||||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security issue: Weak cryptographic hashing algorithm. MD5 is cryptographically broken and should not be used for password hashing. Use a proper password hashing library instead. -def hash_password(password):
- hashed = hashlib.md5(password.encode()).hexdigest() # Semgrep: weak hash
- return hashed
+def hash_password(password):
+ import bcrypt
+ # Use bcrypt for secure password hashing
+ salt = bcrypt.gensalt()
+ hashed = bcrypt.hashpw(password.encode('utf-8'), salt)
+ return hashed 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def main(): | ||||||||||||||||||||||||||||
print("Logging in as", USERNAME) | ||||||||||||||||||||||||||||
password_hash = hash_password(PASSWORD) | ||||||||||||||||||||||||||||
print("Password hash:", password_hash) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if len(sys.argv) > 1: | ||||||||||||||||||||||||||||
delete_data(sys.argv[1]) | ||||||||||||||||||||||||||||
Comment on lines
+26
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security issue: Unsafe command line argument handling. Directly passing command line arguments to potentially dangerous functions without validation creates security risks. - if len(sys.argv) > 1:
- delete_data(sys.argv[1])
+ if len(sys.argv) > 1:
+ path = sys.argv[1]
+ # Validate the path before processing
+ if validate_path(path):
+ delete_data(path)
+ else:
+ print("Error: Invalid path provided")
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
dangerous_eval() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
main() | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding proper entry point protection. The script executes immediately when imported, which can cause issues in testing or when used as a module. -main()
+if __name__ == "__main__":
+ main() 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
rules: | ||||||||||||||||||||||||||||||||||||||||||||||||||
- id: hardcoded-password | ||||||||||||||||||||||||||||||||||||||||||||||||||
pattern: password = "$SECRET" | ||||||||||||||||||||||||||||||||||||||||||||||||||
message: "Avoid hardcoded passwords" | ||||||||||||||||||||||||||||||||||||||||||||||||||
severity: ERROR | ||||||||||||||||||||||||||||||||||||||||||||||||||
languages: [python] | ||||||||||||||||||||||||||||||||||||||||||||||||||
metadata: | ||||||||||||||||||||||||||||||||||||||||||||||||||
category: security | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+1
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve the hardcoded password detection pattern The current pattern rules:
- id: hardcoded-password
- pattern: password = "$SECRET"
+ patterns:
+ - pattern-either:
+ - pattern: $VAR = "..."
+ - pattern: $VAR = '...'
+ - metavariable-regex:
+ metavariable: $VAR
+ regex: '(?i)(password|passwd|pwd|pass|secret|api_key|apikey|auth|token)(_|$)'
+ - pattern-not: $VAR = None
+ - pattern-not: $VAR = ""
message: "Avoid hardcoded passwords"
severity: ERROR
languages: [python]
metadata:
category: security This enhanced pattern will catch various forms of hardcoded credentials including the ones in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid CodeRabbit configuration structure
The
files
property is not a valid top-level configuration option according to the CodeRabbit schema. Valid top-level properties includelanguage
,tone_instructions
,early_access
,enable_free_tier
,reviews
,chat
,knowledge_base
, andcode_generation
.If you're trying to configure file filtering for reviews, use the
reviews.path_filters
property instead:🤖 Prompt for AI Agents