Skip to content

Add static analysis rules for system() in C/C++ and JWT expiry in C# #151

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

Closed

Conversation

ESS-ENN
Copy link
Collaborator

@ESS-ENN ESS-ENN commented Feb 7, 2025

Summary by CodeRabbit

  • New Features

    • Added security checks that flag unsafe command execution across multiple programming languages.
    • Enforced configuration validations to ensure proper token expiration settings.
  • Tests

    • Expanded snapshot and unit test coverage to verify the detection of insecure patterns and validate secure configurations.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ESS-ENN
❌ Sakshis


Sakshis seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Feb 7, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several new static analysis rules and corresponding tests across multiple languages. New rules for C and C++ flag any use of the system() function and advise using execve instead, while a rule for C# ensures JWT token validation parameters enforce expiration checks. Additionally, snapshot and unit test files have been added or modified to verify both valid and invalid scenarios, reinforcing safer coding practices by detecting insecure command execution and token misconfiguration.

Changes

File(s) Change Summary
rules/c/…/dont-call-system-c.yml, rules/cpp/…/dont-call-system-cpp.yml Added new rules for C and C++ that warn against using the system() function, with detection patterns for calls inside if statements and other contexts; recommends using execve and references CWE-78.
rules/csharp/…/jwt-tokenvalidationparameters-no-expiry-validation-csharp.yml Added a new rule for JWT token validation in C# that triggers a warning when token lifetime checks (RequireExpirationTime/ValidateLifetime) are disabled; references CWE-613.
tests/snapshots/dont-call-system-c*.yml, tests/cpp/dont-call-system-cpp-test.yml, tests/java/dont-call-system-c-test.yml Introduced snapshot files and modified test cases for detecting unsafe use of system() calls, including scenarios with and without proper error handling.
tests/snapshots/jwt-tokenvalidationparameters-no-expiry-validation-csharp-snapshot.yml, tests/csharp/jwt-tokenvalidationparameters-no-expiry-validation-csharp-test.yml Added snapshot and test configurations to validate JWT token parameter scenarios in C#, ensuring expiration validation is enforced.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant AST as AST-Grep Tool
    participant Rule as System Call Rule
    Dev->>AST: Submit C/C++ code with system() call
    AST->>Rule: Analyze code patterns
    Rule-->>AST: Identify unsafe system() usage
    AST->>Dev: Emit warning recommending execve
Loading
sequenceDiagram
    participant Dev as Developer
    participant Analyzer as Code Analyzer
    participant Rule as JWT Token Rule
    Dev->>Analyzer: Submit C# code with TokenValidationParameters
    Analyzer->>Rule: Check ValidateLifetime and RequireExpirationTime
    Rule-->>Analyzer: Flag if validation is disabled
    Analyzer->>Dev: Emit warning per security guidelines
Loading

Possibly related PRs

Suggested reviewers

  • ganeshpatro321

Poem

I'm a bunny on a coding spree,
Hopping through rules so securely,
System calls too wild to roam,
I warn with wisdom from my home.
Cheers to safe code and a carrot-filled day! 🐰🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc35ee3 and 8b384b8.

📒 Files selected for processing (9)
  • rules/c/security/dont-call-system-c.yml (1 hunks)
  • rules/cpp/dont-call-system-cpp.yml (1 hunks)
  • rules/csharp/security/jwt-tokenvalidationparameters-no-expiry-validation-csharp.yml (1 hunks)
  • tests/__snapshots__/dont-call-system-c-snapshot.yml (1 hunks)
  • tests/__snapshots__/dont-call-system-cpp-snapshot.yml (1 hunks)
  • tests/__snapshots__/jwt-tokenvalidationparameters-no-expiry-validation-csharp-snapshot.yml (1 hunks)
  • tests/cpp/dont-call-system-cpp-test.yml (1 hunks)
  • tests/csharp/jwt-tokenvalidationparameters-no-expiry-validation-csharp-test.yml (1 hunks)
  • tests/java/dont-call-system-c-test.yml (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ESS-ENN ESS-ENN closed this Feb 7, 2025
@coderabbitai coderabbitai bot changed the title @coderabbitai Add static analysis rules for system() in C/C++ and JWT expiry in C# Feb 7, 2025
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.

2 participants