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): Use WebCrypto to generate all random numbers and strings #9786

Merged
merged 8 commits into from
Jun 19, 2024

Conversation

netroy
Copy link
Member

@netroy netroy commented Jun 17, 2024

Summary

Math.random is considered insecure.
This PR replaces it with WebCrypto based random number and string generators.

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/SEC-51

Review / Merge checklist

  • PR title and summary are descriptive
  • Tests included

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Jun 17, 2024
Copy link
Contributor

✅ No visual regressions found.

@netroy netroy force-pushed the SEC-51-cryptographically-safe-integers branch from 892d62a to 99402df Compare June 17, 2024 19:02
@netroy netroy changed the title fix(core): Use cryptographically safe random numbers (no-changelog) feat(core): Use WebCrypto to generate all random numbers and strings Jun 17, 2024
Comment on lines -153 to -164
test('PATCH /me/password should fail due to missing MFA token', async () => {
const { user, rawPassword } = await createUserWithMfaEnabled();

const newPassword = randomPassword();

await testServer
.authAgentFor(user)
.patch('/me/password')
.send({ currentPassword: rawPassword, newPassword })
.expect(400);
});

Copy link
Member Author

Choose a reason for hiding this comment

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

@RicardoE105 Can you please confirm if this test was invalid?
The 400 is coming from the new password not passing the password policy, and I don't see any MFA checks in any of the /me endpoints.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw this message. Having a look

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this was mistake. But this raises the question: Should we ask for MFA token if the user tries to update the password when it's logged in? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we ask for MFA token if the user tries to update the password

Yes. we have a ticket for that.

@netroy netroy force-pushed the SEC-51-cryptographically-safe-integers branch from 2fdd17e to ad07c6b Compare June 18, 2024 09:20
@netroy netroy requested a review from despairblue June 18, 2024 09:20
packages/workflow/src/utils.ts Outdated Show resolved Hide resolved
packages/workflow/test/utils.test.ts Outdated Show resolved Hide resolved
packages/workflow/test/utils.test.ts Outdated Show resolved Hide resolved
packages/workflow/test/utils.test.ts Show resolved Hide resolved
@netroy netroy requested a review from despairblue June 19, 2024 07:14
@netroy netroy requested a review from despairblue June 19, 2024 09:14
despairblue
despairblue previously approved these changes Jun 19, 2024
Copy link
Contributor

⚠️ Some Cypress E2E specs are failing, please fix them before merging

Copy link

cypress bot commented Jun 19, 2024

2 flaky tests on run #5586 ↗︎

0 395 0 0 Flakiness 2

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 netroy 🗃️ e2e/*
Project: n8n Commit: 5c51d36e21
Status: Passed Duration: 04:38 💡
Started: Jun 19, 2024 11:18 AM Ended: Jun 19, 2024 11:23 AM
Flakiness  e2e/5-ndv.cy.ts • 2 flaky tests

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Screenshots Video
NDV > Stop listening for trigger event from NDV Screenshots Video

Review all test suite changes for PR #9786 ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@netroy netroy merged commit 65c5609 into master Jun 19, 2024
31 checks passed
@netroy netroy deleted the SEC-51-cryptographically-safe-integers branch June 19, 2024 11:33
This was referenced Jun 20, 2024
@janober
Copy link
Member

janober commented Jun 20, 2024

Got released with [email protected]

1 similar comment
@janober
Copy link
Member

janober commented Jun 20, 2024

Got released with [email protected]

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants