@atproto/oauth-provider 0.6.3 → 0.6.4

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atproto/oauth-provider
2
2
 
3
+ ## 0.6.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3690](https://github.com/bluesky-social/atproto/pull/3690) [`9b28184cb`](https://github.com/bluesky-social/atproto/commit/9b28184cb9c417173f46cfb5824dc197dec3e069) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose hcaptcha tokens in hook and errors
8
+
9
+ - [#3690](https://github.com/bluesky-social/atproto/pull/3690) [`9b28184cb`](https://github.com/bluesky-social/atproto/commit/9b28184cb9c417173f46cfb5824dc197dec3e069) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove hcaptcha hostname check
10
+
3
11
  ## 0.6.3
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"account-manager.d.ts","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAEtB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AAEjD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAGzE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,EACZ,wBAAwB,EACxB,wBAAwB,EACxB,UAAU,EACX,MAAM,oBAAoB,CA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C,IAAI,CAAC;CAKrE"}
@@ -28,8 +28,9 @@ class AccountManager {
28
28
  if (!input.hcaptchaToken) {
29
29
  throw new invalid_request_error_js_1.InvalidRequestError('hCaptcha token is required');
30
30
  }
31
+ const tokens = this.hcaptchaClient.buildClientTokens(deviceMetadata.ipAddress, input.handle, deviceMetadata.userAgent);
31
32
  const result = await this.hcaptchaClient
32
- .verify('signup', input.hcaptchaToken, deviceMetadata.ipAddress, input.handle, deviceMetadata.userAgent)
33
+ .verify('signup', input.hcaptchaToken, deviceMetadata.ipAddress, tokens)
33
34
  .catch((err) => {
34
35
  throw invalid_request_error_js_1.InvalidRequestError.from(err, 'hCaptcha verification failed');
35
36
  });
@@ -37,10 +38,11 @@ class AccountManager {
37
38
  input,
38
39
  deviceId,
39
40
  deviceMetadata,
41
+ tokens,
40
42
  result,
41
43
  });
42
44
  try {
43
- this.hcaptchaClient.checkVerifyResult(result);
45
+ this.hcaptchaClient.checkVerifyResult(result, tokens);
44
46
  }
45
47
  catch (err) {
46
48
  throw invalid_request_error_js_1.InvalidRequestError.from(err, 'hCaptcha verification failed');
@@ -1 +1 @@
1
- {"version":3,"file":"account-manager.js","sourceRoot":"","sources":["../../src/account/account-manager.ts"],"names":[],"mappings":";;;AAAA,sDAG6B;AAG7B,iFAAwE;AACxE,oDAAyE;AACzE,yDAAmD;AACnD,iDAAkD;AAgBlD,MAAM,8BAA8B,GAAG,GAAG,CAAA;AAC1C,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAExC,MAAa,cAAc;IAMJ;IACA;IANF,kBAAkB,CAAS;IAC3B,cAAc,CAAiB;IAElD,YACE,MAA6B,EACV,KAAmB,EACnB,KAAiB,EACpC,aAA4B;QAFT,UAAK,GAAL,KAAK,CAAc;QACnB,UAAK,GAAL,KAAK,CAAY;QAGpC,IAAI,CAAC,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,KAAK,KAAK,CAAA;QACpE,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,QAAQ;Y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,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IACxE,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,QAAkB;QAClC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QAC7D,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC3D,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,IAA8B;QAC9D,OAAO,IAAA,sBAAY,EAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC7D,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,IAA8B;QAC9D,OAAO,IAAA,sBAAY,EAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC7D,MAAM,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,MAAc;QAClD,OAAO,IAAA,sBAAY,EAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;YAC7D,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAhND,wCAgNC"}
@@ -147,12 +147,17 @@ export declare const hcaptchaVerifyResultSchema: z.ZodObject<{
147
147
  tags?: string[] | undefined;
148
148
  }>;
149
149
  export type HcaptchaVerifyResult = z.infer<typeof hcaptchaVerifyResultSchema>;
150
+ export type HcaptchaClientTokens = {
151
+ hashedIp: string;
152
+ hashedHandle: string;
153
+ hashedUserAgent?: string;
154
+ };
150
155
  export declare class HCaptchaClient {
151
156
  readonly hostname: string;
152
157
  readonly config: HcaptchaConfig;
153
158
  protected readonly fetch: FetchBound;
154
159
  constructor(hostname: string, config: HcaptchaConfig, fetch?: Fetch);
155
- verify(behaviorType: 'login' | 'signup', response: string, remoteip: string, handle: string, userAgent?: string): Promise<{
160
+ verify(behaviorType: 'login' | 'signup', response: string, remoteip: string, clientTokens: HcaptchaClientTokens): Promise<{
156
161
  hostname: string | null;
157
162
  success: boolean;
158
163
  challenge_ts: string;
@@ -171,11 +176,13 @@ export declare class HCaptchaClient {
171
176
  sigs?: Record<string, unknown> | undefined;
172
177
  tags?: string[] | undefined;
173
178
  }>;
174
- checkVerifyResult(result: HcaptchaVerifyResult): void;
179
+ checkVerifyResult(result: HcaptchaVerifyResult, tokens: HcaptchaClientTokens): void;
180
+ buildClientTokens(remoteip: string, handle: string, userAgent?: string): HcaptchaClientTokens;
175
181
  protected hashToken(value: string): string;
176
182
  }
177
- export declare class HCaptchaVerificationError extends Error {
183
+ export declare class HCaptchaVerifyError extends Error {
178
184
  readonly result: HcaptchaVerifyResult;
179
- constructor(result: HcaptchaVerifyResult, message?: string);
185
+ readonly tokens: HcaptchaClientTokens;
186
+ constructor(result: HcaptchaVerifyResult, tokens: HcaptchaClientTokens, message?: string);
180
187
  }
181
188
  //# sourceMappingURL=hcaptcha.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hcaptcha.d.ts","sourceRoot":"","sources":["../../src/lib/hcaptcha.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,KAAK,EACL,UAAU,EAKX,MAAM,qBAAqB,CAAA;AAG5B,eAAO,MAAM,mBAAmB,aAAoB,CAAA;AACpD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,eAAO,MAAM,oBAAoB;IAC/B;;OAEG;;IAEH;;OAE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,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,EAC/B,KAAK,GAAE,KAAwB;IAKpB,MAAM,CACjB,YAAY,EAAE,OAAO,GAAG,QAAQ,EAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;IAkB7B,iBAAiB,CACtB,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,IAAI;IAmCA,iBAAiB,CACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,oBAAoB;IAQvB,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM;CAMlC;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAE1C,QAAQ,CAAC,MAAM,EAAE,oBAAoB;IACrC,QAAQ,CAAC,MAAM,EAAE,oBAAoB;gBAD5B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,oBAAoB,EACrC,OAAO,CAAC,EAAE,MAAM;CAInB"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HCaptchaVerificationError = exports.HCaptchaClient = exports.hcaptchaVerifyResultSchema = exports.hcaptchaConfigSchema = exports.hcaptchaTokenSchema = void 0;
3
+ exports.HCaptchaVerifyError = exports.HCaptchaClient = exports.hcaptchaVerifyResultSchema = exports.hcaptchaConfigSchema = exports.hcaptchaTokenSchema = void 0;
4
4
  const node_crypto_1 = require("node:crypto");
5
5
  const zod_1 = require("zod");
6
6
  const fetch_1 = require("@atproto-labs/fetch");
@@ -113,7 +113,7 @@ class HCaptchaClient {
113
113
  this.config = config;
114
114
  this.fetch = (0, fetch_1.bindFetch)(fetch);
115
115
  }
116
- async verify(behaviorType, response, remoteip, handle, userAgent) {
116
+ async verify(behaviorType, response, remoteip, clientTokens) {
117
117
  return this.fetch('https://api.hcaptcha.com/siteverify', {
118
118
  method: 'POST',
119
119
  headers: {
@@ -125,36 +125,38 @@ class HCaptchaClient {
125
125
  behavior_type: behaviorType,
126
126
  response,
127
127
  remoteip,
128
- client_tokens: JSON.stringify({
129
- hashedIp: this.hashToken(remoteip),
130
- hashedHandle: this.hashToken(handle),
131
- hashedUserAgent: userAgent ? this.hashToken(userAgent) : undefined,
132
- }),
128
+ client_tokens: JSON.stringify(clientTokens),
133
129
  }).toString(),
134
130
  }).then(fetchSuccessHandler);
135
131
  }
136
- checkVerifyResult(result) {
137
- const { success, hostname, score } = result;
132
+ checkVerifyResult(result, tokens) {
133
+ const { success, score } = result;
138
134
  if (success !== true) {
139
- throw new HCaptchaVerificationError(result, 'Expected success to be true');
140
- }
141
- if (
142
- // Ignore if enterprise feature is not enabled
143
- hostname != null &&
144
- // Fool-proofing: If this is false, the user is trying to use a token
145
- // generated for the same siteKey, but on another domain.
146
- hostname !== this.hostname) {
147
- throw new HCaptchaVerificationError(result, `Hostname ${hostname} does not match ${this.hostname}`);
135
+ throw new HCaptchaVerifyError(result, tokens, 'Expected success to be true');
148
136
  }
137
+ // https://docs.hcaptcha.com/#verify-the-user-response-server-side
138
+ // Please [...] note that the hostname field is derived from the user's
139
+ // browser, and should not be used for authentication of any kind; it is
140
+ // primarily useful as a statistical metric. Additionally, in the event that
141
+ // your site experiences unusually high challenge traffic, the hostname
142
+ // field may be returned as "not-provided" rather than the usual value; all
143
+ // other fields will return their normal values.
149
144
  if (
150
145
  // Ignore if enterprise feature is not enabled
151
146
  score != null &&
152
147
  // Ignore if disabled through config
153
148
  this.config.scoreThreshold != null &&
154
149
  score >= this.config.scoreThreshold) {
155
- throw new HCaptchaVerificationError(result, `Score ${score} is above the threshold ${this.config.scoreThreshold}`);
150
+ throw new HCaptchaVerifyError(result, tokens, `Score ${score} is above the threshold ${this.config.scoreThreshold}`);
156
151
  }
157
152
  }
153
+ buildClientTokens(remoteip, handle, userAgent) {
154
+ return {
155
+ hashedIp: this.hashToken(remoteip),
156
+ hashedHandle: this.hashToken(handle),
157
+ hashedUserAgent: userAgent ? this.hashToken(userAgent) : undefined,
158
+ };
159
+ }
158
160
  hashToken(value) {
159
161
  const hash = (0, node_crypto_1.createHash)('sha256');
160
162
  hash.update(this.config.tokenSalt);
@@ -163,12 +165,14 @@ class HCaptchaClient {
163
165
  }
164
166
  }
165
167
  exports.HCaptchaClient = HCaptchaClient;
166
- class HCaptchaVerificationError extends Error {
168
+ class HCaptchaVerifyError extends Error {
167
169
  result;
168
- constructor(result, message) {
170
+ tokens;
171
+ constructor(result, tokens, message) {
169
172
  super(message);
170
173
  this.result = result;
174
+ this.tokens = tokens;
171
175
  }
172
176
  }
173
- exports.HCaptchaVerificationError = HCaptchaVerificationError;
177
+ exports.HCaptchaVerifyError = HCaptchaVerifyError;
174
178
  //# sourceMappingURL=hcaptcha.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hcaptcha.js","sourceRoot":"","sources":["../../src/lib/hcaptcha.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,6BAAuB;AACvB,+CAO4B;AAC5B,6CAAyC;AAE5B,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAGvC,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C;;OAEG;IACH,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B;;OAEG;IACH,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B;;OAEG;IACH,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B;;;;;;OAMG;IACH,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAA;AAGF;;GAEG;AACU,QAAA,0BAA0B,GAAG,OAAC,CAAC,MAA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AC,cAAc,IAAI,IAAI;YAClC,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EACnC,CAAC;YACD,MAAM,IAAI,mBAAmB,CAC3B,MAAM,EACN,MAAM,EACN,SAAS,KAAK,2BAA2B,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CACtE,CAAA;QACH,CAAC;IACH,CAAC;IAEM,iBAAiB,CACtB,QAAgB,EAChB,MAAc,EACd,SAAkB;QAElB,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;YAClC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACpC,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;SACnE,CAAA;IACH,CAAC;IAES,SAAS,CAAC,KAAa;QAC/B,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAA;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QAClC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAClB,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IACzC,CAAC;CACF;AAxFD,wCAwFC;AAED,MAAa,mBAAoB,SAAQ,KAAK;IAEjC;IACA;IAFX,YACW,MAA4B,EAC5B,MAA4B,EACrC,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAA;QAJL,WAAM,GAAN,MAAM,CAAsB;QAC5B,WAAM,GAAN,MAAM,CAAsB;IAIvC,CAAC;CACF;AARD,kDAQC"}
@@ -8,12 +8,12 @@ import { ClientId } from './client/client-id.js';
8
8
  import { ClientInfo } from './client/client-info.js';
9
9
  import { Client } from './client/client.js';
10
10
  import { InvalidRequestError } from './errors/invalid-request-error.js';
11
- import { HcaptchaConfig, HcaptchaVerifyResult } from './lib/hcaptcha.js';
11
+ import { HcaptchaClientTokens, HcaptchaConfig, HcaptchaVerifyResult } from './lib/hcaptcha.js';
12
12
  import { RequestMetadata } from './lib/http/request.js';
13
13
  import { Awaitable } from './lib/util/type.js';
14
14
  import { AccessDeniedError, OAuthError } from './oauth-errors.js';
15
15
  import { DeviceAccountInfo, DeviceId, SignUpData } from './oauth-store.js';
16
- export { AccessDeniedError, type Account, type Awaitable, Client, type ClientAuth, type ClientId, type ClientInfo, type DeviceAccountInfo, type DeviceId, type HcaptchaConfig, type HcaptchaVerifyResult, InvalidRequestError, type Jwks, type OAuthAuthorizationDetails, type OAuthAuthorizationRequestParameters, type OAuthClientMetadata, OAuthError, type OAuthTokenResponse, type RequestMetadata, type SignInData, type SignUpData, type SignUpInput, };
16
+ export { AccessDeniedError, type Account, type Awaitable, Client, type ClientAuth, type ClientId, type ClientInfo, type DeviceAccountInfo, type DeviceId, type HcaptchaClientTokens, type HcaptchaConfig, type HcaptchaVerifyResult, InvalidRequestError, type Jwks, type OAuthAuthorizationDetails, type OAuthAuthorizationRequestParameters, type OAuthClientMetadata, OAuthError, type OAuthTokenResponse, type RequestMetadata, type SignInData, type SignUpData, type SignUpInput, };
17
17
  export type OAuthHooks = {
18
18
  /**
19
19
  * Use this to alter, override or validate the client metadata & jwks returned
@@ -48,10 +48,15 @@ export type OAuthHooks = {
48
48
  deviceId: DeviceId;
49
49
  deviceMetadata: RequestMetadata;
50
50
  }) => Awaitable<void>;
51
+ /**
52
+ * This hook is called when a user attempts to sign up, after the hcaptcha
53
+ * `/siteverify` request has been made (and before the result is validated).
54
+ */
51
55
  onHcaptchaResult?: (data: {
52
56
  input: SignUpInput;
53
57
  deviceId: DeviceId;
54
58
  deviceMetadata: RequestMetadata;
59
+ tokens: HcaptchaClientTokens;
55
60
  result: HcaptchaVerifyResult;
56
61
  }) => Awaitable<void>;
57
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-hooks.d.ts","sourceRoot":"","sources":["../src/oau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AAI,CAAC,CAAA;CACtB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-hooks.js","sourceRoot":"","sources":["../src/oauth-hooks.ts"],"names":[],"mappings":";;;AAaA,kDAA2C;AAazC,uFAbO,kBAAM,OAaP;AAZR,gFAAuE;AAoBrE,oGApBO,8CAAmB,OAoBP;AAhBrB,uDAAiE;AAK/D,kGALO,mCAAiB,OAKP;AAgBjB,2FArB0B,4BAAU,OAqB1B"}
1
+ {"version":3,"file":"oauth-hooks.js","sourceRoot":"","sources":["../src/oauth-hooks.ts"],"names":[],"mappings":";;;AAaA,kDAA2C;AAiBzC,uFAjBO,kBAAM,OAiBP;AAhBR,gFAAuE;AAyBrE,oGAzBO,8CAAmB,OAyBP;AAjBrB,uDAAiE;AAK/D,kGALO,mCAAiB,OAKP;AAiBjB,2FAtB0B,4BAAU,OAsB1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/oauth-provider",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "license": "MIT",
5
5
  "description": "Generic OAuth2 and OpenID Connect provider for Node.js. Currently only supports features needed for Atproto.",
6
6
  "keywords": [
@@ -45,8 +45,8 @@
45
45
  "zod": "^3.23.8",
46
46
  "@atproto-labs/fetch": "0.2.2",
47
47
  "@atproto-labs/fetch-node": "0.1.8",
48
- "@atproto-labs/simple-store": "0.1.2",
49
48
  "@atproto-labs/pipe": "0.1.0",
49
+ "@atproto-labs/simple-store": "0.1.2",
50
50
  "@atproto-labs/simple-store-memory": "0.1.2",
51
51
  "@atproto/common": "^0.4.8",
52
52
  "@atproto/jwk": "0.1.4",
@@ -55,14 +55,14 @@ export class AccountManager {
55
55
  throw new InvalidRequestError('hCaptcha token is required')
56
56
  }
57
57
 
58
+ const tokens = this.hcaptchaClient.buildClientTokens(
59
+ deviceMetadata.ipAddress,
60
+ input.handle,
61
+ deviceMetadata.userAgent,
62
+ )
63
+
58
64
  const result = await this.hcaptchaClient
59
- .verify(
60
- 'signup',
61
- input.hcaptchaToken,
62
- deviceMetadata.ipAddress,
63
- input.handle,
64
- deviceMetadata.userAgent,
65
- )
65
+ .verify('signup', input.hcaptchaToken, deviceMetadata.ipAddress, tokens)
66
66
  .catch((err) => {
67
67
  throw InvalidRequestError.from(err, 'hCaptcha verification failed')
68
68
  })
@@ -71,11 +71,12 @@ export class AccountManager {
71
71
  input,
72
72
  deviceId,
73
73
  deviceMetadata,
74
+ tokens,
74
75
  result,
75
76
  })
76
77
 
77
78
  try {
78
- this.hcaptchaClient.checkVerifyResult(result)
79
+ this.hcaptchaClient.checkVerifyResult(result, tokens)
79
80
  } catch (err) {
80
81
  throw InvalidRequestError.from(err, 'hCaptcha verification failed')
81
82
  }
@@ -115,6 +115,12 @@ export const hcaptchaVerifyResultSchema = z.object({
115
115
 
116
116
  export type HcaptchaVerifyResult = z.infer<typeof hcaptchaVerifyResultSchema>
117
117
 
118
+ export type HcaptchaClientTokens = {
119
+ hashedIp: string
120
+ hashedHandle: string
121
+ hashedUserAgent?: string
122
+ }
123
+
118
124
  const fetchSuccessHandler = pipe(
119
125
  fetchOkProcessor(),
120
126
  fetchJsonProcessor(),
@@ -135,8 +141,7 @@ export class HCaptchaClient {
135
141
  behaviorType: 'login' | 'signup',
136
142
  response: string,
137
143
  remoteip: string,
138
- handle: string,
139
- userAgent?: string,
144
+ clientTokens: HcaptchaClientTokens,
140
145
  ) {
141
146
  return this.fetch('https://api.hcaptcha.com/siteverify', {
142
147
  method: 'POST',
@@ -149,35 +154,34 @@ export class HCaptchaClient {
149
154
  behavior_type: behaviorType,
150
155
  response,
151
156
  remoteip,
152
- client_tokens: JSON.stringify({
153
- hashedIp: this.hashToken(remoteip),
154
- hashedHandle: this.hashToken(handle),
155
- hashedUserAgent: userAgent ? this.hashToken(userAgent) : undefined,
156
- }),
157
+ client_tokens: JSON.stringify(clientTokens),
157
158
  }).toString(),
158
159
  }).then(fetchSuccessHandler)
159
160
  }
160
161
 
161
- public checkVerifyResult(result: HcaptchaVerifyResult): void {
162
- const { success, hostname, score } = result
162
+ public checkVerifyResult(
163
+ result: HcaptchaVerifyResult,
164
+ tokens: HcaptchaClientTokens,
165
+ ): void {
166
+ const { success, score } = result
163
167
 
164
168
  if (success !== true) {
165
- throw new HCaptchaVerificationError(result, 'Expected success to be true')
166
- }
167
-
168
- if (
169
- // Ignore if enterprise feature is not enabled
170
- hostname != null &&
171
- // Fool-proofing: If this is false, the user is trying to use a token
172
- // generated for the same siteKey, but on another domain.
173
- hostname !== this.hostname
174
- ) {
175
- throw new HCaptchaVerificationError(
169
+ throw new HCaptchaVerifyError(
176
170
  result,
177
- `Hostname ${hostname} does not match ${this.hostname}`,
171
+ tokens,
172
+ 'Expected success to be true',
178
173
  )
179
174
  }
180
175
 
176
+ // https://docs.hcaptcha.com/#verify-the-user-response-server-side
177
+
178
+ // Please [...] note that the hostname field is derived from the user's
179
+ // browser, and should not be used for authentication of any kind; it is
180
+ // primarily useful as a statistical metric. Additionally, in the event that
181
+ // your site experiences unusually high challenge traffic, the hostname
182
+ // field may be returned as "not-provided" rather than the usual value; all
183
+ // other fields will return their normal values.
184
+
181
185
  if (
182
186
  // Ignore if enterprise feature is not enabled
183
187
  score != null &&
@@ -185,13 +189,26 @@ export class HCaptchaClient {
185
189
  this.config.scoreThreshold != null &&
186
190
  score >= this.config.scoreThreshold
187
191
  ) {
188
- throw new HCaptchaVerificationError(
192
+ throw new HCaptchaVerifyError(
189
193
  result,
194
+ tokens,
190
195
  `Score ${score} is above the threshold ${this.config.scoreThreshold}`,
191
196
  )
192
197
  }
193
198
  }
194
199
 
200
+ public buildClientTokens(
201
+ remoteip: string,
202
+ handle: string,
203
+ userAgent?: string,
204
+ ): HcaptchaClientTokens {
205
+ return {
206
+ hashedIp: this.hashToken(remoteip),
207
+ hashedHandle: this.hashToken(handle),
208
+ hashedUserAgent: userAgent ? this.hashToken(userAgent) : undefined,
209
+ }
210
+ }
211
+
195
212
  protected hashToken(value: string) {
196
213
  const hash = createHash('sha256')
197
214
  hash.update(this.config.tokenSalt)
@@ -200,9 +217,10 @@ export class HCaptchaClient {
200
217
  }
201
218
  }
202
219
 
203
- export class HCaptchaVerificationError extends Error {
220
+ export class HCaptchaVerifyError extends Error {
204
221
  constructor(
205
222
  readonly result: HcaptchaVerifyResult,
223
+ readonly tokens: HcaptchaClientTokens,
206
224
  message?: string,
207
225
  ) {
208
226
  super(message)
@@ -13,7 +13,11 @@ import { ClientId } from './client/client-id.js'
13
13
  import { ClientInfo } from './client/client-info.js'
14
14
  import { Client } from './client/client.js'
15
15
  import { InvalidRequestError } from './errors/invalid-request-error.js'
16
- import { HcaptchaConfig, HcaptchaVerifyResult } from './lib/hcaptcha.js'
16
+ import {
17
+ HcaptchaClientTokens,
18
+ HcaptchaConfig,
19
+ HcaptchaVerifyResult,
20
+ } from './lib/hcaptcha.js'
17
21
  import { RequestMetadata } from './lib/http/request.js'
18
22
  import { Awaitable } from './lib/util/type.js'
19
23
  import { AccessDeniedError, OAuthError } from './oauth-errors.js'
@@ -30,6 +34,7 @@ export {
30
34
  type ClientInfo,
31
35
  type DeviceAccountInfo,
32
36
  type DeviceId,
37
+ type HcaptchaClientTokens,
33
38
  type HcaptchaConfig,
34
39
  type HcaptchaVerifyResult,
35
40
  InvalidRequestError,
@@ -82,10 +87,15 @@ export type OAuthHooks = {
82
87
  deviceMetadata: RequestMetadata
83
88
  }) => Awaitable<void>
84
89
 
90
+ /**
91
+ * This hook is called when a user attempts to sign up, after the hcaptcha
92
+ * `/siteverify` request has been made (and before the result is validated).
93
+ */
85
94
  onHcaptchaResult?: (data: {
86
95
  input: SignUpInput
87
96
  deviceId: DeviceId
88
97
  deviceMetadata: RequestMetadata
98
+ tokens: HcaptchaClientTokens
89
99
  result: HcaptchaVerifyResult
90
100
  }) => Awaitable<void>
91
101