Skip to content

Commit

Permalink
Proper validation of entryway op in account creation (bluesky-social#…
Browse files Browse the repository at this point in the history
…1975)

* ensure entryway plc rotation key

* update plc lib on pds, test
  • Loading branch information
devinivy authored Dec 18, 2023
1 parent 80161e3 commit 16b31e3
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/pds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@atproto/syntax": "workspace:^",
"@atproto/xrpc": "workspace:^",
"@atproto/xrpc-server": "workspace:^",
"@did-plc/lib": "^0.0.1",
"@did-plc/lib": "^0.0.4",
"better-sqlite3": "^7.6.2",
"bytes": "^3.1.2",
"compression": "^1.7.4",
Expand Down
9 changes: 7 additions & 2 deletions packages/pds/src/api/com/atproto/server/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { DidDocument, MINUTE, check } from '@atproto/common'
import { AtprotoData, ensureAtpDocument } from '@atproto/identity'
import { InvalidRequestError } from '@atproto/xrpc-server'
import { ExportableKeypair, Keypair, Secp256k1Keypair } from '@atproto/crypto'
import * as plc from '@did-plc/lib'
import disposable from 'disposable-email'
import {
baseNormalizeAndValidate,
normalizeAndValidateHandle,
} from '../../../../handle'
import * as plc from '@did-plc/lib'
import { Server } from '../../../../lexicon'
import { InputSchema as CreateAccountInput } from '../../../../lexicon/types/com/atproto/server/createAccount'
import AppContext from '../../../../context'
Expand Down Expand Up @@ -101,7 +101,12 @@ const validateInputsForEntrywayPds = async (
'IncompatibleDidDoc',
)
}
await plc.assureValidOp(plcOp)
try {
await plc.assureValidOp(plcOp)
await plc.assureValidSig([plcRotationKey], plcOp)
} catch (err) {
throw new InvalidRequestError('invalid plc operation', 'IncompatibleDidDoc')
}
const doc = plc.formatDidDoc({ did, ...plcOp })
const data = ensureAtpDocument(doc)

Expand Down
23 changes: 23 additions & 0 deletions packages/pds/tests/entryway.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as os from 'node:os'
import * as path from 'node:path'
import * as plcLib from '@did-plc/lib'
import AtpAgent from '@atproto/api'
import { Secp256k1Keypair, randomStr } from '@atproto/crypto'
import { SeedClient, TestPds, TestPlc, mockResolvers } from '@atproto/dev-env'
Expand Down Expand Up @@ -131,6 +132,28 @@ describe('entryway', () => {
expect(accountFromPds?.handle).toEqual('alice3.test')
expect(accountFromEntryway?.handle).toEqual('alice3.test')
})

it('does not allow bringing own op to account creation.', async () => {
const {
data: { signingKey },
} = await pdsAgent.api.com.atproto.server.reserveSigningKey({})
const rotationKey = await Secp256k1Keypair.create()
const plcCreate = await plcLib.createOp({
signingKey,
rotationKeys: [rotationKey.did(), entryway.ctx.plcRotationKey.did()],
handle: 'weirdalice.test',
pds: pds.ctx.cfg.service.publicUrl,
signer: rotationKey,
})
const tryCreateAccount = pdsAgent.api.com.atproto.server.createAccount(
{ did: plcCreate.did, plcOp: plcCreate.op, handle: 'weirdalice.test' },
{
headers: SeedClient.getHeaders(accessToken),
encoding: 'application/json',
},
)
await expect(tryCreateAccount).rejects.toThrow('invalid plc operation')
})
})

const createEntryway = async (
Expand Down
90 changes: 72 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 16b31e3

Please sign in to comment.