Skip to content
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

Add security rules for empty passwords in Ruby and Rust applications #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ESS-ENN
Copy link
Collaborator

@ESS-ENN ESS-ENN commented Dec 11, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new security rules for Ruby and Rust applications to flag empty password usage in database connections.
    • Added guidance for secure credential management and best practices.
  • Tests

    • New test cases added for validating database connections with empty passwords in both Ruby and Rust.
    • Snapshots created for testing scenarios involving empty passwords for Cassandra and SQLx connections.
  • Documentation

    • Updated references to security best practices and OWASP resources for credential management.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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 Dec 11, 2024

Walkthrough

This pull request introduces new security rules for Ruby and Rust applications to identify and flag instances of empty passwords used in database connections. The Ruby rule targets connections to Cassandra, while the Rust rule covers MySQL and PostgreSQL connections. Each rule is categorized with a severity level of "warning" and provides guidance on secure credential management practices. Additionally, the changes include new test cases and snapshots to validate the behavior of applications when handling empty passwords.

Changes

File Path Change Summary
rules/ruby/security/ruby-cassandra-empty-password-ruby.yml New rule ruby-cassandra-empty-password-ruby added to flag empty passwords in Cassandra connections.
rules/rust/security/empty-password-rust.yml New rule empty-password-rust added to identify empty credentials in MySQL and PostgreSQL connections. New utility functions for matching call expressions added.
tests/snapshots/empty-password-rust-snapshot.yml New snapshot file added with three test functions for MySQL and PostgreSQL connections using empty passwords.
tests/snapshots/ruby-cassandra-empty-password-ruby-snapshot.yml New snapshot file added for testing Ruby Cassandra connections with empty passwords.
tests/ruby/ruby-cassandra-empty-password-ruby-test.yml New test case added for validating Cassandra client behavior with empty passwords, including valid and invalid scenarios.
tests/rust/empty-password-rust-test.yml New test file added with asynchronous test functions for validating database connections using SQLx with empty passwords.

Possibly related PRs

Suggested reviewers

  • petrisorcoderabbit
  • rohit121

Poem

🐇 In the land of code we hop and play,
New rules for safety, hip-hip-hooray!
Empty passwords, we say no more,
Secure your secrets, that's what we're for!
With tests and snapshots, we guard the gate,
For a safer world, let’s celebrate! 🎉


🪧 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. (Experiment)
  • @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.

@coderabbitai coderabbitai bot changed the title @coderabbitai Add security rules for empty passwords in Ruby and Rust applications Dec 11, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
tests/ruby/ruby-cassandra-empty-password-ruby-test.yml (1)

1-12: Enhance test coverage with additional scenarios

Consider adding the following test cases to improve coverage:

  1. Valid cases using environment variables
  2. Valid cases using secure credential storage
  3. Invalid cases with null passwords
  4. Invalid cases with whitespace-only passwords
tests/__snapshots__/ruby-cassandra-empty-password-ruby-snapshot.yml (1)

1-112: Enhance snapshot documentation

Consider adding:

  1. Comments explaining the purpose of each snapshot
  2. Expected behavior documentation
  3. References to related security guidelines
rules/ruby/security/ruby-cassandra-empty-password-ruby.yml (2)

4-10: Enhance security guidance in message

The message provides good basic guidance but could be improved by:

  1. Adding specific examples of secure credential management
  2. Mentioning the risks of credential exposure in logs
  3. Referencing specific vault solutions (e.g., HashiCorp Vault, AWS Secrets Manager)

15-131: Enhance pattern matching coverage

Consider adding patterns to catch:

  1. Empty passwords passed through method calls
  2. Empty passwords from configuration files
  3. Empty passwords in connection strings
  4. Empty passwords masked with whitespace

Example pattern for method calls:

  password_from_method():
    kind: call
    has:
      stopBy: end
      kind: method
      pattern: get_password
    inside:
      kind: pair
      pattern: password:
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 18-18: wrong indentation: expected 4 but found 3

(indentation)


[warning] 38-38: wrong indentation: expected 13 but found 12

(indentation)


[warning] 46-46: wrong indentation: expected 18 but found 17

(indentation)


[warning] 47-47: wrong indentation: expected 19 but found 18

(indentation)


[warning] 50-50: wrong indentation: expected 9 but found 11

(indentation)


[warning] 53-53: wrong indentation: expected 13 but found 15

(indentation)


[warning] 58-58: wrong indentation: expected 4 but found 3

(indentation)


[warning] 78-78: wrong indentation: expected 13 but found 12

(indentation)


[warning] 87-87: wrong indentation: expected 9 but found 11

(indentation)


[warning] 90-90: wrong indentation: expected 13 but found 15

(indentation)


[warning] 94-94: wrong indentation: expected 9 but found 8

(indentation)


[warning] 95-95: wrong indentation: expected 12 but found 15

(indentation)


[warning] 98-98: wrong indentation: expected 17 but found 16

(indentation)


[warning] 99-99: wrong indentation: expected 20 but found 22

(indentation)


[warning] 100-100: too many spaces after colon

(colons)


[warning] 103-103: wrong indentation: expected 20 but found 22

(indentation)


[warning] 106-106: wrong indentation: expected 24 but found 26

(indentation)


[warning] 107-107: wrong indentation: expected 28 but found 30

(indentation)


[warning] 110-110: wrong indentation: expected 12 but found 14

(indentation)


[warning] 113-113: wrong indentation: expected 16 but found 15

(indentation)


[warning] 116-116: wrong indentation: expected 17 but found 16

(indentation)


[warning] 117-117: wrong indentation: expected 20 but found 22

(indentation)


[warning] 118-118: too many spaces after colon

(colons)


[warning] 121-121: wrong indentation: expected 20 but found 22

(indentation)


[warning] 124-124: wrong indentation: expected 24 but found 26

(indentation)


[warning] 125-125: wrong indentation: expected 28 but found 30

(indentation)


[error] 126-126: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between da59ae6 and 40ccf7f.

📒 Files selected for processing (6)
  • rules/ruby/security/ruby-cassandra-empty-password-ruby.yml (1 hunks)
  • rules/rust/security/empty-password-rust.yml (1 hunks)
  • tests/__snapshots__/empty-password-rust-snapshot.yml (1 hunks)
  • tests/__snapshots__/ruby-cassandra-empty-password-ruby-snapshot.yml (1 hunks)
  • tests/ruby/ruby-cassandra-empty-password-ruby-test.yml (1 hunks)
  • tests/rust/empty-password-rust-test.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
rules/ruby/security/ruby-cassandra-empty-password-ruby.yml

[warning] 18-18: wrong indentation: expected 4 but found 3

(indentation)


[warning] 38-38: wrong indentation: expected 13 but found 12

(indentation)


[warning] 46-46: wrong indentation: expected 18 but found 17

(indentation)


[warning] 47-47: wrong indentation: expected 19 but found 18

(indentation)


[warning] 50-50: wrong indentation: expected 9 but found 11

(indentation)


[warning] 53-53: wrong indentation: expected 13 but found 15

(indentation)


[warning] 58-58: wrong indentation: expected 4 but found 3

(indentation)


[warning] 78-78: wrong indentation: expected 13 but found 12

(indentation)


[warning] 87-87: wrong indentation: expected 9 but found 11

(indentation)


[warning] 90-90: wrong indentation: expected 13 but found 15

(indentation)


[warning] 94-94: wrong indentation: expected 9 but found 8

(indentation)


[warning] 95-95: wrong indentation: expected 12 but found 15

(indentation)


[warning] 98-98: wrong indentation: expected 17 but found 16

(indentation)


[warning] 99-99: wrong indentation: expected 20 but found 22

(indentation)


[warning] 100-100: too many spaces after colon

(colons)


[warning] 103-103: wrong indentation: expected 20 but found 22

(indentation)


[warning] 106-106: wrong indentation: expected 24 but found 26

(indentation)


[warning] 107-107: wrong indentation: expected 28 but found 30

(indentation)


[warning] 110-110: wrong indentation: expected 12 but found 14

(indentation)


[warning] 113-113: wrong indentation: expected 16 but found 15

(indentation)


[warning] 116-116: wrong indentation: expected 17 but found 16

(indentation)


[warning] 117-117: wrong indentation: expected 20 but found 22

(indentation)


[warning] 118-118: too many spaces after colon

(colons)


[warning] 121-121: wrong indentation: expected 20 but found 22

(indentation)


[warning] 124-124: wrong indentation: expected 24 but found 26

(indentation)


[warning] 125-125: wrong indentation: expected 28 but found 30

(indentation)


[error] 126-126: trailing spaces

(trailing-spaces)

🔇 Additional comments (9)
tests/rust/empty-password-rust-test.yml (4)

4-13: LGTM! Good security practice using environment variable for password.

The test case demonstrates proper password handling by sourcing credentials from environment variables.


16-26: LGTM! Appropriate negative test case for MySQL empty password detection.

This test case correctly validates the security rule's ability to detect empty passwords in MySQL connections.


28-40: LGTM! Comprehensive negative test case with SSL configuration.

This test case effectively validates empty password detection while including SSL configuration, providing good coverage of security scenarios.


42-54: LGTM! Good coverage of alternative initialization patterns.

This test case ensures the security rule can detect empty passwords regardless of the initialization pattern used.

rules/rust/security/empty-password-rust.yml (4)

1-14: LGTM! Well-documented security rule with clear messaging.

The rule provides:

  • Clear identification and severity level
  • Comprehensive explanation of the security risk
  • Actionable remediation steps
  • Relevant security references (CWE-287)

15-105: LGTM! Robust pattern matching for MySQL connections.

The utility function match_call_expression_with_mysqlconnections provides comprehensive AST matching for MySQL connection patterns.


106-303: LGTM! Thorough pattern matching for PostgreSQL connections.

The utility functions for PostgreSQL connections cover both direct initialization and instance-based patterns.


305-309: LGTM! Well-structured rule composition.

The rule effectively combines all pattern matching utilities to provide comprehensive coverage.

tests/__snapshots__/empty-password-rust-snapshot.yml (1)

1-643: LGTM! Comprehensive snapshot coverage for empty password detection.

The snapshots provide:

  • Accurate AST patterns for both MySQL and PostgreSQL
  • Detailed matching information for different initialization patterns
  • Proper labeling for primary and secondary matches

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