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: verify legitimate claim↔︎redeem by assigning a random phrase during email validation #747

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/access-api/postmark/welcome.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

<p>Hi {{email}}! To complete your {{product_name}} registration, we just need to verify your email address.</p>
<p>Before clicking the button below, please confirm the app you are trying to register is showing this phrase: <code>{{match_phrase}}</code></p>
<!-- Action -->
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
Expand Down
6 changes: 5 additions & 1 deletion packages/access-api/postmark/welcome.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Hi {{email}}! To complete your {{product_name}} registration,
we just need to verify your email address.

Please visit the following link in your web browser:
Please confirm the app you are trying to register is showing this phrase:

{{match_phrase}}

If it is, please visit the following link in your web browser:

{{action_url}}

Expand Down
4 changes: 4 additions & 0 deletions packages/access-api/src/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { voucherClaimProvider } from './voucher-claim.js'
import { voucherRedeemProvider } from './voucher-redeem.js'
import * as uploadApi from './upload-api-proxy.js'
import { accessAuthorizeProvider } from './access-authorize.js'
import { generateNoncePhrase } from '../utils/phrase.js'
import { accessDelegateProvider } from './access-delegate.js'
import { accessClaimProvider } from './access-claim.js'
import { providerAddProvider } from './provider-add.js'
Expand Down Expand Up @@ -195,6 +196,7 @@ export function service(ctx) {

const encoded = delegationToString(inv)
const url = `${ctx.url.protocol}//${ctx.url.host}/validate-email?ucan=${encoded}&mode=recover`
const nonce = generateNoncePhrase()

// For testing
if (ctx.config.ENV === 'test') {
Expand All @@ -204,7 +206,9 @@ export function service(ctx) {
await ctx.email.sendValidation({
to: capability.nb.identity.replace('mailto:', ''),
url,
nonce,
})
return { matchPhrase: nonce }
}
),
},
Expand Down
4 changes: 4 additions & 0 deletions packages/access-api/src/service/voucher-claim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Server from '@ucanto/server'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { delegationToString } from '@web3-storage/access/encoding'
import { generateNoncePhrase } from '../utils/phrase.js'

/**
* @param {import('../bindings').RouteContext} ctx
Expand Down Expand Up @@ -41,10 +42,13 @@ export function voucherClaimProvider(ctx) {
}

const url = `${ctx.url.protocol}//${ctx.url.host}/validate-email?ucan=${encoded}`
const nonce = generateNoncePhrase()

await ctx.email.sendValidation({
to: capability.nb.identity.replace('mailto:', ''),
url,
nonce,
})
return { matchPhrase: nonce }
})
}
2 changes: 2 additions & 0 deletions packages/access-api/src/utils/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const debug = () => new DebugEmail()
* @typedef ValidationEmailSend
* @property {string} to
* @property {string} url
* @property {string} nonce
*/

/**
Expand Down Expand Up @@ -44,6 +45,7 @@ export class Email {
product_name: 'Web3 Storage',
email: opts.to,
action_url: opts.url,
match_phrase: opts.nonce,
},
}),
})
Expand Down
Loading