Merge branch 'master' into chore/codeowners-fix
CI / Test ingest-api (pull_request) Successful in 36s
CI / Test api (pull_request) Successful in 36s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m3s
CI / Validate Docker build (pull_request) Successful in 3m2s

This commit is contained in:
spark committed 2026-10-22 01:16:24 +01:00
commit dc1aa3365e
5 files changed
+89 -1

No files matched your search

+9
View File
@@ -23,6 +23,15 @@ const nextConfig: NextConfig = {
async rewrites() {
return [
{ source: "/health", destination: `${INGEST_API_URL}/health` },
// BIT-31442: the recent-errors handler (api/src/routes/public/recentErrors.ts)
// registers the /v1/paperclip/recent-errors alias on the admin API (port 3200),
// not on ingest-api. The generic /v1/* rule below would otherwise send it to
// ingest-api (port 3041), which has no such route and returns 404. This more
// specific rule must come first; Next.js evaluates rewrites in order.
{
source: "/v1/paperclip/:path*",
destination: `${ADMIN_API_URL}/v1/paperclip/:path*`,
},
{ source: "/v1/:path*", destination: `${INGEST_API_URL}/v1/:path*` },
{
source: "/api/error-monitoring/:path*",
+16
View File
@@ -45,6 +45,22 @@ export function authorizeReadQuery(request: FastifyRequest, reply: FastifyReply)
return true;
}
// BIT-31442: accept X-Api-Key header as an alternative to the query param so
// programmatic callers (Paperclip, QA) can avoid leaking the key in URLs/logs.
// The header may carry either the resolve/reporting key or the read-only
// DEBUG_VIEW_ERRORS_KEY, mirroring the query-param semantics.
const headerRaw = request.headers['x-api-key'];
const headerVal = Array.isArray(headerRaw) ? headerRaw[0] : headerRaw;
const providedHeader = typeof headerVal === 'string' ? headerVal.trim() : '';
if (providedHeader !== '') {
if (apiKey && safeEqual(providedHeader, apiKey)) {
return true;
}
if (viewKey && safeEqual(providedHeader, viewKey)) {
return true;
}
}
reply.code(401).send({
success: false,
message: 'Unauthorized',
@@ -171,4 +171,60 @@ describe('GET /api/error-monitoring/recent-errors', () => {
// ['resolved', '%boom%', '%boom%', '%boom%', limit, offset]
expect(params).toEqual(['resolved', '%boom%', '%boom%', '%boom%', 10, 0]);
});
it('serves the /v1/paperclip/recent-errors alias from the same handler (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/v1/paperclip/recent-errors?api_key=test-recent-errors-key',
});
expect(res.statusCode).toBe(200);
expect(execute).toHaveBeenCalledTimes(1);
});
it('accepts the resolve key via X-Api-Key header (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'test-recent-errors-key' },
});
expect(res.statusCode).toBe(200);
expect(execute).toHaveBeenCalledTimes(1);
});
it('accepts the read-only view key via X-Api-Key header (BIT-31442)', async () => {
const prevView = process.env.DEBUG_VIEW_ERRORS_KEY;
process.env.DEBUG_VIEW_ERRORS_KEY = 'test-view-key';
try {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'test-view-key' },
});
expect(res.statusCode).toBe(200);
} finally {
if (prevView === undefined) {
delete process.env.DEBUG_VIEW_ERRORS_KEY;
} else {
process.env.DEBUG_VIEW_ERRORS_KEY = prevView;
}
}
});
it('rejects an invalid X-Api-Key header with 401 (BIT-31442)', async () => {
const execute = vi.fn().mockResolvedValue([[]]);
const app = await buildApp(execute);
const res = await app.inject({
method: 'GET',
url: '/api/error-monitoring/recent-errors',
headers: { 'x-api-key': 'wrong-key' },
});
expect(res.statusCode).toBe(401);
expect(execute).not.toHaveBeenCalled();
});
});
+4
View File
@@ -59,6 +59,10 @@ Alias: `GET /v1/paperclip/recent-errors` (same handler).
**Query:** `api_key` *or* `view_errors`, plus optional `limit`, `offset`, `status`, `severity`, `project_slug`, `q`, `order`.
**Header (BIT-31442):** `X-Api-Key: <key>` is accepted as an alternative to the `api_key`/`view_errors` query params, so programmatic callers can avoid leaking the key in URLs and access logs. The header may carry either `ERROR_RESOLVE_API_KEY`/`ERROR_REPORTING_API_KEY` or the read-only `DEBUG_VIEW_ERRORS_KEY`.
> **Proxy note (BIT-31442):** the `/v1/paperclip/*` alias is served by the admin API (port 3200), not ingest-api (port 3041). The `admin-ui` Next.js rewrite routes `/v1/paperclip/:path*` to the admin API *before* the generic `/v1/:path*` → ingest-api rule. If the alias returns 404 in production, verify that rewrite order in `admin-ui/next.config.ts`.
**Response 200**
```json
+4 -1
View File
@@ -50,11 +50,14 @@ These routes mirror the CRM error-monitoring module for Paperclip and automation
### Read: `GET /api/error-monitoring/recent-errors`
Alias: `GET /v1/paperclip/recent-errors` (same handler; served by the admin API via the `admin-ui` rewrite — BIT-31442).
| Credential | Notes |
|------------|--------|
| `api_key` query | Must match `ERROR_RESOLVE_API_KEY` or `ERROR_REPORTING_API_KEY` |
| `view_errors` query | Must match `DEBUG_VIEW_ERRORS_KEY` (read-oriented) |
| Admin session | Not used on this path; query credentials only |
| `X-Api-Key` header (BIT-31442) | Carries either the resolve/reporting key or `DEBUG_VIEW_ERRORS_KEY`; alternative to the query params to avoid key leakage in URLs/logs |
| Admin session | Not used on this path; query/header credentials only |
At least one of the server secrets above must be configured or the endpoint returns **503**.