Skip to content

Conversation

avishniakov
Copy link
Contributor

@avishniakov avishniakov commented Feb 29, 2024

Describe changes

I fixed the missing rate limit for login API to prevent misuse and too frequent login attempts.

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • If my change requires a change to docs, I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • If my changes require changes to the dashboard, these changes are communicated/requested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Summary by CodeRabbit

  • New Features
    • Introduced rate limiting on authentication requests to enhance security and manage traffic effectively. Users can now make up to 5 requests per minute and 1000 requests per day.

Copy link
Contributor

coderabbitai bot commented Feb 29, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The recent update introduces slowapi as an optional dependency to enhance the server's resilience against abuse. Specifically, it applies rate limiting to authentication endpoints, ensuring they can only be accessed a certain number of times per minute or day. This measure helps protect the server from potential overload or attack by regulating access frequency.

Changes

File Path Change Summary
pyproject.toml Added slowapi as an optional dependency (>=0.1.9).
.../zen_server/routers/auth_endpoints.py Imported Limiter and get_remote_address from slowapi; initialized limiter with Limiter(key_func=get_remote_address); added rate limiting (5/minute;1000/day) to the token function.

🐰✨
In the land of code and might,
A new guard rises, shining bright.
"Slow and steady," it firmly said,
Keeping the server safe, ahead.
With every hop, it sets the pace,
Ensuring all find their rightful place.
🌟🐾

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added internal To filter out internal PRs and issues bug Something isn't working labels Feb 29, 2024
@avishniakov
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

Quickstart template updates in examples/quickstart have been pushed.

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 357f94c and 32c06cb.
Files selected for processing (2)
  • pyproject.toml (1 hunks)
  • src/zenml/zen_server/routers/auth_endpoints.py (3 hunks)
Additional comments: 3
src/zenml/zen_server/routers/auth_endpoints.py (3)
  • 30-31: The import statements for Limiter and get_remote_address from slowapi are correctly placed and follow Python best practices.
  • 80-80: Initializing the limiter instance with Limiter(key_func=get_remote_address) is appropriate for rate limiting based on the client's IP address. This setup is suitable for preventing misuse and excessive login attempts.
  • 262-262: Decorating the token function with @limiter.limit("5/minute;1000/day") effectively implements rate limiting for login attempts. This rate limit is reasonable for preventing brute-force attacks while allowing legitimate users access. Ensure that the chosen rate limits are aligned with the expected usage patterns and consider making them configurable if necessary.

Copy link
Contributor

NLP template updates in examples/e2e_nlp have been pushed.

Copy link
Contributor

@AlexejPenner AlexejPenner left a comment

Choose a reason for hiding this comment

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

🦭 - Looks good as is, feel free to unify with cloud rate limiting

Copy link
Contributor

@stefannica stefannica left a comment

Choose a reason for hiding this comment

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

I love how simple slowapi is. I don't recommend we use fastapi_limiter for this, it's overkill.

I already closed the original vulnerability as informational on account of us not advertising the username/password authentication method as a full-fledged production-grade security scheme. If slowapi doesn't work out, we could also give up and not fix this at all.

@AlexejPenner
Copy link
Contributor

I love how simple slowapi is. I don't recommend we use fastapi_limiter for this, it's overkill.

I already closed the original vulnerability as informational on account of us not advertising the username/password authentication method as a full-fledged production-grade security scheme. If slowapi doesn't work out, we could also give up and not fix this at all.

good catch - forgot about redis

Copy link
Contributor

github-actions bot commented Mar 1, 2024

E2E template updates in examples/e2e have been pushed.

Copy link
Contributor

Quickstart template updates in examples/quickstart have been pushed.

@stefannica stefannica added Highest P0 Security issue severity - P0/Highest P2 Security issue severity - P2/Medium and removed Highest P0 Security issue severity - P0/Highest labels Mar 12, 2024
Copy link
Contributor

@stefannica stefannica left a comment

Choose a reason for hiding this comment

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

Everything looks great. I love the minimalistic limiter implementation, definitely a lot better than having to hack our way into slowapi. I left a couple of comments with improvement suggestions. I leave it up to you if you want to address them or not.

@avishniakov avishniakov merged commit f100a57 into develop Mar 18, 2024
@avishniakov avishniakov deleted the bugfix/OSSK-456-no-rate-limiting-on-login-page-allows-bruteforce-attack branch March 18, 2024 11:59
@avishniakov avishniakov mentioned this pull request Mar 20, 2024
9 tasks
adtygan pushed a commit to adtygan/zenml that referenced this pull request Mar 21, 2024
* set rate limits for login api

* Auto-update of Starter template

* Auto-update of NLP template

* properly handle exceptions

* configurable rates

* Auto-update of E2E template

* relax rate limit for tests

* relax rate limit for tests

* relax rate limit for tests

* relax dev server rate limits

* reduce limiter on successful requests

* relax limit in tests again

* toggle for rate limiting

* darglint

* update docs

* Update docs/book/deploying-zenml/zenml-self-hosted/deploy-with-docker.md

Co-authored-by: Alex Strick van Linschoten <[email protected]>

* Auto-update of Starter template

* use own rate limiter

* lint and docstrings

* check limits before processing request

* review suggestions

* Update src/zenml/zen_server/utils.py

Co-authored-by: Stefan Nica <[email protected]>

* review suggestions

* fix 3.8/3.9

---------

Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Alex Strick van Linschoten <[email protected]>
Co-authored-by: Stefan Nica <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working internal To filter out internal PRs and issues P2 Security issue severity - P2/Medium run-slow-ci security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants