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(core): Rate limit forgot password endpoint #7604

Merged

Conversation

RicardoE105
Copy link
Contributor

Github issue / Community forum post (link here to close automatically):

@RicardoE105 RicardoE105 changed the title rate limit forgot password endpoint fix(core): rate limit forgot password endpoint Nov 3, 2023
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Nov 3, 2023
@RicardoE105 RicardoE105 changed the title fix(core): rate limit forgot password endpoint fix(API): rate limit forgot password endpoint Nov 3, 2023
@RicardoE105 RicardoE105 changed the title fix(API): rate limit forgot password endpoint fix(API): Rate limit forgot password endpoint Nov 3, 2023
Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

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

Should we also update the frontend to handle 429s and show some other message instead of

Please contact your administrator (problem with your SMTP setup)

@csuermann
Copy link
Contributor

Great PR! Just a few comments:

  • What will the user experience look like when the rate-limit kicks in?
  • We should consider deployment scenarios with more than 1 primary n8n instance and consider externalizing the rate-limiter's state to Redis in those cases
  • Will rate-limiting based on IP addresses also work reliably if requests come in through proxy servers or load balancers? (Docs)

@netroy netroy closed this Nov 3, 2023
@netroy netroy reopened this Nov 3, 2023
@netroy
Copy link
Member

netroy commented Nov 3, 2023

Sorry, clicked on the wrong button.

@RicardoE105
Copy link
Contributor Author

RicardoE105 commented Nov 3, 2023

Great PR! Just a few comments:

  • What will the user experience look like when the rate-limit kicks in?
  • We should consider deployment scenarios with more than 1 primary n8n instance and consider externalizing the rate-limiter's state to Redis in those cases
  • Will rate-limiting based on IP addresses also work reliably if requests come in through proxy servers or load balancers? (Docs)
  1. as it's right now, it would show "Please contact your administrator (problem with your SMTP setup)", but Adi suggested above to show a proper error.
  2. Had a small chat with @netroy about this and this limiting would still work just that each instance would its individual count. @netroy any other thought here?
  3. Ah very good question. Had not thought about this. The solution they present have you find out the numbers of trusted proxy manually?! Will have a sync with the cloud team to see how we can address this at least taking in consideration our infra. This might not be relevant to us if k8 deploys one LB per namespace

@netroy
Copy link
Member

netroy commented Nov 3, 2023

1. as it's right now, it would show "Please contact your administrator (problem with your SMTP setup)", but Adi suggested above to show a proper error.

We don't need a specific error in this case. We should update the frontend to show the "problem with SMTP" error only when there is an actual error with SMTP, and for everything else we could have a generic "Sorry, an error occurred" message.

2. Had a small chat with @netroy about this and this limiting would still work just that each instance would its individual count. @netroy any other thought here?

We could setup the rate-limit-redis package at some point if really needed to, but IMO, we can let each instance rate limit individually. Synchronizing the limits across instances isn't really necessary.

3. Ah very good question. Had not thought about this. The solution they present have you find out the numbers of trusted proxy manually?! Will have a sync with the cloud team to see how we can address this at least taking in consideration our infra. This might not be relevant to us if k8 deploys one LB per namespace

We should update the core app to accept a generic env variable (defaulting to 0) to be passed into express's trust proxy setting.
Let's not make this cloud specific. Cloud instance could simply define this additional env variable, and set it to 1.

RicardoE105 and others added 2 commits November 3, 2023 10:39
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <[email protected]>
Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

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

LGTM.
But, should we also add the new config variable in schema

	proxy_hops: {
		format: Number,
		default: 0,
		env: 'N8N_PROXY_HOPS',
		doc: 'Number of reverse-proxies n8n is running behind',
	},

and update the code after this line to include

const proxyHops = config.getEnv('proxy_hops');
if (proxyHops > 0) this.app.set('trust proxy', proxyHops);

@netroy netroy changed the title fix(API): Rate limit forgot password endpoint feat(core): Rate limit forgot password endpoint Nov 3, 2023
Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

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

I suppose we should make windowMs and limit configurable. But, I also think that these defaults should be enough for almost everyone, and we could consider making these configurable if/when there is an actual demand for it.

Thanks for patching this so quickly 🙏🏽

@RicardoE105
Copy link
Contributor Author

Thanks for all the help @netroy 🙏

Copy link

cypress bot commented Nov 3, 2023

3 flaky tests on run #2726 ↗︎

0 269 0 0 Flakiness 3

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 RicardoE105 🗃️ e2e/*
Project: n8n Commit: edace34aaa
Status: Passed Duration: 10:44 💡
Started: Nov 3, 2023 5:04 PM Ended: Nov 3, 2023 5:15 PM
Flakiness  6-code-node.cy.ts • 2 flaky tests

View Output Video

Test Artifacts
Code node > Code editor > should execute the placeholder successfully in both modes Output Screenshots Video
... > generate code button should have correct state & tooltips Output Screenshots Video
Flakiness  28-resource-mapper.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Resource Mapper > should correctly delete single field Output Screenshots Video

Review all test suite changes for PR #7604 ↗︎

Copy link
Contributor

github-actions bot commented Nov 3, 2023

✅ All Cypress E2E specs passed

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (0bd4e74) 33.87% compared to head (edace34) 32.03%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7604      +/-   ##
==========================================
- Coverage   33.87%   32.03%   -1.85%     
==========================================
  Files        3408     3410       +2     
  Lines      208643   208693      +50     
  Branches    22568    22656      +88     
==========================================
- Hits        70680    66845    -3835     
- Misses     136808   140683    +3875     
- Partials     1155     1165      +10     
Files Coverage Δ
packages/cli/src/config/schema.ts 83.33% <ø> (ø)
...es/cli/src/controllers/passwordReset.controller.ts 75.00% <100.00%> (+0.43%) ⬆️
packages/cli/src/AbstractServer.ts 48.54% <50.00%> (+0.02%) ⬆️
...kages/editor-ui/src/views/ForgotMyPasswordView.vue 0.00% <0.00%> (-28.85%) ⬇️

... and 65 files with indirect coverage changes

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

@RicardoE105 RicardoE105 merged commit 5790e25 into master Nov 3, 2023
17 of 18 checks passed
@RicardoE105 RicardoE105 deleted the ado-1327-tech-debt-email-bombing-via-forgot-password branch November 3, 2023 17:44
@RicardoE105 RicardoE105 restored the ado-1327-tech-debt-email-bombing-via-forgot-password branch November 3, 2023 19:13
@github-actions github-actions bot mentioned this pull request Nov 8, 2023
ivov added a commit that referenced this pull request Nov 8, 2023
#
[1.16.0](https://github.com/n8n-io/n8n/compare/[email protected]@1.16.0)
(2023-11-08)


### Bug Fixes

* **core:** Comply with custom default for workflow saving settings
([#7634](#7634))
([48c068f](48c068f))
* **core:** Decrease reset password token expire time
([#7598](#7598))
([2aa7f63](2aa7f63))
* **core:** Ensure `init` before checking leader or follower in
multi-main scenario ([#7621](#7621))
([a994ba5](a994ba5))
* **core:** Ensure pruning starts only after migrations have completed
([#7626](#7626))
([f748de9](f748de9))
* **core:** Fix accessor error when running partial execution
([#7618](#7618))
([26361df](26361df)),
closes [#6229](#6229)
* **core:** Make password-reset urls valid only for single-use
([#7622](#7622))
([6031424](6031424))
* **Crypto Node:** Fix issue with value not appearing for Sign action
([#7619](#7619))
([5df583f](5df583f))
* **editor:** Allow overriding theme from query params
([#7591](#7591))
([2854a0c](2854a0c))
* **editor:** Fix issue that frontend breaks with unkown nodes
([#7596](#7596))
([db56a9e](db56a9e))
* **editor:** Fix local storage flags defaulting to undefined string
([#7603](#7603))
([151e60f](151e60f))
* **editor:** Fix workflow history prune time limit (getting hours
instead of days) ([#7644](#7644))
([3d5a485](3d5a485))
* **editor:** Hide not supported node options
([#7597](#7597))
([b532a7b](b532a7b))
* **editor:** Remove unknown credentials on pasting workflow
([#7582](#7582))
([d633753](d633753))
* **editor:** Reset canvas zoom before workspace reset in node view
([#7625](#7625))
([78b84af](78b84af))
* **editor:** Zoom in/out on canvas the same amount on scroll/gesture
([#7602](#7602))
([c92402a](c92402a))
* **Facebook Lead Ads Trigger Node:** Fix issue with missing scope for
business management ([#7616](#7616))
([32b85ba](32b85ba))


### Features

* **core:** Add the node version to telemetry in node_graph_string
([#7449](#7449))
([59dc36a](59dc36a))
* **core:** Coordinate workflow activation in multiple main scenario in
internal API ([#7566](#7566))
([c857e42](c857e42))
* **core:** Initial support for two-way communication over websockets
([#7570](#7570))
([ac87701](ac87701))
* **core:** Log executed migrations with info level
([#7586](#7586))
([7dac9ab](7dac9ab))
* **core:** Rate limit forgot password endpoint
([#7604](#7604))
([5790e25](5790e25))
* **LinkedIn Node:** Add support for Article thumbnails
([#7489](#7489))
([e6d3d1a](e6d3d1a))
* **NocoDB Node:** Add new data apis and workspace support
([#7329](#7329))
([da2d2a8](da2d2a8))

Co-authored-by: ivov <[email protected]>
@janober
Copy link
Member

janober commented Nov 8, 2023

Got released with [email protected]

@netroy netroy deleted the ado-1327-tech-debt-email-bombing-via-forgot-password branch June 12, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants