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

feat: add hostnameExceptionList for ssrf #100

Merged
merged 3 commits into from
Jul 8, 2024
Merged

Conversation

killagu
Copy link
Contributor

@killagu killagu commented Jul 8, 2024

Summary by CodeRabbit

  • New Features

    • Introduced hostnameExceptionList for specifying allowed hostnames within IP blacklists, enhancing SSRF protection.
  • Bug Fixes

    • Adjusted access method for refererWhiteList to improve security configuration handling.
  • Tests

    • Added test cases to validate the functionality of the new hostnameExceptionList feature.
  • Documentation

    • Updated README to include information about the new hostnameExceptionList in security configurations.

Copy link
Contributor

coderabbitai bot commented Jul 8, 2024

Walkthrough

A new hostnameExceptionList array has been added to the security configurations in multiple files to specify legal hostnames within an ipBlackList. This update includes changes to configuration files, utility functions, and related test cases to enhance the security measures for SSRF protection.

Changes

File(s) Change Summary
README.md Added hostnameExceptionList to the security export section.
app/extend/context.js Accessed refererWhiteList from this.app.config.security.csrf.
config/config.default.js Added hostnameExceptionList under the ssrf configuration object.
lib/utils.js Updated ssrf.checkAddress signature to include family and hostname; added logic for hostnameExceptionList.
test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js Introduced security configurations for SSRF protection specifying IP blacklists and hostname exceptions.
test/fixtures/apps/ssrf-hostname-exception-list/package.json New JSON configuration with the name "ssrf-ip-black-list".
test/ssrf.test.js Added hostnameExceptionList test case within the describe block using mock functions for curl.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Config as config.default.js
    participant Context as context.js
    participant Utils as utils.js
    participant Test as ssrf.test.js

    App->>Config: Read ssrf configuration
    Config-->>App: Return ssrf settings with hostnameExceptionList
    App->>Context: Access refererWhiteList from security.csrf
    Context->>Utils: Call ssrf.checkAddress with family and hostname
    Utils->>Config: Check hostname against hostnameExceptionList
    Utils-->>Context: Return address check result
    Test->>App: Mock curl and test safeCurl
    App-->>Test: Return test results with valid hostnameExceptionList checks
Loading

Poem

In the code, we've paved the way,
For hostnames valid, come what may.
Amidst the blacklists, exceptions grace,
With safety measures in their place.
A rabbit's joy in each secure twist,
Leap on, dear coder, into the mist! 🌟


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@killagu killagu force-pushed the feat/hostnameExceptionList branch from 65c852d to 67c0043 Compare July 8, 2024 14:45
Copy link

pkg-pr-new bot commented Jul 8, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: cedf173

egg-security

npm i https://pkg.pr.new/eggjs/egg-security@100


templates

Copy link

pkg-pr-new bot commented Jul 8, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: 67c0043

egg-security

npm i https://pkg.pr.new/eggjs/egg-security@100


templates

app/extend/context.js Outdated Show resolved Hide resolved
Copy link
Contributor

@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

Outside diff range and nitpick comments (2)
test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js (1)

1-1: Remove redundant 'use strict' directive.

JavaScript modules are in strict mode by default, making this directive unnecessary.

- 'use strict';
Tools
Biome

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

lib/utils.js (1)

114-121: Change to an optional chain.

Use optional chaining to simplify the hostname check.

- if (hostname && hostnameExceptionList) {
-   if (hostnameExceptionList.includes(hostname)) {
-     return true;
-   }
+ if (hostnameExceptionList?.includes(hostname)) {
+   return true;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b4d8baa and 67c0043.

Files selected for processing (7)
  • README.md (2 hunks)
  • app/extend/context.js (1 hunks)
  • config/config.default.js (1 hunks)
  • lib/utils.js (1 hunks)
  • test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js (1 hunks)
  • test/fixtures/apps/ssrf-hostname-exception-list/package.json (1 hunks)
  • test/ssrf.test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • test/fixtures/apps/ssrf-hostname-exception-list/package.json
Additional context used
Biome
test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js

[error] 1-1: Redundant use strict directive.

The entire contents of JavaScript modules are automatically in strict mode, with no statement needed to initiate it.
Safe fix: Remove the redundant use strict directive.

(lint/suspicious/noRedundantUseStrict)

lib/utils.js

[error] 111-111: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

LanguageTool
README.md

[grammar] ~526-~526: Consider using third-person verb forms for singular and mass nouns.
Context: ...onList(Array) - specific which hostname are legal within ipBlackList. - checkAddres...

(MASS_AGREEMENT)

Additional comments not posted (5)
test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js (1)

10-13: Ensure hostname exception list is comprehensive.

Review the list of hostnames to ensure all necessary exceptions are included.

config/config.default.js (1)

106-106: Ensure hostnameExceptionList is properly configured.

Verify that the hostnameExceptionList is correctly populated and used within the application.

test/ssrf.test.js (1)

175-204: Ensure comprehensive testing of hostnameExceptionList.

Verify that the test cases cover all possible scenarios for the hostnameExceptionList.

app/extend/context.js (1)

212-212: Verify the correctness of the new access path.

The new access path for refererWhiteList is this.app.config.security.csrf.refererWhiteList. Ensure that this path is correct and that the refererWhiteList property exists within csrf.

Verification successful

The new access path is correct.

The refererWhiteList property is correctly accessed as this.app.config.security.csrf.refererWhiteList.

  • lib/utils.js: config.csrf.refererWhiteList
  • config/config.default.js: refererWhiteList within csrf
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of `refererWhiteList` in `csrf`.

# Test: Search for the configuration definition. Expect: `refererWhiteList` is defined within `csrf`.
rg --type javascript $'refererWhiteList'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the existence of `refererWhiteList` in `csrf`.

# Test: Search for the configuration definition. Expect: `refererWhiteList` is defined within `csrf`.
rg --type js 'refererWhiteList'

Length of output: 1331

README.md (1)

544-547: Verify the validity of the hostnames in the example.

Ensure that the hostnames provided in the hostnameExceptionList example are valid and correctly formatted.

Verification successful

The hostnames in the hostnameExceptionList example are valid and correctly formatted.

  • registry.npmjs.org
  • registry.npmmirror.com
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the validity of hostnames in `hostnameExceptionList`.

# Test: Check if the hostnames in the example are valid. Expect: Hostnames are correctly formatted.
rg --type javascript $'hostnameExceptionList:'

Length of output: 80


Script:

#!/bin/bash
# Description: Verify the validity of hostnames in `hostnameExceptionList`.

# Test: Check if the hostnames in the example are valid. Expect: Hostnames are correctly formatted.
rg 'hostnameExceptionList:' --glob '*.js' --glob '*.jsx' --glob '*.ts' --glob '*.tsx'

Length of output: 247


Script:

#!/bin/bash
# Description: Display the contents of the file containing hostnameExceptionList.

# Test: Display the lines around the hostnameExceptionList to verify the hostnames.
rg 'hostnameExceptionList:' --glob 'test/fixtures/apps/ssrf-hostname-exception-list/config/config.default.js' -A 5 -B 5

Length of output: 1109

README.md Outdated Show resolved Hide resolved
killagu and others added 2 commits July 8, 2024 22:52
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 67c0043 and cedf173.

Files selected for processing (1)
  • README.md (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • README.md

Copy link

codecov bot commented Jul 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.28%. Comparing base (b4d8baa) to head (cedf173).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #100      +/-   ##
==========================================
+ Coverage   97.26%   97.28%   +0.01%     
==========================================
  Files          32       32              
  Lines        1354     1362       +8     
  Branches      340      342       +2     
==========================================
+ Hits         1317     1325       +8     
  Misses         37       37              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fengmk2 fengmk2 merged commit 92a34f3 into master Jul 8, 2024
26 checks passed
@fengmk2 fengmk2 deleted the feat/hostnameExceptionList branch July 8, 2024 15:02
fengmk2 pushed a commit that referenced this pull request Jul 8, 2024
[skip ci]

## [3.6.0](v3.5.0...v3.6.0) (2024-07-08)

### Features

* add hostnameExceptionList for ssrf ([#100](#100)) ([92a34f3](92a34f3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants