Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix: openapi auth errors return 401 instead of 500 & mask real API key prefix (#17143)

Rdmclin2f0c5cd091bb4
diff --git a/.agents/skills/agent-testing/references/probe-mock-patterns.md b/.agents/skills/agent-testing/references/probe-mock-patterns.md
index 835ba8024d0..ac39e7cb1db 100644
--- a/.agents/skills/agent-testing/references/probe-mock-patterns.md
+++ b/.agents/skills/agent-testing/references/probe-mock-patterns.md
@@ -1081,6 +1081,7 @@ nodeintegration, plugins, disablewebsecurity, allowpopups, preload, …`). The h
- **Works**: seed an `agents` row and set `topics.agent_id` (and `messages.agent_id`)
before opening the share page. Verify the fetch actually fired via
`agent-browser network requests | grep getMessages`, not by waiting on the UI.
+
### E15. βœ… Next dev does NOT hot-reload `apps/server/**` β€” you are testing STALE compiled server code
- **Situation**: verifying a working-tree change inside `apps/server/src/**` (an agent-runtime
@@ -1130,3 +1131,22 @@ nodeintegration, plugins, disablewebsecurity, allowpopups, preload, …`). The h
`window.__LOBE_STORES.aiInfra().enabledChatModelList` β†’ `[{id: provider, children: [{id: model}]}]` β€”
and pick one from there. Also: a send that "resolves fine but creates no operation" is a UI-gate
symptom; **screenshot the composer** instead of re-reading your store call.
+
+### E18. Fresh-worktree `seed-user` dies on `Cannot find module 'bcryptjs'` β€” NODE\_PATH into .pnpm fixes it
+
+- **Situation**: in a fresh git-worktree install, `init-dev-env.sh seed-user`
+ (which runs `node <<'NODE'` from the repo root) throws MODULE\_NOT\_FOUND for
+ `bcryptjs`, even though `pnpm install` succeeded.
+- **Cause not fully established**: `bcryptjs` exists in `node_modules/.pnpm/`
+ but is not linked at the repo-root `node_modules` top level in that install
+ (`pg` was linked, `bcryptjs` wasn't), so a root-cwd stdin script can't
+ resolve it.
+- **Works**: prefix the call with
+ `NODE_PATH="$PWD/node_modules/.pnpm/bcryptjs@<ver>/node_modules"` (check the
+ exact version dir first). CJS stdin scripts honor NODE\_PATH; seeding then
+ completes normally.
+- Same run also (re)confirmed: `init-dev-env.sh dev` ports are DYNAMIC (e.g.
+ next on 33803, vite on 32459) β€” never hardcode 3010; re-run
+ `scripts/test-env.sh` after the server is up, it reads the ports-file. And
+ the `os error 35` agent-browser daemon wedge (D8) recovers with
+ `agent-browser close --all` + re-running `setup-auth.sh web-seed`.
diff --git a/packages/openapi/src/app.ts b/packages/openapi/src/app.ts
index 48665e13af1..23b34a7d026 100644
--- a/packages/openapi/src/app.ts
+++ b/packages/openapi/src/app.ts
@@ -1,5 +1,6 @@
import { Hono } from 'hono';
import { cors } from 'hono/cors';
+import { HTTPException } from 'hono/http-exception';
import { logger } from 'hono/logger';
import { prettyJSON } from 'hono/pretty-json';
@@ -22,7 +23,14 @@ app.use('*', workspaceAuthMiddleware);
// Error handling middleware
app.onError((error: Error, c) => {
console.error('Hono Error:', error);
- return c.json({ error: error.message }, 500);
+ // Middleware-thrown HTTPExceptions (e.g. auth 401) must keep their status
+ // instead of being flattened to 500, while staying in the same ApiResponse
+ // envelope that BaseController.handleError produces for controller errors.
+ const status = error instanceof HTTPException ? error.status : 500;
+ return c.json(
+ { error: error.message, success: false, timestamp: new Date().toISOString() },
+ status,
+ );
});
// Health check endpoint
diff --git a/src/routes/(main)/settings/apikey/features/ApiKeyDisplay/index.tsx b/src/routes/(main)/settings/apikey/features/ApiKeyDisplay/index.tsx
index 48ddb346d1b..84939011707 100644
--- a/src/routes/(main)/settings/apikey/features/ApiKeyDisplay/index.tsx
+++ b/src/routes/(main)/settings/apikey/features/ApiKeyDisplay/index.tsx
@@ -29,7 +29,14 @@ const ApiKeyDisplay: FC<ApiKeyDisplayProps> = ({ apiKey }) => {
}
};
- const displayValue = apiKey && (isVisible ? apiKey : `lb-${'*'.repeat(apiKey.length - 2)}`);
+ // Mask with the key's real prefix (e.g. `sk-lh-`) so the hidden state
+ // doesn't misrepresent the key format.
+ const maskPrefixLength = apiKey ? apiKey.lastIndexOf('-') + 1 : 0;
+ const displayValue =
+ apiKey &&
+ (isVisible
+ ? apiKey
+ : `${apiKey.slice(0, maskPrefixLength)}${'*'.repeat(apiKey.length - maskPrefixLength)}`);
if (!apiKey) {
return t('apikey.display.autoGenerated');