@atproto/pds 0.4.40 → 0.4.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/account-manager/index.d.ts +3 -4
- package/dist/account-manager/index.d.ts.map +1 -1
- package/dist/account-manager/index.js +2 -3
- package/dist/account-manager/index.js.map +1 -1
- package/dist/auth-verifier.d.ts.map +1 -1
- package/dist/auth-verifier.js +11 -9
- package/dist/auth-verifier.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +2 -1
- package/dist/config/config.js.map +1 -1
- package/dist/config/env.d.ts +2 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +2 -1
- package/dist/config/env.js.map +1 -1
- package/dist/lexicon/index.d.ts +2 -0
- package/dist/lexicon/index.d.ts.map +1 -1
- package/dist/lexicon/index.js +4 -0
- package/dist/lexicon/index.js.map +1 -1
- package/dist/lexicon/lexicons.d.ts +32 -0
- package/dist/lexicon/lexicons.d.ts.map +1 -1
- package/dist/lexicon/lexicons.js +32 -0
- package/dist/lexicon/lexicons.js.map +1 -1
- package/dist/lexicon/types/app/bsky/notification/getUnreadCount.d.ts +1 -0
- package/dist/lexicon/types/app/bsky/notification/getUnreadCount.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/notification/listNotifications.d.ts +2 -0
- package/dist/lexicon/types/app/bsky/notification/listNotifications.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/notification/listNotifications.js.map +1 -1
- package/dist/lexicon/types/app/bsky/notification/putPreferences.d.ts +29 -0
- package/dist/lexicon/types/app/bsky/notification/putPreferences.d.ts.map +1 -0
- package/dist/lexicon/types/app/bsky/notification/putPreferences.js +3 -0
- package/dist/lexicon/types/app/bsky/notification/putPreferences.js.map +1 -0
- package/dist/logger.d.ts +3 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +9 -76
- package/dist/logger.js.map +1 -1
- package/dist/oauth/detailed-account-store.d.ts +2 -2
- package/dist/oauth/detailed-account-store.d.ts.map +1 -1
- package/dist/oauth/detailed-account-store.js.map +1 -1
- package/package.json +9 -9
- package/src/account-manager/index.ts +4 -5
- package/src/auth-verifier.ts +18 -9
- package/src/config/config.ts +2 -1
- package/src/config/env.ts +4 -2
- package/src/lexicon/index.ts +12 -0
- package/src/lexicon/lexicons.ts +33 -0
- package/src/lexicon/types/app/bsky/notification/getUnreadCount.ts +1 -0
- package/src/lexicon/types/app/bsky/notification/listNotifications.ts +2 -0
- package/src/lexicon/types/app/bsky/notification/putPreferences.ts +38 -0
- package/src/logger.ts +11 -81
- package/src/oauth/detailed-account-store.ts +2 -2
package/src/logger.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type IncomingMessage } from 'node:http'
|
|
1
2
|
import { stdSerializers } from 'pino'
|
|
2
3
|
import pinoHttp from 'pino-http'
|
|
3
|
-
import { subsystemLogger } from '@atproto/common'
|
|
4
|
+
import { obfuscateHeaders, subsystemLogger } from '@atproto/common'
|
|
4
5
|
|
|
5
6
|
export const dbLogger = subsystemLogger('pds:db')
|
|
6
7
|
export const didCacheLogger = subsystemLogger('pds:did-cache')
|
|
@@ -17,85 +18,14 @@ export const oauthLogger = subsystemLogger('pds:oauth')
|
|
|
17
18
|
export const loggerMiddleware = pinoHttp({
|
|
18
19
|
logger: httpLogger,
|
|
19
20
|
serializers: {
|
|
20
|
-
err:
|
|
21
|
-
|
|
21
|
+
err: (err: unknown) => ({
|
|
22
|
+
code: err?.['code'],
|
|
23
|
+
message: err?.['message'],
|
|
24
|
+
}),
|
|
25
|
+
req: (req: IncomingMessage) => {
|
|
26
|
+
const serialized = stdSerializers.req(req)
|
|
27
|
+
const headers = obfuscateHeaders(serialized.headers)
|
|
28
|
+
return { ...serialized, headers }
|
|
29
|
+
},
|
|
22
30
|
},
|
|
23
31
|
})
|
|
24
|
-
|
|
25
|
-
function errSerializer(err: any) {
|
|
26
|
-
return {
|
|
27
|
-
code: err?.code,
|
|
28
|
-
message: err?.message,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function reqSerializer(req: any) {
|
|
33
|
-
const serialized = stdSerializers.req(req)
|
|
34
|
-
serialized.headers = obfuscateHeaders(serialized.headers)
|
|
35
|
-
return serialized
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function obfuscateHeaders(headers: Record<string, string>) {
|
|
39
|
-
const obfuscatedHeaders: Record<string, string> = {}
|
|
40
|
-
for (const key in headers) {
|
|
41
|
-
if (key.toLowerCase() === 'authorization') {
|
|
42
|
-
obfuscatedHeaders[key] = obfuscateAuthHeader(headers[key])
|
|
43
|
-
} else if (key.toLowerCase() === 'dpop') {
|
|
44
|
-
obfuscatedHeaders[key] = obfuscateJws(headers[key]) || 'Invalid'
|
|
45
|
-
} else {
|
|
46
|
-
obfuscatedHeaders[key] = headers[key]
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return obfuscatedHeaders
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function obfuscateAuthHeader(authHeader: string): string {
|
|
53
|
-
// This is a hot path (runs on every request). Avoid using split() or regex.
|
|
54
|
-
|
|
55
|
-
const spaceIdx = authHeader.indexOf(' ')
|
|
56
|
-
if (spaceIdx === -1) return 'Invalid'
|
|
57
|
-
|
|
58
|
-
const type = authHeader.slice(0, spaceIdx)
|
|
59
|
-
switch (type.toLowerCase()) {
|
|
60
|
-
case 'bearer':
|
|
61
|
-
return `${type} ${obfuscateBearer(authHeader.slice(spaceIdx + 1))}`
|
|
62
|
-
case 'dpop':
|
|
63
|
-
return `${type} ${obfuscateJws(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`
|
|
64
|
-
case 'basic':
|
|
65
|
-
return `${type} ${obfuscateBasic(authHeader.slice(spaceIdx + 1)) || 'Invalid'}`
|
|
66
|
-
default:
|
|
67
|
-
return `Invalid`
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function obfuscateBasic(token: string): null | string {
|
|
72
|
-
if (!token) return null
|
|
73
|
-
const buffer = Buffer.from(token, 'base64')
|
|
74
|
-
if (!buffer.length) return null // Buffer.from will silently ignore invalid base64 chars
|
|
75
|
-
const authHeader = buffer.toString('utf8')
|
|
76
|
-
const colIdx = authHeader.indexOf(':')
|
|
77
|
-
if (colIdx === -1) return null
|
|
78
|
-
const username = authHeader.slice(0, colIdx)
|
|
79
|
-
return `${username}:***`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function obfuscateBearer(token: string): string {
|
|
83
|
-
return obfuscateJws(token) || obfuscateToken(token)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function obfuscateToken(token: string): string {
|
|
87
|
-
return token ? '***' : ''
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function obfuscateJws(token: string): null | string {
|
|
91
|
-
const firstDot = token.indexOf('.')
|
|
92
|
-
if (firstDot === -1) return null
|
|
93
|
-
|
|
94
|
-
const secondDot = token.indexOf('.', firstDot + 1)
|
|
95
|
-
if (secondDot === -1) return null
|
|
96
|
-
|
|
97
|
-
if (token.indexOf('.', secondDot + 1) !== -1) return null
|
|
98
|
-
|
|
99
|
-
// Strip the signature
|
|
100
|
-
return token.slice(0, secondDot) + '.obfuscated'
|
|
101
|
-
}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
AccountInfo,
|
|
3
3
|
AccountStore,
|
|
4
4
|
DeviceId,
|
|
5
|
-
|
|
5
|
+
SignInCredentials,
|
|
6
6
|
} from '@atproto/oauth-provider'
|
|
7
7
|
|
|
8
8
|
import { AccountManager } from '../account-manager/index'
|
|
@@ -50,7 +50,7 @@ export class DetailedAccountStore implements AccountStore {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
async authenticateAccount(
|
|
53
|
-
credentials:
|
|
53
|
+
credentials: SignInCredentials,
|
|
54
54
|
deviceId: DeviceId,
|
|
55
55
|
): Promise<AccountInfo | null> {
|
|
56
56
|
const accountInfo = await this.accountManager.authenticateAccount(
|