Repository navigation
fix(kernel): rate-limit inbound address rotation and require step-up #142
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -163,8 +163,11 @@ suite('inbound address rotation on PostgreSQL', () => { | |||||||
| await root.end(); | ||||||||
| }); | ||||||||
|
|
||||||||
| // The HTTP app as the API runs it; the RPC caller is whoever `caller` names. | ||||||||
| // The HTTP app as the API runs it; the RPC caller is whoever `caller` names. Rotation is R3 (#113), so the caller | ||||||||
| // has a fresh second factor unless `callerMfa` is false. | ||||||||
| let caller = ''; | ||||||||
| let callerMfa = true; | ||||||||
| const SESSION = '5b0c1f2e-3d4a-4b5c-8d6e-7f8091a2b3c4'; | ||||||||
| let app: ReturnType<typeof createHttpApp>; | ||||||||
| const httpApp = () => | ||||||||
| (app ??= createHttpApp({ | ||||||||
|
|
@@ -182,9 +185,9 @@ suite('inbound address rotation on PostgreSQL', () => { | |||||||
| userId: caller, | ||||||||
| email: 'rot@example.com', | ||||||||
| name: null, | ||||||||
| aal: 'aal1', | ||||||||
| sessionId: randomUUID(), | ||||||||
| mfaAt: null, | ||||||||
| aal: callerMfa ? 'aal2' : 'aal1', | ||||||||
| sessionId: SESSION, | ||||||||
| mfaAt: callerMfa ? Math.floor(Date.now() / 1000) : null, | ||||||||
| }), | ||||||||
| pool, | ||||||||
| aiEnabled: false, | ||||||||
|
|
@@ -263,7 +266,7 @@ suite('inbound address rotation on PostgreSQL', () => { | |||||||
| { token: oldToken, retired: true }, | ||||||||
| { token: newToken, retired: false }, | ||||||||
| ]); | ||||||||
| expect(await rotateAudits(org.orgId)).toEqual([{ actor_id: users.owner, outcome: 'ok', detail: {} }]); | ||||||||
| expect(await rotateAudits(org.orgId)).toMatchObject([{ actor_id: users.owner, outcome: 'ok', detail: { aal: 'aal2', sessionId: SESSION } }]); | ||||||||
| await expect(runtime.query('kernel.org.get', {}, { actor: asUser(users.owner), orgId: org.orgId })).resolves.toMatchObject({ | ||||||||
| inboundAddress: `${newToken}@in.test`, | ||||||||
| }); | ||||||||
|
|
@@ -282,6 +285,14 @@ suite('inbound address rotation on PostgreSQL', () => { | |||||||
| caller = users.viewer; | ||||||||
| expect((await rotate(randomUUID())).status).toBe(403); | ||||||||
| expect(await tokenOf(org.orgId)).toBe(newToken); | ||||||||
| // So is the owner without a fresh second factor (R3, #113): the SPA is told to run an MFA challenge. | ||||||||
| caller = users.owner; | ||||||||
| callerMfa = false; | ||||||||
| const noMfa = await rotate(randomUUID()); | ||||||||
| expect(noMfa.status).toBe(403); | ||||||||
| expect(JSON.stringify(await noMfa.json())).toContain('STEP_UP_REQUIRED'); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Asserting the error response by stringifying the entire JSON and using
Suggested change
|
||||||||
| callerMfa = true; | ||||||||
| expect(await tokenOf(org.orgId)).toBe(newToken); | ||||||||
|
|
||||||||
| // Mail to the new address and to the retired one: the API answers 202 to both (no oracle). | ||||||||
| expect((await deliver(oldToken, '7701')).status).toBe(202); | ||||||||
|
|
@@ -326,7 +337,12 @@ suite('inbound address rotation on PostgreSQL', () => { | |||||||
| const stale = await rotate(key); | ||||||||
| expect(await stale.json()).toEqual({ json: latest }); | ||||||||
| expect(await ledger(org.orgId)).toHaveLength(3); | ||||||||
| expect((await rotateAudits(org.orgId)).map((a) => a.outcome)).toEqual(['ok', 'denied', 'ok']); | ||||||||
| expect((await rotateAudits(org.orgId)).map((a) => [a.outcome, a.detail.code ?? null])).toEqual([ | ||||||||
| ['ok', null], | ||||||||
| ['denied', 'FORBIDDEN'], | ||||||||
| ['denied', 'STEP_UP_REQUIRED'], | ||||||||
| ['ok', null], | ||||||||
| ]); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('drops mail queued for a token that is rotated away before the worker processes it', { timeout: 90_000 }, async () => { | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newly added paragraph contains a hardcoded Vietnamese string. To comply with the project's internationalization (i18n) standards (which use
use-intlas outlined in the architecture plan), this user-facing text should be externalized to the translation files (e.g.,messages/vi.jsonandmessages/en.json) and retrieved using a translation hook.