Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): tighten bearer parsing and initialize api auth email

Tin7b750d842523
diff --git a/apps/api/src/utils/authenticate-api-request.ts b/apps/api/src/utils/authenticate-api-request.ts
index aa5302cbe..7bf060906 100644
--- a/apps/api/src/utils/authenticate-api-request.ts
+++ b/apps/api/src/utils/authenticate-api-request.ts
@@ -18,12 +18,16 @@ function parseBearerToken(authHeader: string | undefined): {
return { token: null, malformed: false };
}
- const match = authHeader.match(/^Bearer\s+(.+)$/i);
+ if (!authHeader.match(/^Bearer\b/i)) {
+ return { token: null, malformed: false };
+ }
+
+ const match = authHeader.match(/^Bearer\s+(\S+)$/i);
if (!match) {
return { token: null, malformed: true };
}
- const token = match[1]?.replace(/\s+/g, "").trim();
+ const token = match[1]?.trim();
if (!token) {
return { token: null, malformed: true };
}
@@ -45,6 +49,7 @@ export async function authenticateApiRequest(c: Context): Promise<void> {
if (apiKeyResult?.valid && apiKeyResult.key) {
const key = apiKeyResult.key;
c.set("userId", key.userId);
+ c.set("userEmail", "");
c.set("user", null);
c.set("session", null);
c.set("apiKey", {