Skip to content

Add security rules for detecting hard-coded secrets in JavaScript applications #73

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

Merged
merged 7 commits into from
Dec 17, 2024

Conversation

ESS-ENN
Copy link
Collaborator

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

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced security rules to detect hard-coded secrets in JavaScript applications using express-jwt, express-session, and sequelize, enhancing credential management practices.
  • Tests

    • Added comprehensive test cases for validating the correct usage of JWT and session middleware, ensuring hard-coded secrets are not used.
    • Implemented tests for Sequelize configurations to distinguish between valid and invalid usage of hard-coded credentials.

These changes improve security and promote best practices for handling sensitive information in JavaScript applications.

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2024

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.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Dec 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces new security rules for detecting hard-coded secrets in JavaScript applications using the express-jwt, express-session, and Sequelize libraries. Each rule is classified with a severity level of "warning" and includes specific matching patterns to identify hard-coded credentials. Additionally, test configurations are added to validate both correct and incorrect usages of these libraries, ensuring that developers adhere to best practices regarding secret management.

Changes

File Change Summary
rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml New rule added: express-jwt-hardcoded-secret-javascript for detecting hard-coded secrets.
rules/javascript/security/express-session-hardcoded-secret-javascript.yml New rule added: express-session-hardcoded-secret-javascript for detecting hard-coded secrets.
rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml New rule and utilities added: node-sequelize-hardcoded-secret-argument-javascript, MATCH_BLANK_PASSWORD, and MATCH_BLANK_PASSWORD_with_instance.
tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml Added multiple snapshots for testing JWT middleware with various hard-coded secrets.
tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml Added snapshots for testing express-session middleware configurations.
tests/__snapshots__/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml Added snapshots for testing Sequelize instantiation with hard-coded secrets.
tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml New test case added for validating JWT middleware with hard-coded secrets.
tests/javascript/express-session-hardcoded-secret-javascript-test.yml New test case added for validating express-session middleware configurations.
tests/javascript/node-sequelize-hardcoded-secret-argument-javascript-test.yml New test case added for validating Sequelize connection parameters with hard-coded secrets.

Possibly related PRs

  • Rules - Express-jwt-hardcoded-secret in Js/Ts #11: This PR introduces rules for detecting hard-coded secrets in JavaScript and TypeScript applications using the express-jwt library, which directly relates to the main PR's focus on hard-coded credentials in JavaScript code using the same library.
  • Rules - node-rsa-weak-key in Js/Ts #12: Similar to Rules - Express-jwt-hardcoded-secret in Js/Ts #11, this PR also introduces a rule for detecting hard-coded secrets in JavaScript applications using the express-jwt library, reinforcing the main PR's objective of enhancing security against hard-coded credentials.
  • New Rules #2 #9: This PR adds a rule for detecting hard-coded secrets in JavaScript applications using the express-session library, which is relevant as it addresses similar security concerns regarding hard-coded credentials in JavaScript applications.

Suggested reviewers

  • petrisorcoderabbit

Poem

In the code where secrets hide,
A rabbit hops, with eyes open wide.
"No more hard-coded keys," it sings,
"Use env vars for safer things!
Let's keep our code both clean and bright,
Secure our secrets, hold them tight!" 🐇✨


📜 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 bf7c109 and c56b73b.

📒 Files selected for processing (9)
  • rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml (1 hunks)
  • tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml (1 hunks)
  • tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/express-session-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/node-sequelize-hardcoded-secret-argument-javascript-test.yml (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.

@coderabbitai coderabbitai bot changed the title @coderabbitai Add security rules for detecting hard-coded secrets in JavaScript applications Dec 5, 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 (13)
tests/javascript/express-session-hardcoded-secret-javascript-test.yml (2)

2-8: Enhance valid test case with explicit secure practices

The valid case could be more explicit about proper secret management:

 valid:
   - |
-    let config1 = {
-    secret: config.secret,
+    const sessionConfig = {
+    secret: process.env.SESSION_SECRET,
     resave: false,
     saveUninitialized: false,
     }
+  - |
+    // Using multiple secrets for rotation
+    const sessionConfig = {
+      secret: [
+        process.env.SESSION_SECRET_CURRENT,
+        process.env.SESSION_SECRET_PREVIOUS
+      ],
+      resave: false,
+      saveUninitialized: false
+    }

31-31: Add newline at end of file

     saveUninitialized: false,
     }
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 31-31: no new line character at the end of file

(new-line-at-end-of-file)

tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml (2)

2-7: Enhance valid test cases with additional secure practices

Consider adding more examples of secure JWT configuration:

 valid:
   - |
     app.get('/ok-protected', jwt({ secret: process.env.SECRET }), function(req, res) {
     if (!req.user.admin) return res.sendStatus(401);
     res.sendStatus(200);
     });
+  - |
+    // Using asymmetric key pair
+    const publicKey = fs.readFileSync(process.env.JWT_PUBLIC_KEY_PATH);
+    app.get('/asymmetric-protected', 
+      jwt({ secret: publicKey, algorithms: ['RS256'] }), 
+      function(req, res) {
+        if (!req.user.admin) return res.sendStatus(401);
+        res.sendStatus(200);
+    });
+  - |
+    // Using secret callback for key rotation
+    app.get('/dynamic-protected',
+      jwt({
+        secret: (req, payload, done) => {
+          done(null, process.env.JWT_SECRET);
+        }
+      }),
+      function(req, res) {
+        if (!req.user.admin) return res.sendStatus(401);
+        res.sendStatus(200);
+    });

8-44: Add test cases for additional security anti-patterns

Consider adding more invalid cases that demonstrate other security anti-patterns:

 invalid:
   // ... existing cases ...
+  - |
+    // Reading secret from a hardcoded file path
+    const secretFromFile = fs.readFileSync('./jwt-secret.key', 'utf8');
+    app.get('/protected-file', jwt({ secret: secretFromFile }), function(req, res) {
+      if (!req.user.admin) return res.sendStatus(401);
+      res.sendStatus(200);
+    });
+  - |
+    // Using weak secret in development configuration
+    const isDev = process.env.NODE_ENV === 'development';
+    app.get('/protected-dev', 
+      jwt({ secret: isDev ? 'dev-secret' : process.env.SECRET }), 
+      function(req, res) {
+        if (!req.user.admin) return res.sendStatus(401);
+        res.sendStatus(200);
+    });
rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml (2)

1-13: Consider enhancing the security message with specific remediation steps.

While the message effectively explains the risks, it could be more actionable by including:

  • Example of using environment variables
  • Reference to specific secret management solutions
  • Link to Sequelize's documentation on configuration best practices
 message: >-
   A secret is hard-coded in the application. Secrets stored in source
   code, such as credentials, identifiers, and other types of sensitive data,
   can be leaked and used by internal or external malicious actors. Use
   environment variables to securely provide credentials and other secrets or
   retrieve them from a secure vault or Hardware Security Module (HSM).
+  Example:
+  const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS);
+  For production, consider using:
+  - AWS Secrets Manager
+  - HashiCorp Vault
+  - Azure Key Vault

73-75: Consider expanding pattern matching for additional security scenarios.

The current rule focuses on basic Sequelize instantiation, but could be enhanced to detect:

  • URI connection strings with embedded credentials
  • Connection pooling configurations
  • SSL certificate paths

Would you like me to provide examples of additional patterns to cover these scenarios?

tests/__snapshots__/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml (1)

1-109: Enhance test coverage with additional scenarios.

While the current test cases cover basic usage patterns, consider adding:

  1. Connection URI strings
  2. Environment variable usage (negative test)
  3. Configuration objects with nested credentials
  4. Connection pool configurations

Would you like me to provide examples of these additional test scenarios?

tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1)

1-270: Consider additional test scenarios for express-session configurations.

While current tests cover basic configurations, consider adding:

  1. Environment variable usage (negative test)
  2. Complex secret configurations (arrays of secrets)
  3. Custom store configurations with embedded credentials
  4. Cookie configuration scenarios

Would you like me to provide examples of these additional test scenarios?

rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (1)

14-143: Consider enhancing MATCH_SECRET_DIRECTLY pattern for additional edge cases.

The pattern effectively catches direct string assignments but could be enhanced to detect:

  1. Template literals (e.g., `${secret}`)
  2. String concatenation (e.g., 'secret' + process.env.SUFFIX)
  3. Object spread syntax (e.g., { ...config, secret: 'value' })

Would you like me to provide the pattern modifications to handle these cases?

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 22-22: wrong indentation: expected 12 but found 11

(indentation)


[warning] 25-25: wrong indentation: expected 13 but found 11

(indentation)


[warning] 26-26: wrong indentation: expected 15 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


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

(indentation)


[error] 49-49: trailing spaces

(trailing-spaces)


[warning] 55-55: wrong indentation: expected 18 but found 20

(indentation)


[warning] 58-58: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 66-66: wrong indentation: expected 32 but found 34

(indentation)


[warning] 67-67: wrong indentation: expected 38 but found 40

(indentation)


[warning] 71-71: wrong indentation: expected 38 but found 40

(indentation)


[warning] 74-74: wrong indentation: expected 42 but found 44

(indentation)


[warning] 75-75: too many spaces before colon

(colons)


[warning] 77-77: wrong indentation: expected 46 but found 48

(indentation)


[warning] 84-84: wrong indentation: expected 18 but found 20

(indentation)


[warning] 88-88: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 99-99: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 109-109: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 120-120: wrong indentation: expected 16 but found 18

(indentation)


[warning] 127-127: wrong indentation: expected 26 but found 28

(indentation)


[warning] 130-130: wrong indentation: expected 30 but found 32

(indentation)


[warning] 133-133: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)

rules/javascript/security/express-session-hardcoded-secret-javascript.yml (2)

14-110: Consider additional patterns for MATCH_SECRET utility.

The MATCH_SECRET utility could be enhanced to detect:

  1. Environment-based fallbacks (e.g., secret: process.env.SECRET || 'default')
  2. Configuration objects (e.g., config.session.secret)

Would you like me to provide the pattern modifications for these cases?

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 53-53: wrong indentation: expected 38 but found 36

(indentation)


[error] 63-63: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[warning] 71-71: wrong indentation: expected 34 but found 32

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[error] 88-88: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[warning] 97-97: wrong indentation: expected 40 but found 37

(indentation)


[error] 109-109: trailing spaces

(trailing-spaces)


111-255: Fix YAML indentation for better maintainability.

The file has inconsistent indentation that should be fixed for better maintainability.

Apply this diff to fix the indentation:

     MATCH_SECRET_INSIDE_APP:
         kind: pair
         pattern: $C
         inside:
-            stopBy: end
-            kind: expression_statement
+             stopBy: end
+             kind: expression_statement
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 119-119: wrong indentation: expected 22 but found 19

(indentation)


[warning] 122-122: wrong indentation: expected 23 but found 20

(indentation)


[warning] 123-123: wrong indentation: expected 26 but found 23

(indentation)


[warning] 126-126: wrong indentation: expected 27 but found 23

(indentation)


[warning] 127-127: wrong indentation: expected 29 but found 26

(indentation)


[warning] 130-130: wrong indentation: expected 29 but found 26

(indentation)


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

(indentation)


[warning] 141-141: wrong indentation: expected 38 but found 35

(indentation)


[warning] 145-145: wrong indentation: expected 38 but found 35

(indentation)


[warning] 148-148: wrong indentation: expected 39 but found 36

(indentation)


[warning] 152-152: wrong indentation: expected 40 but found 37

(indentation)


[warning] 153-153: wrong indentation: expected 43 but found 40

(indentation)


[warning] 157-157: wrong indentation: expected 43 but found 44

(indentation)


[warning] 158-158: wrong indentation: expected 50 but found 47

(indentation)


[warning] 161-161: wrong indentation: expected 50 but found 48

(indentation)


[error] 163-163: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 173-173: wrong indentation: expected 38 but found 36

(indentation)


[error] 183-183: trailing spaces

(trailing-spaces)


[error] 190-190: trailing spaces

(trailing-spaces)


[warning] 191-191: wrong indentation: expected 34 but found 32

(indentation)


[error] 199-199: trailing spaces

(trailing-spaces)


[error] 208-208: trailing spaces

(trailing-spaces)


[warning] 210-210: wrong indentation: expected 26 but found 25

(indentation)


[warning] 213-213: wrong indentation: expected 29 but found 28

(indentation)


[error] 216-216: trailing spaces

(trailing-spaces)


[warning] 217-217: wrong indentation: expected 38 but found 35

(indentation)


[error] 219-219: trailing spaces

(trailing-spaces)


[warning] 220-220: wrong indentation: expected 39 but found 36

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 235-235: wrong indentation: expected 40 but found 37

(indentation)

tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml (2)

1-82: Add warning comments for example secrets.

The test cases contain hardcoded secrets that could be mistakenly copied. Consider adding clear warning comments.

Add warning comments like:

+# WARNING: The secrets below are for testing purposes only. Never use hardcoded secrets in production.
 import express from 'express';
 import jwt from 'express-jwt';

83-429: Enhance test coverage with negative test cases.

The snapshots focus on detecting hardcoded secrets but could benefit from examples of correct implementations using environment variables or secure configuration patterns.

Would you like me to provide examples of secure configurations to add to the test suite?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2f95a8e and fd3e0cf.

📒 Files selected for processing (9)
  • rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml (1 hunks)
  • tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml (1 hunks)
  • tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/express-session-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/node-sequelize-hardcoded-secret-argument-javascript-test.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
tests/javascript/express-session-hardcoded-secret-javascript-test.yml

[error] 31-31: no new line character at the end of file

(new-line-at-end-of-file)

rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml

[warning] 22-22: wrong indentation: expected 12 but found 11

(indentation)


[warning] 25-25: wrong indentation: expected 13 but found 11

(indentation)


[warning] 26-26: wrong indentation: expected 15 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


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

(indentation)


[error] 49-49: trailing spaces

(trailing-spaces)


[warning] 55-55: wrong indentation: expected 18 but found 20

(indentation)


[warning] 58-58: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 66-66: wrong indentation: expected 32 but found 34

(indentation)


[warning] 67-67: wrong indentation: expected 38 but found 40

(indentation)


[warning] 71-71: wrong indentation: expected 38 but found 40

(indentation)


[warning] 74-74: wrong indentation: expected 42 but found 44

(indentation)


[warning] 75-75: too many spaces before colon

(colons)


[warning] 77-77: wrong indentation: expected 46 but found 48

(indentation)


[warning] 84-84: wrong indentation: expected 18 but found 20

(indentation)


[warning] 88-88: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 99-99: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 109-109: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 120-120: wrong indentation: expected 16 but found 18

(indentation)


[warning] 127-127: wrong indentation: expected 26 but found 28

(indentation)


[warning] 130-130: wrong indentation: expected 30 but found 32

(indentation)


[warning] 133-133: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 152-152: wrong indentation: expected 12 but found 11

(indentation)


[warning] 155-155: wrong indentation: expected 13 but found 11

(indentation)


[warning] 156-156: wrong indentation: expected 15 but found 14

(indentation)


[warning] 160-160: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


[warning] 182-182: wrong indentation: expected 14 but found 16

(indentation)


[warning] 185-185: wrong indentation: expected 18 but found 20

(indentation)


[warning] 201-201: wrong indentation: expected 18 but found 20

(indentation)


[warning] 204-204: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 212-212: wrong indentation: expected 32 but found 34

(indentation)


[warning] 213-213: wrong indentation: expected 38 but found 40

(indentation)


[warning] 217-217: wrong indentation: expected 38 but found 40

(indentation)


[warning] 220-220: wrong indentation: expected 42 but found 44

(indentation)


[warning] 221-221: too many spaces before colon

(colons)


[warning] 223-223: wrong indentation: expected 46 but found 48

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 231-231: wrong indentation: expected 18 but found 20

(indentation)


[warning] 235-235: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 246-246: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 256-256: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 267-267: wrong indentation: expected 16 but found 18

(indentation)


[warning] 274-274: wrong indentation: expected 26 but found 28

(indentation)


[warning] 277-277: wrong indentation: expected 30 but found 32

(indentation)


[warning] 280-280: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 291-291: wrong indentation: expected 2 but found 4

(indentation)

rules/javascript/security/express-session-hardcoded-secret-javascript.yml

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 53-53: wrong indentation: expected 38 but found 36

(indentation)


[error] 63-63: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[warning] 71-71: wrong indentation: expected 34 but found 32

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[error] 88-88: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[warning] 97-97: wrong indentation: expected 40 but found 37

(indentation)


[error] 109-109: trailing spaces

(trailing-spaces)


[warning] 119-119: wrong indentation: expected 22 but found 19

(indentation)


[warning] 122-122: wrong indentation: expected 23 but found 20

(indentation)


[warning] 123-123: wrong indentation: expected 26 but found 23

(indentation)


[warning] 126-126: wrong indentation: expected 27 but found 23

(indentation)


[warning] 127-127: wrong indentation: expected 29 but found 26

(indentation)


[warning] 130-130: wrong indentation: expected 29 but found 26

(indentation)


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

(indentation)


[warning] 141-141: wrong indentation: expected 38 but found 35

(indentation)


[warning] 145-145: wrong indentation: expected 38 but found 35

(indentation)


[warning] 148-148: wrong indentation: expected 39 but found 36

(indentation)


[warning] 152-152: wrong indentation: expected 40 but found 37

(indentation)


[warning] 153-153: wrong indentation: expected 43 but found 40

(indentation)


[warning] 157-157: wrong indentation: expected 43 but found 44

(indentation)


[warning] 158-158: wrong indentation: expected 50 but found 47

(indentation)


[warning] 161-161: wrong indentation: expected 50 but found 48

(indentation)


[error] 163-163: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 173-173: wrong indentation: expected 38 but found 36

(indentation)


[error] 183-183: trailing spaces

(trailing-spaces)


[error] 190-190: trailing spaces

(trailing-spaces)


[warning] 191-191: wrong indentation: expected 34 but found 32

(indentation)


[error] 199-199: trailing spaces

(trailing-spaces)


[error] 208-208: trailing spaces

(trailing-spaces)


[warning] 210-210: wrong indentation: expected 26 but found 25

(indentation)


[warning] 213-213: wrong indentation: expected 29 but found 28

(indentation)


[error] 216-216: trailing spaces

(trailing-spaces)


[warning] 217-217: wrong indentation: expected 38 but found 35

(indentation)


[error] 219-219: trailing spaces

(trailing-spaces)


[warning] 220-220: wrong indentation: expected 39 but found 36

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 235-235: wrong indentation: expected 40 but found 37

(indentation)

rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml

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

(indentation)


[warning] 22-22: wrong indentation: expected 19 but found 16

(indentation)


[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 19

(indentation)


[warning] 27-27: wrong indentation: expected 25 but found 22

(indentation)


[warning] 31-31: wrong indentation: expected 25 but found 22

(indentation)


[warning] 35-35: wrong indentation: expected 26 but found 23

(indentation)


[warning] 40-40: wrong indentation: expected 27 but found 28

(indentation)


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

(indentation)


[warning] 44-44: wrong indentation: expected 26 but found 23

(indentation)


[error] 46-46: trailing spaces

(trailing-spaces)


[warning] 47-47: wrong indentation: expected 27 but found 24

(indentation)


[warning] 54-54: wrong indentation: expected 26 but found 23

(indentation)


[error] 56-56: trailing spaces

(trailing-spaces)


[warning] 57-57: wrong indentation: expected 27 but found 24

(indentation)


[warning] 64-64: wrong indentation: expected 26 but found 23

(indentation)


[error] 66-66: trailing spaces

(trailing-spaces)


[warning] 67-67: wrong indentation: expected 27 but found 24

(indentation)

🔇 Additional comments (4)
tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1)

1-1: Verify rule effectiveness against real-world patterns.

Let's check the codebase for potential bypass patterns that these rules might miss.

✅ Verification successful

Let me try a different approach to verify the rule's effectiveness by examining the test cases and rule patterns directly.


Rule implementation effectively catches hardcoded session secrets

After examining the rule definition and test cases, the implementation effectively detects:

  • Direct string literals used as session secrets
  • Variable assignments with hardcoded secrets
  • Both CommonJS and ES6 module import patterns
  • Different object structure variations where secrets are defined
  • Various express-session configuration patterns

The rule correctly validates legitimate cases where secrets are pulled from configuration objects while flagging hardcoded values in both direct session configurations and separate config objects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Sequelize instantiation patterns that might bypass the rules
echo "Checking Sequelize instantiation patterns..."
rg -t js -t ts "new\s+Sequelize\s*\(" -A 3

# Search for express-session configurations that might bypass the rules
echo "Checking express-session configurations..."
rg -t js -t ts "session\s*\(\s*\{" -A 3

# Search for potential credential string concatenation
echo "Checking string concatenation patterns..."
ast-grep --pattern 'new Sequelize($$$+ $$$)'

Length of output: 718


Script:

#!/bin/bash
# Check the rule definition and test cases
echo "Examining rule definition and test cases..."
fd "express-session.*\.yml" --exec cat {}

# Look for any express-session related test files
echo -e "\nChecking related test files..."
fd "express-session.*\.(js|ts|snap)" --exec cat {}

# Search for session configuration patterns in the entire codebase
echo -e "\nSearching session patterns..."
rg -g "!{dist,node_modules}" "session.*secret"

Length of output: 17858

rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (2)

1-13: LGTM! Well-structured rule configuration with clear security context.

The rule is well-defined with appropriate severity level and includes helpful references to CWE-798 and OWASP guidelines.


144-289: Verify pattern effectiveness for namespace imports.

The MATCH_PATTERN_WITH_INSTANCE utility handles various import styles, but let's verify its effectiveness with namespace imports.

✅ Verification successful

Pattern correctly handles all express-jwt import variations including namespace imports

Based on the test cases and snapshots, the pattern effectively covers all import variations of express-jwt:

  • Default imports: import jwt from 'express-jwt'
  • Named imports: import { expressJwt } from 'express-jwt'
  • CommonJS require: var jwt = require('express-jwt')

While there are no explicit namespace import examples (import * as jwt from 'express-jwt') in the test cases, the pattern's structure in the rule correctly accounts for this case through the namespace_import matcher:

has:
    stopBy: end
    kind: namespace_import
    has:
        stopBy: end
        kind: identifier
        pattern: $E
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for namespace imports of express-jwt in the codebase
ast-grep --pattern $'import * as $E from "express-jwt"'

# Search for potential usage patterns with namespace imports
ast-grep --pattern $'$E.expressJwt({ secret: $_ })'

Length of output: 109


Script:

#!/bin/bash
# Let's try a broader search to find any express-jwt related imports and usage
# Search for any imports of express-jwt
rg -l "express-jwt" --type js --type ts

# Search for any usage of expressJwt or jwt with secret
rg "(?:expressJwt|jwt).*secret" --type js --type ts

# Search for test files that might contain example usage
fd -e test.js -e spec.js -e test.ts -e spec.ts | xargs rg "express-jwt"

Length of output: 4846


Script:

#!/bin/bash
# Let's examine the test file to see the actual test cases and usage patterns
cat tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml

# Also check the snapshot file for comprehensive coverage of different import patterns
cat tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml

Length of output: 12176

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 152-152: wrong indentation: expected 12 but found 11

(indentation)


[warning] 155-155: wrong indentation: expected 13 but found 11

(indentation)


[warning] 156-156: wrong indentation: expected 15 but found 14

(indentation)


[warning] 160-160: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


[warning] 182-182: wrong indentation: expected 14 but found 16

(indentation)


[warning] 185-185: wrong indentation: expected 18 but found 20

(indentation)


[warning] 201-201: wrong indentation: expected 18 but found 20

(indentation)


[warning] 204-204: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 212-212: wrong indentation: expected 32 but found 34

(indentation)


[warning] 213-213: wrong indentation: expected 38 but found 40

(indentation)


[warning] 217-217: wrong indentation: expected 38 but found 40

(indentation)


[warning] 220-220: wrong indentation: expected 42 but found 44

(indentation)


[warning] 221-221: too many spaces before colon

(colons)


[warning] 223-223: wrong indentation: expected 46 but found 48

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 231-231: wrong indentation: expected 18 but found 20

(indentation)


[warning] 235-235: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 246-246: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 256-256: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 267-267: wrong indentation: expected 16 but found 18

(indentation)


[warning] 274-274: wrong indentation: expected 26 but found 28

(indentation)


[warning] 277-277: wrong indentation: expected 30 but found 32

(indentation)


[warning] 280-280: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)

rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1)

1-13: LGTM! Comprehensive security rule for express-session secrets.

The rule effectively detects hardcoded session secrets with appropriate severity and clear guidance.

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

🧹 Nitpick comments (2)
rules/javascript/security/express-session-hardcoded-secret-javascript.yml (2)

15-110: Add coverage for template literals and string concatenation

The current pattern might miss secrets defined using template literals or string concatenation. Consider adding patterns to catch cases like:

const secret = `my${hardcoded}secret`
// or
const secret = 'my' + 'hardcoded' + 'secret'

Would you like me to help create additional patterns for these cases?

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 53-53: wrong indentation: expected 38 but found 36

(indentation)


[error] 63-63: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[warning] 71-71: wrong indentation: expected 34 but found 32

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[error] 88-88: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[warning] 97-97: wrong indentation: expected 40 but found 37

(indentation)


[error] 109-109: trailing spaces

(trailing-spaces)


1-150: Fix YAML formatting issues

The YAML file has several formatting inconsistencies:

  1. Inconsistent indentation (e.g., lines 23, 26, 45)
  2. Trailing spaces (e.g., lines 43, 63, 70)

Would you like me to provide a properly formatted version of the file?

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 53-53: wrong indentation: expected 38 but found 36

(indentation)


[error] 63-63: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[warning] 71-71: wrong indentation: expected 34 but found 32

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[error] 88-88: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[warning] 97-97: wrong indentation: expected 40 but found 37

(indentation)


[error] 109-109: trailing spaces

(trailing-spaces)


[warning] 112-112: wrong indentation: expected 8 but found 6

(indentation)


[warning] 126-126: wrong indentation: expected 20 but found 18

(indentation)


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

(indentation)


[error] 142-142: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd3e0cf and 7d58b71.

📒 Files selected for processing (2)
  • rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1 hunks)
  • tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/snapshots/express-session-hardcoded-secret-javascript-snapshot.yml
🧰 Additional context used
🪛 yamllint (1.35.1)
rules/javascript/security/express-session-hardcoded-secret-javascript.yml

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


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

(indentation)


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

(indentation)


[warning] 53-53: wrong indentation: expected 38 but found 36

(indentation)


[error] 63-63: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[warning] 71-71: wrong indentation: expected 34 but found 32

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[error] 88-88: trailing spaces

(trailing-spaces)


[error] 89-89: trailing spaces

(trailing-spaces)


[warning] 97-97: wrong indentation: expected 40 but found 37

(indentation)


[error] 109-109: trailing spaces

(trailing-spaces)


[warning] 112-112: wrong indentation: expected 8 but found 6

(indentation)


[warning] 126-126: wrong indentation: expected 20 but found 18

(indentation)


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

(indentation)


[error] 142-142: trailing spaces

(trailing-spaces)

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d58b71 and cb79ed3.

📒 Files selected for processing (2)
  • rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1 hunks)
  • tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/snapshots/express-session-hardcoded-secret-javascript-snapshot.yml
🧰 Additional context used
🪛 yamllint (1.35.1)
rules/javascript/security/express-session-hardcoded-secret-javascript.yml

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 22 but found 19

(indentation)


[warning] 48-48: wrong indentation: expected 23 but found 24

(indentation)


[warning] 53-53: wrong indentation: expected 8 but found 6

(indentation)


[warning] 67-67: wrong indentation: expected 20 but found 18

(indentation)


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

(indentation)


[warning] 84-84: wrong indentation: expected 16 but found 13

(indentation)


[warning] 86-86: wrong indentation: expected 17 but found 14

(indentation)


[warning] 89-89: wrong indentation: expected 20 but found 18

(indentation)


[warning] 92-92: wrong indentation: expected 22 but found 24

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
rules/javascript/security/express-session-hardcoded-secret-javascript.yml (3)

1-13: Consider upgrading severity to "error"

Hard-coded secrets represent a critical security vulnerability that could lead to credential exposure. Given the severe security implications (CWE-798), this rule should be treated as an error rather than a warning.

-severity: warning
+severity: error

97-105: Expand secret identifier patterns

The current constraint is too restrictive and might miss common variations of secret identifiers.

    S:
-        regex: '^secret$'
+        regex: '^(secret|SECRET|sessionSecret|session_secret|jwt_secret|jwtSecret)$'

Additionally, consider adding patterns for:

  1. Common misspellings: secert, sceret
  2. Numbered variations: secret1, secret_1
  3. Environment-specific variations: dev_secret, prod_secret
    S:
        regex: '^(secret|secert|sceret|secret[0-9]|secret_[0-9]|(dev|prod|stage|test)_secret)$'
        ignoreCase: true
🧰 Tools
🪛 yamllint (1.35.1)

[error] 97-97: trailing spaces

(trailing-spaces)


1-105: Verify pattern effectiveness against real-world examples

Let's verify the effectiveness of these patterns against common express-session usage patterns in the wild.

✅ Verification successful

Let me gather more information to verify if our patterns would catch different variations of session configuration.


Let me try one more search pattern to check for CommonJS require patterns and other session configuration variations.


Based on the results from examining express-session examples, I can now provide a final verification of the security rule's effectiveness.

Rule pattern effectively catches common express-session secret configurations

The rule's patterns successfully match real-world express-session usage based on the examples found:

  • Matches direct secret configuration: app.use(session({ secret: 'keyboard cat', ... }))
  • Catches both ES module imports and CommonJS requires: import session from 'express-session' and var session = require('express-session')
  • Handles variable declarations and object configurations

The patterns in the rule cover the common ways developers configure express-session secrets, making it effective at identifying hardcoded credentials in session middleware configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for express-session usage patterns in popular repositories
# to ensure our patterns catch real-world scenarios

# Clone top express-session examples
git clone --depth 1 https://github.com/expressjs/session examples/express-session
git clone --depth 1 https://github.com/expressjs/express examples/express

# Search for session secret patterns
echo "Analyzing express-session usage patterns..."
rg -U "session\(.*secret.*\)" examples/ -A 2 -B 2

# Search for potential secret patterns we might miss
echo "Checking for potential missed patterns..."
rg -U "session\(.*\{.*\}.*\)" examples/ -A 2 -B 2

Length of output: 1295


Script:

#!/bin/bash
# Let's check for more variations of session configuration

# Check for different import patterns
echo "Checking import patterns..."
rg "import.*session.*express" examples/ -A 2

# Check for different secret assignment patterns
echo "Checking variable assignments..."
rg "const.*secret.*=.*" examples/ -A 2
rg "let.*secret.*=.*" examples/ -A 2

# Check test files for more examples
echo "Checking test files..."
rg -t js "session\(" examples/express-session/test -A 2 -B 2

# Check for environment variable usage patterns
echo "Checking environment variable patterns..."
rg "process\.env\..*SECRET" examples/ -A 2

Length of output: 1478


Script:

#!/bin/bash
# Check for CommonJS patterns and session configurations

# Check for require patterns
echo "Checking require patterns..."
rg "require\(['\"]express-session['\"]\)" examples/ -A 3

# Look for session configuration examples in example files
echo "Checking example files..."
fd -e js -e ts -e mjs --exec grep -l "session" {} examples/ | xargs cat

# Check for session middleware setup patterns
echo "Checking middleware patterns..."
rg "app\.use\(.*session" examples/ -A 3 -B 1

Length of output: 90791

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 22 but found 19

(indentation)


[warning] 48-48: wrong indentation: expected 23 but found 24

(indentation)


[warning] 53-53: wrong indentation: expected 8 but found 6

(indentation)


[warning] 67-67: wrong indentation: expected 20 but found 18

(indentation)


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

(indentation)


[warning] 84-84: wrong indentation: expected 16 but found 13

(indentation)


[warning] 86-86: wrong indentation: expected 17 but found 14

(indentation)


[warning] 89-89: wrong indentation: expected 20 but found 18

(indentation)


[warning] 92-92: wrong indentation: expected 22 but found 24

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: trailing spaces

(trailing-spaces)

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: 6

♻️ Duplicate comments (2)
rules/javascript/security/express-session-hardcoded-secret-javascript.yml (2)

1-13: ⚠️ Potential issue

Consider upgrading severity to "error"

Hard-coded secrets represent a critical security vulnerability that could lead to credential exposure.

Apply this change:

 id: express-session-hardcoded-secret-javascript
 language: javascript
-severity: warning
+severity: error

103-105: 🛠️ Refactor suggestion

Expand secret identifier patterns

The current constraint only matches the exact string "secret".

Apply this change:

     S:
-        regex: '^secret$'
+        regex: '^(secret|SECRET|sessionSecret|session_secret|jwt_secret|jwtSecret)$'
🧹 Nitpick comments (4)
rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml (1)

85-97: Fix YAML formatting and add missing newline

The file has inconsistent indentation and is missing a newline at the end.

Apply these formatting fixes:

 rule:
-  any:
-     - kind: string
-       matches: MATCH_BLANK_PASSWORD
-     - kind: identifier
-       matches: MATCH_BLANK_PASSWORD_with_instance
+    any:
+        - kind: string
+          matches: MATCH_BLANK_PASSWORD
+        - kind: identifier
+          matches: MATCH_BLANK_PASSWORD_with_instance
 constraints:
-   R:
-    kind: string
-    has:
-       stopBy: neighbor
-       kind: string_fragment
-    
+    R:
+        kind: string
+        has:
+            stopBy: neighbor
+            kind: string_fragment
+
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 86-86: wrong indentation: expected 4 but found 2

(indentation)


[warning] 87-87: wrong indentation: expected 6 but found 5

(indentation)


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

(indentation)


[warning] 93-93: wrong indentation: expected 7 but found 4

(indentation)


[warning] 95-95: wrong indentation: expected 8 but found 7

(indentation)


[error] 97-97: trailing spaces

(trailing-spaces)

rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (3)

1-13: Consider enhancing security references

The security message and references are good, but could be strengthened by adding:

 note: >-
   [CWE-798] Use of Hard-coded Credentials.
   [REFERENCES]
       - https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
+      - https://cwe.mitre.org/data/definitions/798.html
+      - https://auth0.com/blog/express-jwt-security-best-practices/
+      - https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-204C.pdf

290-294: Consider additional validation in rule definition

While the rule correctly combines both patterns, consider adding:

  1. Pattern validation for environment variables (positive pattern)
  2. Maximum string length check for potential secrets
  3. Pattern exclusions for test files
 rule:
     kind: pair
+    not:
+      matches: MATCH_ENV_VAR_USAGE
     any:
       - matches: MATCH_SECRET_DIRECTLY
       - matches: MATCH_PATTERN_WITH_INSTANCE
+    where:
+      - pattern: $SECRET
+        maxLength: 100
+    exclude:
+      - "**/*.test.js"
+      - "**/*.spec.js"
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 291-291: wrong indentation: expected 2 but found 4

(indentation)


1-294: Fix YAML formatting issues

The file has numerous indentation inconsistencies flagged by yamllint. Consider:

  1. Using a consistent 2-space indentation
  2. Removing trailing spaces (lines 49, 226)
  3. Fixing colon spacing (lines 75, 221)

I can help generate a properly formatted version of the file if needed.

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 22-22: wrong indentation: expected 12 but found 11

(indentation)


[warning] 25-25: wrong indentation: expected 13 but found 11

(indentation)


[warning] 26-26: wrong indentation: expected 15 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


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

(indentation)


[error] 49-49: trailing spaces

(trailing-spaces)


[warning] 55-55: wrong indentation: expected 18 but found 20

(indentation)


[warning] 58-58: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 66-66: wrong indentation: expected 32 but found 34

(indentation)


[warning] 67-67: wrong indentation: expected 38 but found 40

(indentation)


[warning] 71-71: wrong indentation: expected 38 but found 40

(indentation)


[warning] 74-74: wrong indentation: expected 42 but found 44

(indentation)


[warning] 75-75: too many spaces before colon

(colons)


[warning] 77-77: wrong indentation: expected 46 but found 48

(indentation)


[warning] 84-84: wrong indentation: expected 18 but found 20

(indentation)


[warning] 88-88: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 99-99: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 109-109: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 120-120: wrong indentation: expected 16 but found 18

(indentation)


[warning] 127-127: wrong indentation: expected 26 but found 28

(indentation)


[warning] 130-130: wrong indentation: expected 30 but found 32

(indentation)


[warning] 133-133: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 152-152: wrong indentation: expected 12 but found 11

(indentation)


[warning] 155-155: wrong indentation: expected 13 but found 11

(indentation)


[warning] 156-156: wrong indentation: expected 15 but found 14

(indentation)


[warning] 160-160: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


[warning] 182-182: wrong indentation: expected 14 but found 16

(indentation)


[warning] 185-185: wrong indentation: expected 18 but found 20

(indentation)


[warning] 201-201: wrong indentation: expected 18 but found 20

(indentation)


[warning] 204-204: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 212-212: wrong indentation: expected 32 but found 34

(indentation)


[warning] 213-213: wrong indentation: expected 38 but found 40

(indentation)


[warning] 217-217: wrong indentation: expected 38 but found 40

(indentation)


[warning] 220-220: wrong indentation: expected 42 but found 44

(indentation)


[warning] 221-221: too many spaces before colon

(colons)


[warning] 223-223: wrong indentation: expected 46 but found 48

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 231-231: wrong indentation: expected 18 but found 20

(indentation)


[warning] 235-235: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 246-246: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 256-256: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 267-267: wrong indentation: expected 16 but found 18

(indentation)


[warning] 274-274: wrong indentation: expected 26 but found 28

(indentation)


[warning] 277-277: wrong indentation: expected 30 but found 32

(indentation)


[warning] 280-280: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 291-291: wrong indentation: expected 2 but found 4

(indentation)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb79ed3 and bf7c109.

📒 Files selected for processing (9)
  • rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/express-session-hardcoded-secret-javascript.yml (1 hunks)
  • rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml (1 hunks)
  • tests/__snapshots__/express-jwt-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/express-session-hardcoded-secret-javascript-snapshot.yml (1 hunks)
  • tests/__snapshots__/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml (1 hunks)
  • tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/express-session-hardcoded-secret-javascript-test.yml (1 hunks)
  • tests/javascript/node-sequelize-hardcoded-secret-argument-javascript-test.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/javascript/node-sequelize-hardcoded-secret-argument-javascript-test.yml
  • tests/snapshots/node-sequelize-hardcoded-secret-argument-javascript-snapshot.yml
  • tests/javascript/express-jwt-hardcoded-secret-javascript-test.yml
  • tests/snapshots/express-session-hardcoded-secret-javascript-snapshot.yml
  • tests/snapshots/express-jwt-hardcoded-secret-javascript-snapshot.yml
🧰 Additional context used
🪛 yamllint (1.35.1)
rules/javascript/security/node-sequelize-hardcoded-secret-argument-javascript.yml

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

(indentation)


[warning] 22-22: wrong indentation: expected 19 but found 16

(indentation)


[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 19

(indentation)


[warning] 27-27: wrong indentation: expected 25 but found 22

(indentation)


[warning] 31-31: wrong indentation: expected 25 but found 22

(indentation)


[warning] 35-35: wrong indentation: expected 26 but found 23

(indentation)


[warning] 40-40: wrong indentation: expected 27 but found 28

(indentation)


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

(indentation)


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

(indentation)


[warning] 56-56: wrong indentation: expected 19 but found 16

(indentation)


[warning] 57-57: wrong indentation: expected 22 but found 19

(indentation)


[warning] 60-60: wrong indentation: expected 23 but found 19

(indentation)


[warning] 61-61: wrong indentation: expected 25 but found 22

(indentation)


[warning] 65-65: wrong indentation: expected 25 but found 22

(indentation)


[warning] 69-69: wrong indentation: expected 26 but found 23

(indentation)


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

(indentation)


[error] 79-79: trailing spaces

(trailing-spaces)


[warning] 81-81: wrong indentation: expected 22 but found 19

(indentation)


[warning] 83-83: wrong indentation: expected 23 but found 22

(indentation)


[warning] 86-86: wrong indentation: expected 4 but found 2

(indentation)


[warning] 87-87: wrong indentation: expected 6 but found 5

(indentation)


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

(indentation)


[warning] 93-93: wrong indentation: expected 7 but found 4

(indentation)


[warning] 95-95: wrong indentation: expected 8 but found 7

(indentation)


[error] 97-97: trailing spaces

(trailing-spaces)

rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml

[warning] 22-22: wrong indentation: expected 12 but found 11

(indentation)


[warning] 25-25: wrong indentation: expected 13 but found 11

(indentation)


[warning] 26-26: wrong indentation: expected 15 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


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

(indentation)


[error] 49-49: trailing spaces

(trailing-spaces)


[warning] 55-55: wrong indentation: expected 18 but found 20

(indentation)


[warning] 58-58: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 66-66: wrong indentation: expected 32 but found 34

(indentation)


[warning] 67-67: wrong indentation: expected 38 but found 40

(indentation)


[warning] 71-71: wrong indentation: expected 38 but found 40

(indentation)


[warning] 74-74: wrong indentation: expected 42 but found 44

(indentation)


[warning] 75-75: too many spaces before colon

(colons)


[warning] 77-77: wrong indentation: expected 46 but found 48

(indentation)


[warning] 84-84: wrong indentation: expected 18 but found 20

(indentation)


[warning] 88-88: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 99-99: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 109-109: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 120-120: wrong indentation: expected 16 but found 18

(indentation)


[warning] 127-127: wrong indentation: expected 26 but found 28

(indentation)


[warning] 130-130: wrong indentation: expected 30 but found 32

(indentation)


[warning] 133-133: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 152-152: wrong indentation: expected 12 but found 11

(indentation)


[warning] 155-155: wrong indentation: expected 13 but found 11

(indentation)


[warning] 156-156: wrong indentation: expected 15 but found 14

(indentation)


[warning] 160-160: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


[warning] 182-182: wrong indentation: expected 14 but found 16

(indentation)


[warning] 185-185: wrong indentation: expected 18 but found 20

(indentation)


[warning] 201-201: wrong indentation: expected 18 but found 20

(indentation)


[warning] 204-204: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 212-212: wrong indentation: expected 32 but found 34

(indentation)


[warning] 213-213: wrong indentation: expected 38 but found 40

(indentation)


[warning] 217-217: wrong indentation: expected 38 but found 40

(indentation)


[warning] 220-220: wrong indentation: expected 42 but found 44

(indentation)


[warning] 221-221: too many spaces before colon

(colons)


[warning] 223-223: wrong indentation: expected 46 but found 48

(indentation)


[error] 226-226: trailing spaces

(trailing-spaces)


[warning] 231-231: wrong indentation: expected 18 but found 20

(indentation)


[warning] 235-235: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 246-246: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 256-256: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 267-267: wrong indentation: expected 16 but found 18

(indentation)


[warning] 274-274: wrong indentation: expected 26 but found 28

(indentation)


[warning] 277-277: wrong indentation: expected 30 but found 32

(indentation)


[warning] 280-280: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)


[warning] 291-291: wrong indentation: expected 2 but found 4

(indentation)

rules/javascript/security/express-session-hardcoded-secret-javascript.yml

[warning] 23-23: wrong indentation: expected 22 but found 19

(indentation)


[warning] 26-26: wrong indentation: expected 23 but found 20

(indentation)


[error] 43-43: trailing spaces

(trailing-spaces)


[warning] 45-45: wrong indentation: expected 22 but found 19

(indentation)


[warning] 48-48: wrong indentation: expected 23 but found 24

(indentation)


[warning] 53-53: wrong indentation: expected 8 but found 6

(indentation)


[warning] 67-67: wrong indentation: expected 20 but found 18

(indentation)


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

(indentation)


[warning] 84-84: wrong indentation: expected 16 but found 13

(indentation)


[warning] 86-86: wrong indentation: expected 17 but found 14

(indentation)


[warning] 89-89: wrong indentation: expected 20 but found 18

(indentation)


[warning] 92-92: wrong indentation: expected 22 but found 24

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: trailing spaces

(trailing-spaces)

tests/javascript/express-session-hardcoded-secret-javascript-test.yml

[error] 31-31: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
rules/javascript/security/express-jwt-hardcoded-secret-javascript.yml (1)

15-143: 🛠️ Refactor suggestion

Address potential edge cases and fix formatting

The pattern matcher is comprehensive but consider these improvements:

  1. Edge Cases:

    • Add pattern for template literals (`${secret}`)
    • Handle object spread operators
    • Consider destructured assignments
  2. Fix formatting issues:

    • Inconsistent indentation throughout the pattern
    • Trailing spaces on line 49
🧰 Tools
🪛 yamllint (1.35.1)

[warning] 22-22: wrong indentation: expected 12 but found 11

(indentation)


[warning] 25-25: wrong indentation: expected 13 but found 11

(indentation)


[warning] 26-26: wrong indentation: expected 15 but found 14

(indentation)


[warning] 30-30: wrong indentation: expected 15 but found 14

(indentation)


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

(indentation)


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

(indentation)


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

(indentation)


[error] 49-49: trailing spaces

(trailing-spaces)


[warning] 55-55: wrong indentation: expected 18 but found 20

(indentation)


[warning] 58-58: wrong indentation: expected 22 but found 24

(indentation)


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

(indentation)


[warning] 66-66: wrong indentation: expected 32 but found 34

(indentation)


[warning] 67-67: wrong indentation: expected 38 but found 40

(indentation)


[warning] 71-71: wrong indentation: expected 38 but found 40

(indentation)


[warning] 74-74: wrong indentation: expected 42 but found 44

(indentation)


[warning] 75-75: too many spaces before colon

(colons)


[warning] 77-77: wrong indentation: expected 46 but found 48

(indentation)


[warning] 84-84: wrong indentation: expected 18 but found 20

(indentation)


[warning] 88-88: wrong indentation: expected 26 but found 28

(indentation)


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

(indentation)


[warning] 99-99: wrong indentation: expected 16 but found 18

(indentation)


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

(indentation)


[warning] 109-109: wrong indentation: expected 30 but found 32

(indentation)


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

(indentation)


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

(indentation)


[warning] 120-120: wrong indentation: expected 16 but found 18

(indentation)


[warning] 127-127: wrong indentation: expected 26 but found 28

(indentation)


[warning] 130-130: wrong indentation: expected 30 but found 32

(indentation)


[warning] 133-133: wrong indentation: expected 34 but found 36

(indentation)


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

(indentation)

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.

3 participants