Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(serve-http): POST /ingest answers 400 invalid_slug for an invalid slug header

garrytana5cd449c64ab
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c28e3db672..6838f7ef6b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,7 +16,7 @@ identifiers and attribution are available in the pre-removal Git revision
### Itemized changes
-- `src/commands/serve-http-webhooks.ts`, `src/core/minions/handlers/ingest-capture.ts`: `POST /ingest` stores the caller's token or OAuth client on the job. The route answers `404 page_not_found` for an `X-Gbrain-Slug` the caller cannot read and `403 permission_denied` for a member fact page or the scope page, and queues nothing. The job checks the same writer again right before it writes, so a page restricted after the 202 is still refused, and a queued webhook job with no stored writer is checked as a guest. Fresh slugs and pages the caller can read import as before.
+- `src/commands/serve-http-webhooks.ts`, `src/core/minions/handlers/ingest-capture.ts`: `POST /ingest` stores the caller's token or OAuth client on the job. The route answers `404 page_not_found` for an `X-Gbrain-Slug` the caller cannot read and `403 permission_denied` for a member fact page or the scope page, and queues nothing. An `X-Gbrain-Slug` that is not a valid slug gets `400 invalid_slug` instead of a queued job that fails later (#8763). The job checks the same writer again right before it writes, so a page restricted after the 202 is still refused, and a queued webhook job with no stored writer is checked as a guest. Fresh slugs and pages the caller can read import as before.
- `src/core/ops/image.ts`, `src/core/search/image-loader.ts`: `search_by_image` accepts only an http(s) `image_url` from any caller that is not the trusted local CLI, and refuses `image_path` unless the context says the caller is local. The loader reads local paths only when its caller opts in, and checks for a regular file and the size cap before it reads.
- `src/commands/serve-http-webhooks.ts`: a push event is verified against the source's secret before anything about the repository is answered. An unknown repository, a source with no secret and a bad signature all get the same `401 signature_mismatch`; the missing-secret case is logged on the server with the command that sets it.
- `src/core/git-remote.ts`, `src/core/sources-ops.ts`, `src/core/ops/sources.ts`: a URL source a remote caller adds is cloned with git-lfs downloads off, written into the clone's own git config (`lfs.fetchexclude=*`, which outranks the repository's `.lfsconfig`, with hooks off so git-lfs's pre-push hook never runs), so every later pull, managed refresh and commit-push in that checkout keeps large files as pointer files and contacts no LFS endpoint. The source records `added_by_remote_caller: true` so a re-clone keeps it off. A URL source a remote caller added before this release carries no such record, so remove it and add it again (from the remote caller or with `gbrain sources add --url`, which keeps git-lfs) to choose its setting. A remote caller whose clone fails gets a fixed message; git's own error goes to the brain host's log. Sources added from the local CLI keep git-lfs.
diff --git a/src/commands/serve-http-webhooks.ts b/src/commands/serve-http-webhooks.ts
index d26fed4c2f..8cda00497b 100644
--- a/src/commands/serve-http-webhooks.ts
+++ b/src/commands/serve-http-webhooks.ts
@@ -28,6 +28,7 @@ import { NO_SOURCES } from '../core/source-id.ts';
import { noSourceGrantError } from '../core/ops/context.ts';
import { renderAction } from '../core/agent-output.ts';
import { assertWebhookWriterMayReplace } from '../core/minions/handlers/ingest-capture.ts';
+import { validateSlug } from '../core/utils.ts';
/**
* v0.46: normalize the per-event GitHub webhook payload shape into
@@ -473,13 +474,18 @@ async function handleIngest(
const writeSourceId = authInfo.sourceId ?? 'default';
const writer = authInfo.principal ? { principal: { kind: authInfo.principal.kind, id: authInfo.principal.id } } : undefined;
if (callerSlug) {
+ try {
+ validateSlug(callerSlug);
+ } catch (err) {
+ res.status(400).json({ error: 'invalid_slug', message: err instanceof Error ? err.message : String(err) });
+ return;
+ }
try {
await assertWebhookWriterMayReplace(engine, writer, writeSourceId, callerSlug);
} catch (err) {
- if (err instanceof OperationError) {
- res.status(err.code === 'page_not_found' ? 404 : 403).json({ error: err.code, message: err.message });
- return;
- }
+ if (!(err instanceof OperationError)) throw err;
+ res.status(err.code === 'page_not_found' ? 404 : 403).json({ error: err.code, message: err.message });
+ return;
}
}
diff --git a/test/serve-http-ingest-member-access.test.ts b/test/serve-http-ingest-member-access.test.ts
index 402cb901ba..0a9ed7f7a1 100644
--- a/test/serve-http-ingest-member-access.test.ts
+++ b/test/serve-http-ingest-member-access.test.ts
@@ -120,6 +120,14 @@ describe('POST /ingest refuses pages the caller cannot write over MCP', () => {
expect(await engine.readPageSnapshot(ALICE_MEMBER_PAGE, { sourceId: SRC })).toBeNull();
});
+ test('a slug header that is not a valid slug: 400 invalid_slug, nothing queued', async () => {
+ const before = await queuedJobs();
+ const res = await ingest('../escape');
+ expect(res.status).toBe(400);
+ expect((await res.json() as { error: string }).error).toBe('invalid_slug');
+ expect(await queuedJobs()).toBe(before);
+ });
+
test('a page the caller can read still imports through the job', async () => {
const res = await ingest(OPEN, page('Team open', '') + '\nUpdated by bob.\n');
expect(res.status).toBe(202);