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

397 create ip check #400

Merged
merged 5 commits into from
Dec 19, 2024
Merged

397 create ip check #400

merged 5 commits into from
Dec 19, 2024

Conversation

DeboraSerra
Copy link
Contributor

Describe your changes

Briefly describe the changes you made and their purpose.

Issue number

Mention the issue number(s) this PR addresses (e.g., #123).

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

When IP is not in the Allowed IPs
image
When IP is in the Allowed IPs or the env variable is not present
image

@DeboraSerra DeboraSerra requested a review from erenfn December 18, 2024 18:19
@DeboraSerra DeboraSerra changed the base branch from master to develop December 18, 2024 18:20
@DeboraSerra DeboraSerra linked an issue Dec 18, 2024 that may be closed by this pull request
2 tasks
Copy link
Contributor

coderabbitai bot commented Dec 18, 2024

Walkthrough

This pull request introduces IP filtering middleware for the backend application. The changes involve adding new environment variables across different configuration files (.env, .env.production, .env.test) to specify allowed IP ranges and specific IP addresses. A new middleware ipFilter.middleware.js is created to implement IP-based access control, which checks incoming requests against the defined IP restrictions. The server.js file is updated to incorporate this new middleware into the application's request processing pipeline.

Changes

File Change Summary
backend/.env* Added two new environment variables: ALLOWED_IP_RANGE and ALLOWED_IPS to define IP access restrictions
backend/src/middleware/ipFilter.middleware.js New middleware file created with functions to validate and filter IP addresses
backend/src/server.js Added ipFilter middleware to the application, replaced quotes, commented out fileSizeValidator

Sequence Diagram

sequenceDiagram
    Client->>+Server: HTTP Request
    Server->>+IPFilter: Check IP
    alt IP is Allowed
        IPFilter-->>Server: Allow Request
        Server->>+Application: Process Request
    else IP is Not Allowed
        IPFilter-->>Client: 401 Unauthorized
    end
Loading

Possibly Related PRs

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

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.

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

🧹 Nitpick comments (3)
backend/src/middleware/ipFilter.middleware.js (3)

1-5: Beware of potential IPv6 addresses.
Currently, we're forcing IPv4 by stripping out the “::ffff:” prefix. If you expect IPv6 traffic, we could inadvertently cause unauthorized rejections. Consider adding robust IPv6 handling to avoid sweaty palms if your app grows to support IPv6.


7-21: Validate environment input more gracefully.
Parsing the IP range by splitting on “, ” may fail if the environment variable is missing or doesn't follow the exact spacing. Consider a safer approach like .split(",") and trimming each entry.


23-38: Ensure no meltdown with large IP ranges.
Looping over each range is fine for smaller sets, but watch for performance if these ranges expand. We might use an IP range library to avoid sudden mom’s-spaghetti moments under high load.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2f98b and f1cf159.

📒 Files selected for processing (5)
  • backend/.env (1 hunks)
  • backend/.env.production (1 hunks)
  • backend/.env.test (1 hunks)
  • backend/src/middleware/ipFilter.middleware.js (1 hunks)
  • backend/src/server.js (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • backend/.env
  • backend/src/server.js
🔇 Additional comments (2)
backend/.env.production (1)

14-16: Confirm production IPs are correct.
Double-check these ranges and addresses for your real production environment. If they’re misconfigured, you’ll lock out legitimate traffic, and that’s some real spaghetti on your sweater.

backend/.env.test (1)

18-20: Test environment alignment.
Including 127.0.0.1 is great for local testing. Ensure the rest of these addresses and ranges match up with your test scenarios to avoid unexpected blocking.

Copy link
Contributor

@swoopertr swoopertr left a comment

Choose a reason for hiding this comment

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

Checked and tested. works fine.

@swoopertr swoopertr merged commit 7448e08 into develop Dec 19, 2024
2 checks passed
This was referenced Dec 20, 2024
@erenfn erenfn deleted the 397-create-ip-check branch January 16, 2025 23:51
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.

Create IP Check
2 participants