Repository navigation
fix: harden API key handling and bound agent task claims #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
7f6dcc3
7c3e605
e7dc490
3129565
d79e723
40e2f3d
79f443c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { timingSafeEqual } from "node:crypto"; | ||
|
|
||
| export function timingSafeEquals(a: string, b: string): boolean { | ||
| const bufferA = Buffer.from(a); | ||
| const bufferB = Buffer.from(b); | ||
|
|
||
| if (bufferA.length !== bufferB.length) return false; | ||
|
|
||
| return timingSafeEqual(bufferA, bufferB); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { randomUUID } from "node:crypto"; | ||
| import { API_KEY_HEADER } from "@crm/auth"; | ||
| import { Injectable, Logger, type NestMiddleware } from "@nestjs/common"; | ||
| import type { NextFunction, Request, Response } from "express"; | ||
| import { type RequestContext, runInRequestContext } from "./request-context"; | ||
|
|
@@ -18,7 +19,7 @@ export class RequestLoggerMiddleware implements NestMiddleware { | |
| const context: RequestContext = { | ||
| requestId, | ||
| method: request.method, | ||
| path: request.originalUrl, | ||
| path: request.path, | ||
| }; | ||
| const startedAt = process.hrtime.bigint(); | ||
|
|
||
|
|
@@ -56,6 +57,7 @@ export class RequestLoggerMiddleware implements NestMiddleware { | |
| durationMs: Number(durationMs.toFixed(1)), | ||
| ip: request.ip, | ||
| userAgent: request.get("user-agent"), | ||
| apiKeyPresented: Boolean(request.get(API_KEY_HEADER)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The hardening is untested: Prompt for AI agents |
||
| }; | ||
|
|
||
| if (statusCode >= 500) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.