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(backend): bypass sig validation #741

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions packages/backend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function envFloat(name: string, value: number): number {
return envValue == null ? value : +envValue
}

// function envBool(name: string, value: boolean): boolean {
// const envValue = process.env[name]
// return envValue == null ? value : Boolean(envValue)
// }
function envBool(name: string, value: boolean): boolean {
const envValue = process.env[name]
return envValue == null ? value : envValue === 'true'
}

export type IAppConfig = typeof Config

Expand Down Expand Up @@ -103,6 +103,7 @@ export const Config = {

signatureSecret: process.env.SIGNATURE_SECRET, // optional
signatureVersion: envInt('SIGNATURE_VERSION', 1),
bypassSignatureValidation: envBool('BYPASS_SIGNATURE_VALIDATION', false),

openPaymentsSpec: envString(
'OPEN_PAYMENTS_SPEC',
Expand Down
14 changes: 8 additions & 6 deletions packages/backend/src/open_payments/auth/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export function createAuthMiddleware({
if (!access) {
ctx.throw(403, 'Insufficient Grant')
}
try {
if (!(await verifySigAndChallenge(grant.key.jwk, ctx))) {
ctx.throw(401, 'Invalid signature')
if (!config.bypassSignatureValidation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Log might be handy when signature validation is being bypassed, could also do an early return to avoid nesting

Copy link
Contributor

Choose a reason for hiding this comment

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

could also do an early return to avoid nesting

I think we do still want the ctx.grant = grant below

try {
if (!(await verifySigAndChallenge(grant.key.jwk, ctx))) {
ctx.throw(401, 'Invalid signature')
}
} catch (e) {
ctx.status = 401
ctx.throw(401, `Invalid signature`)
}
} catch (e) {
ctx.status = 401
ctx.throw(401, `Invalid signature`)
}
await GrantReference.transaction(async (trx: Transaction) => {
const grantRef = await grantReferenceService.get(grant.grant, trx)
Expand Down