@smartcrab/server 0.2.0-next-20261007091801 → 0.2.0

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.
@@ -1,4 +1,4 @@
1
- import { TOKEN_TTL_SECONDS } from "@smartcrab/contracts-public";
1
+ import { OAUTH_ERROR_CODES, TOKEN_TTL_SECONDS } from "@smartcrab/contracts-public";
2
2
  import { PKCE_COOKIE_NAME, SESSION_COOKIE_NAME, clearAuthCookie, readCookie, serializeAuthCookie, } from "./cookies.js";
3
3
  import { errorToResponse, problemResponse } from "./errors.js";
4
4
  import { createOidcClient } from "./oidc-client.js";
@@ -254,7 +254,8 @@ export const createServerAuth = (config) => {
254
254
  const url = new URL(request.url);
255
255
  const errorParam = url.searchParams.get("error");
256
256
  if (errorParam !== null) {
257
- return failWith(problemResponse(400, "oauth_authorization_error", errorParam.slice(0, 64)));
257
+ const publicError = OAUTH_ERROR_CODES.find((knownError) => knownError === errorParam) ?? "server_error";
258
+ return failWith(problemResponse(400, "oauth_authorization_error", publicError));
258
259
  }
259
260
  const code = url.searchParams.get("code");
260
261
  const state = url.searchParams.get("state");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartcrab/server",
3
- "version": "0.2.0-next-20261007091801",
3
+ "version": "0.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "jose": "6.2.8",
31
31
  "cookie": "2.0.1",
32
- "@smartcrab/contracts-public": "0.2.0-next-20261007091801"
32
+ "@smartcrab/contracts-public": "0.2.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "typescript": "5.9.3",
@@ -517,18 +517,50 @@ describe("callbackHandler", () => {
517
517
  expect(body).toMatchObject({ code: "pkce_cookie_invalid" });
518
518
  });
519
519
 
520
- test("surfaces authorization errors from the redirect", async () => {
520
+ test("surfaces known authorization errors without provider-supplied descriptions", async () => {
521
521
  const state = createStubState();
522
522
  const auth = createTestAuth(state);
523
523
  const login = await runLogin(auth);
524
+ const callbackUrl = new URL("/auth/callback", APP_ORIGIN);
525
+ callbackUrl.searchParams.set("error", "access_denied");
526
+ callbackUrl.searchParams.set("error_description", "private provider details");
527
+ callbackUrl.searchParams.set("state", login.state);
524
528
  const response = await auth.callbackHandler(
525
- new Request(`${APP_ORIGIN}/auth/callback?error=access_denied&state=${login.state}`, {
529
+ new Request(callbackUrl, {
526
530
  headers: { cookie: `${PKCE_COOKIE_NAME}=${login.pkceCookieValue}` },
527
531
  }),
528
532
  );
529
533
  expect(response.status).toBe(400);
530
534
  const body: unknown = await response.json();
531
- expect(body).toMatchObject({ code: "oauth_authorization_error" });
535
+ expect(body).toMatchObject({
536
+ code: "oauth_authorization_error",
537
+ detail: "access_denied",
538
+ });
539
+ expect(JSON.stringify(body)).not.toContain("private provider details");
540
+ });
541
+
542
+ test("replaces unknown authorization errors with a fixed generic detail", async () => {
543
+ const state = createStubState();
544
+ const auth = createTestAuth(state);
545
+ const login = await runLogin(auth);
546
+ const attackerText = `sensitive@example.com ${"private".repeat(16)}`;
547
+ const callbackUrl = new URL("/auth/callback", APP_ORIGIN);
548
+ callbackUrl.searchParams.set("error", attackerText);
549
+ callbackUrl.searchParams.set("error_description", "also private");
550
+ callbackUrl.searchParams.set("state", login.state);
551
+ const response = await auth.callbackHandler(
552
+ new Request(callbackUrl, {
553
+ headers: { cookie: `${PKCE_COOKIE_NAME}=${login.pkceCookieValue}` },
554
+ }),
555
+ );
556
+ expect(response.status).toBe(400);
557
+ const body: unknown = await response.json();
558
+ expect(body).toMatchObject({
559
+ code: "oauth_authorization_error",
560
+ detail: "server_error",
561
+ });
562
+ expect(JSON.stringify(body)).not.toContain(attackerText);
563
+ expect(JSON.stringify(body)).not.toContain("also private");
532
564
  });
533
565
 
534
566
  test("rejects a nonce mismatch in the ID token", async () => {
@@ -1,4 +1,4 @@
1
- import { TOKEN_TTL_SECONDS } from "@smartcrab/contracts-public";
1
+ import { OAUTH_ERROR_CODES, TOKEN_TTL_SECONDS } from "@smartcrab/contracts-public";
2
2
  import type { TokenResponse } from "@smartcrab/contracts-public";
3
3
  import type { JWTPayload } from "jose";
4
4
  import {
@@ -508,7 +508,9 @@ export const createServerAuth = (config: ServerAuthConfig): ServerAuth => {
508
508
  const url = new URL(request.url);
509
509
  const errorParam = url.searchParams.get("error");
510
510
  if (errorParam !== null) {
511
- return failWith(problemResponse(400, "oauth_authorization_error", errorParam.slice(0, 64)));
511
+ const publicError =
512
+ OAUTH_ERROR_CODES.find((knownError) => knownError === errorParam) ?? "server_error";
513
+ return failWith(problemResponse(400, "oauth_authorization_error", publicError));
512
514
  }
513
515
  const code = url.searchParams.get("code");
514
516
  const state = url.searchParams.get("state");