Skip to content

Commit

Permalink
feat(auth): Make sig validation not processed in dev mode (#683)
Browse files Browse the repository at this point in the history
* feat: bypass as signature check

* remove test import

Co-authored-by: Brandon Wilson <[email protected]>

* chore(auth): fix formatting

* fix(auth): add missing test call

* fix(auth): add tests, reset config

* refactor: update config

Co-authored-by: Brandon Wilson <[email protected]>

* refactor: prefer done over isdone

Co-authored-by: Brandon Wilson <[email protected]>

* refactor: remove extra test

* fix(auth): make tests work by punting on done

Co-authored-by: Brandon Wilson <[email protected]>

* chore(auth): reset default bypassSignatureValidation via @wilsonianb

* chore(auth): allow multiple configs in tests

Co-authored-by: Brandon Wilson <[email protected]>
  • Loading branch information
mankins and wilsonianb authored Nov 3, 2022
1 parent 3807051 commit 8898075
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- "5432:5432"
environment:
POSTGRES_PASSWORD: password
BYPASS_SIGNATURE_VALIDATION: false
redis:
image: "redis:7"
restart: unless-stopped
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ export const Config = {
databaseCleanupWorkers: envInt('DATABASE_CLEANUP_WORKERS', 1),
accessTokenDeletionDays: envInt('ACCESS_TOKEN_DELETION_DAYS', 30),
introspectionHttpsig: envBool('INTROSPECTION_HTTPSIG', false),
incomingPaymentInteraction: envBool('INCOMING_PAYMENT_INTERACTION', false)
incomingPaymentInteraction: envBool('INCOMING_PAYMENT_INTERACTION', false),
bypassSignatureValidation: envBool('BYPASS_SIGNATURE_VALIDATION', false)
}
59 changes: 56 additions & 3 deletions packages/auth/src/signature/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {

describe('Signature Service', (): void => {
let deps: IocContract<AppServices>
let appContainer: TestContainer
const appContainers: TestContainer[] = []

let keyPath: string
let publicKey: JWKWithRequired
let privateKey: JWKWithRequired
Expand All @@ -43,7 +44,8 @@ describe('Signature Service', (): void => {

beforeAll(async (): Promise<void> => {
deps = await initIocContainer(Config)
appContainer = await createTestApp(deps)
const appContainer = await createTestApp(deps)
appContainers.push(appContainer)

const keys = await generateTestKeys()
keyPath = '/' + keys.keyId
Expand All @@ -57,7 +59,9 @@ describe('Signature Service', (): void => {

afterAll(async (): Promise<void> => {
nock.restore()
await appContainer.shutdown()
for (let i = 0; i < appContainers.length; i++) {
await appContainers[i].shutdown()
}
})

describe('signatures', (): void => {
Expand Down Expand Up @@ -401,6 +405,55 @@ describe('Signature Service', (): void => {
scope.isDone()
})

test('middleware succeeds if BYPASS_SIGNATURE_VALIDATION is true with bad signature', async (): Promise<void> => {
const altDeps = await initIocContainer({
...Config,
bypassSignatureValidation: true
})

const altContainer = await createTestApp(altDeps)
appContainers.push(altContainer)

nock(KEY_REGISTRY_ORIGIN)
.get(keyPath)
.reply(200, {
jwk: testClientKey.jwk,
client: TEST_CLIENT
} as ClientKey)

const ctx = await createContextWithSigHeaders(
{
headers: {
Accept: 'application/json'
},
url: '/',
method: 'POST'
},
{},
{
client: {
display: TEST_CLIENT_DISPLAY,
key: {
proof: 'httpsig',
jwk: testClientKey.jwk
}
}
},
privateKey,
altDeps
)

ctx.headers['signature'] = 'wrong-signature'

await grantInitiationHttpsigMiddleware(ctx, next)

expect(ctx.response.status).toEqual(200)
expect(next).toHaveBeenCalled()

// TODO: https://github.com/interledger/rafiki/issues/656
// scope.done()
})

test('middleware fails if client is invalid', async (): Promise<void> => {
const ctx = await createContextWithSigHeaders(
{
Expand Down
6 changes: 6 additions & 0 deletions packages/auth/src/signature/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ async function verifySigAndChallenge(
clientKey: JWKWithRequired,
ctx: HttpSigContext
): Promise<boolean> {
const config = await ctx.container.use('config')
if (config.bypassSignatureValidation) {
// bypass
return true
}

const sig = ctx.headers['signature'] as string
const sigInput = ctx.headers['signature-input'] as string
const challenge = sigInputToChallenge(sigInput, ctx)
Expand Down

0 comments on commit 8898075

Please sign in to comment.