Skip to content

test: showcase semgrep integration and cost calculation#22

Open
ramirobarraco wants to merge 2 commits intomainfrom
test/showcase-semgrep-cost
Open

test: showcase semgrep integration and cost calculation#22
ramirobarraco wants to merge 2 commits intomainfrom
test/showcase-semgrep-cost

Conversation

@ramirobarraco
Copy link
Copy Markdown
Collaborator

Summary

Demo PR to showcase the semgrep integration detecting security vulnerabilities and the cost calculation with Gemini 2.5 Flash.

This file contains intentional vulnerabilities for testing:

  • SQL injection
  • Command injection
  • Hardcoded secrets
  • Insecure deserialization (pickle)
  • Path traversal
  • Arbitrary code execution (exec)

Expected Results

  • Semgrep detects 5+ security findings (posted as separate comment)
  • LLM generates additional review comments for issues semgrep can't catch
  • Cost calculated and displayed (~$0.005/review with Gemini 2.5 Flash)

Test Plan

  • Verify semgrep detects vulnerabilities
  • Verify static analysis posted as separate comment
  • Verify LLM generates additional insights
  • Verify cost calculation displays correctly
  • Close PR after demonstration (do not merge)

WARNING: This PR contains intentionally vulnerable code and should NOT be merged.

🤖 Generated with Claude Code

ramirobarraco and others added 2 commits March 26, 2026 15:41
This file contains intentional security vulnerabilities to demonstrate
the semgrep integration detecting and reporting issues:

- SQL injection (string formatting in queries)
- Command injection (shell=True with user input)
- Hardcoded secrets (API keys and passwords)
- Insecure deserialization (pickle.loads)
- Path traversal (unvalidated user paths)
- Arbitrary code execution (exec with user input)

WARNING: This is for demonstration purposes only.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Semgrep's --config auto skips tests/ directory by default.
Moving the demo file to src/ ensures it gets scanned.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

🔍 Nitpick Senior - Static Analysis

Found 5 issue(s) via static analysis (semgrep):

Severity File Line Rule Message
❌ ERROR src/vulnerable_demo.py 19 python.sqlalchemy.security.sqlalchemy-execute-raw-query.sqlalchemy-execute-raw-query Avoiding SQL string concatenation: untrusted input concatenated with raw SQL query can result in SQL...
❌ ERROR src/vulnerable_demo.py 28 python.lang.security.audit.subprocess-shell-true.subprocess-shell-true Found 'subprocess' function 'run' with 'shell=True'. This is dangerous because this call will spawn ...
⚠️ WARNING src/vulnerable_demo.py 19 python.lang.security.audit.formatted-sql-query.formatted-sql-query Detected possible formatted SQL query. Use parameterized queries instead.
⚠️ WARNING src/vulnerable_demo.py 46 python.lang.security.deserialization.pickle.avoid-pickle Avoid using pickle, which is known to lead to code execution vulnerabilities. When unpickling, the...
⚠️ WARNING src/vulnerable_demo.py 61 python.lang.security.audit.exec-detected.exec-detected Detected the use of exec(). exec() can be dangerous if used to evaluate dynamic content. If this con...

💡 These findings are from automated static analysis. The AI review below focuses on issues requiring human judgment.


🤓 Um, actually... reviewed by Nitpick Senior

Comment thread src/vulnerable_demo.py
return result.stdout


def hardcoded_secret_example():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security | ❌ ERROR

A sensitive API key is hardcoded directly in the source code.

Why this matters: Hardcoding sensitive information like API keys directly in the source code makes it easily discoverable and compromises the security of the application if the code is exposed. This violates the principle of secure configuration management and makes credential rotation difficult.

Comment thread src/vulnerable_demo.py


def hardcoded_secret_example():
"""Contains hardcoded credentials - security risk."""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security | ❌ ERROR

A sensitive password is hardcoded directly in the source code.

Why this matters: Hardcoding sensitive information like passwords directly in the source code makes it easily discoverable and compromises the security of the application if the code is exposed. This violates the principle of secure configuration management and makes credential rotation difficult.

Comment thread src/vulnerable_demo.py
def path_traversal_example(user_path: str) -> str:
"""Vulnerable to path traversal attacks."""
# BAD: No validation of user-supplied path
base_dir = "/var/data"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security | ❌ ERROR

The user_path input is used to construct a file path without proper validation, leading to a path traversal vulnerability.

Why this matters: The application constructs a file path using unvalidated user input. This allows an attacker to manipulate the user_path to access arbitrary files or directories on the server's file system, potentially leading to information disclosure or unauthorized file modification. The underlying issue is the assumption that user_path will always represent a simple filename within the base_dir.

@github-actions
Copy link
Copy Markdown

🤓 Nitpick Senior Review

The pull request introduces a new file src/vulnerable_demo.py which contains intentionally vulnerable code. This file demonstrates several critical security flaws, including hardcoded secrets and a path traversal vulnerability.

Confidence: 2/5

⚠️ Changes needed - significant issues

Files Changed

File Type Overview
src/vulnerable_demo.py Enhancement New file demonstrating various security vulnerabilities for testing purposes.

Issues Found (3)


🤓 Um, actually... reviewed by Nitpick Senior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant