Skip to content

Commit

Permalink
sanity check on did part
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Feb 13, 2024
1 parent 9360e24 commit b400fae
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-pds-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- pds-node-v20
- pds-sanity-check
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down
1 change: 1 addition & 0 deletions lexicons/com/atproto/server/reserveSigningKey.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"properties": {
"did": {
"type": "string",
"format": "did",
"description": "The DID to reserve a key for."
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,7 @@ export const schemaDict = {
properties: {
did: {
type: 'string',
format: 'did',
description: 'The DID to reserve a key for.',
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,7 @@ export const schemaDict = {
properties: {
did: {
type: 'string',
format: 'did',
description: 'The DID to reserve a key for.',
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/ozone/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,7 @@ export const schemaDict = {
properties: {
did: {
type: 'string',
format: 'did',
description: 'The DID to reserve a key for.',
},
},
Expand Down
13 changes: 13 additions & 0 deletions packages/pds/src/actor-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path'
import assert from 'assert'
import fs from 'fs/promises'
import * as crypto from '@atproto/crypto'
import { Keypair, ExportableKeypair } from '@atproto/crypto'
Expand Down Expand Up @@ -148,6 +149,7 @@ export class ActorStore {
async reserveKeypair(did?: string): Promise<string> {
let keyLoc: string | undefined
if (did) {
assertSafePathPart(did)
keyLoc = path.join(this.reservedKeyDir, did)
const maybeKey = await loadKey(keyLoc)
if (maybeKey) {
Expand Down Expand Up @@ -259,3 +261,14 @@ export type ActorStoreTransactor = {
record: RecordTransactor
pref: PreferenceTransactor
}

function assertSafePathPart(part: string) {
const normalized = path.normalize(part)
assert(
part === normalized &&
!part.startsWith('.') &&
!part.includes('/') &&
!part.includes('\\'),
`unsafe path part: ${part}`,
)
}
1 change: 1 addition & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3643,6 +3643,7 @@ export const schemaDict = {
properties: {
did: {
type: 'string',
format: 'did',
description: 'The DID to reserve a key for.',
},
},
Expand Down

0 comments on commit b400fae

Please sign in to comment.