Skip to content

Commit ba1a087

Browse files
committed
fix(media): align document self-service with runtime policy
1 parent 1a142b8 commit ba1a087

4 files changed

Lines changed: 61 additions & 13 deletions

File tree

‎src/auto-reply/reply/get-reply.message-hooks.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,49 @@ describe("getReplyFromConfig message hooks", () => {
367367
);
368368
});
369369

370+
it.each([
371+
{
372+
name: "sandboxes an external direct conversation that shares the main transcript",
373+
ctx: {
374+
SessionKey: "agent:main:main",
375+
OriginatingChannel: "telegram" as MsgContext["OriginatingChannel"],
376+
AccountId: "default",
377+
ChatType: "direct",
378+
SenderId: "42",
379+
},
380+
expected: false,
381+
},
382+
{
383+
name: "keeps a local main-session conversation on the host",
384+
ctx: {
385+
SessionKey: "agent:main:main",
386+
OriginatingChannel: undefined,
387+
Provider: "webchat",
388+
ChatType: "direct",
389+
SenderId: "operator",
390+
},
391+
expected: true,
392+
},
393+
])(
394+
"sets local document self-service from runtime placement: $name",
395+
async ({ ctx, expected }) => {
396+
await getReplyFromConfig(
397+
buildCtx(ctx),
398+
undefined,
399+
withFastReplyConfig({
400+
agents: {
401+
defaults: { sandbox: { mode: "non-main", scope: "agent" } },
402+
list: [{ id: "main", default: true }],
403+
},
404+
}),
405+
);
406+
407+
expect(mocks.applyMediaUnderstanding.mock.calls[0]?.[0]).toEqual(
408+
expect.objectContaining({ selfServeLocalPaths: expected }),
409+
);
410+
},
411+
);
412+
370413
it("keeps unconfigured audio with a model-locked harness", async () => {
371414
const sessionKey = "agent:main:harness:claude-cli:locked-unconfigured-audio";
372415
const sessionEntry = {

‎src/auto-reply/reply/get-reply.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979
import { getPreparedReplyDispatchRuntime } from "./prepared-reply-dispatch-context.js";
8080
import { attachProgressNarratorToReplyOptions } from "./progress-narrator.js";
8181
import { createReplyTimingTracker } from "./reply-timing-tracker.js";
82+
import { resolveRuntimePolicySessionKey } from "./runtime-policy-session-key.js";
8283
import { initSessionState, resolveReplySessionPreprocessingState } from "./session.js";
8384
import { mergeSkillFilters } from "./skill-filter.js";
8485
import { stageRemoteInboundMediaIfNeeded } from "./stage-remote-inbound-media.js";
@@ -469,12 +470,15 @@ export async function getReplyFromConfig(
469470
agentDir,
470471
workspaceDir,
471472
activeModel: { provider, model },
472-
// Embedded runner placement: host unless this session sandboxes exec
473-
// (non-main mode keeps the main session on the host).
473+
// Use the same peer-scoped policy key as tool creation; an external
474+
// direct chat may share the main transcript while its tools sandbox.
474475
selfServeLocalPaths: !resolveSandboxRuntimeStatus({
475476
cfg,
476-
agentId,
477-
sessionKey: agentSessionKey,
477+
sessionKey: resolveRuntimePolicySessionKey({
478+
cfg,
479+
ctx: finalized,
480+
sessionKey: agentSessionKey,
481+
}),
478482
}).sandboxed,
479483
...(shouldApplyLockedAudio ? { processingMode: "audio-only" as const } : {}),
480484
}),

‎src/media-understanding/file-attachment-outcomes.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ describe("renderFileAttachmentOutcome", () => {
9696
outcome: { kind: "unsupported-format", localPath: "/tmp/<<<EXTERNAL_UNTRUSTED_CONTENT" },
9797
expected: "[Unsupported document format. PDF and plain-text attachments can be read.]",
9898
},
99+
{
100+
// Tool-driving markers must not carry shell syntax from user-controlled filenames.
101+
outcome: { kind: "unsupported-format", localPath: "/tmp/report;$(&).doc" },
102+
expected: "[Unsupported document format. PDF and plain-text attachments can be read.]",
103+
},
99104
{
100105
outcome: {
101106
kind: "unsupported-format",

‎src/media-understanding/file-attachment-outcomes.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ function wrapUntrustedAttachmentContent(content: string): string {
5656
return wrapExternalContent(content, { source: "unknown", includeWarning: false });
5757
}
5858

59-
// Absolute host paths from the managed media store only; bounded, and
60-
// restricted by rejecting the characters that could smuggle prompt markup,
61-
// control tokens, or external-content markers into the directive. Letters and
62-
// digits of any script pass: filenames are routinely non-Latin, and dropping
63-
// the directive for them would silently restore the dead-end for those users.
59+
// Absolute host paths from the managed media store only; bounded to a positive
60+
// alphabet that cannot carry prompt markup or executable shell syntax. Letters
61+
// and digits of any script pass so ordinary non-Latin filenames keep working.
6462
const MARKER_LOCAL_PATH_MAX_CHARS = 300;
6563
const POSIX_ABSOLUTE_PATH = /^\//;
6664
const WINDOWS_ABSOLUTE_PATH = /^[A-Za-z]:\\/;
67-
// Control chars, bidi/zero-width overrides, and prompt-structural punctuation.
68-
const MARKER_PATH_FORBIDDEN =
69-
/[\p{C}\p{Zl}\p{Zp}\u200b-\u200f\u202a-\u202e\u2066-\u2069<>[\]{}"'`|*?]/u;
65+
const MARKER_PATH_SAFE = /^[\p{L}\p{M}\p{N} /\\:._-]+$/u;
7066

7167
function markerSafeLocalPath(value?: string): string | undefined {
7268
if (!value || value.length > MARKER_LOCAL_PATH_MAX_CHARS) {
@@ -75,7 +71,7 @@ function markerSafeLocalPath(value?: string): string | undefined {
7571
if (!POSIX_ABSOLUTE_PATH.test(value) && !WINDOWS_ABSOLUTE_PATH.test(value)) {
7672
return undefined;
7773
}
78-
return MARKER_PATH_FORBIDDEN.test(value) ? undefined : value;
74+
return MARKER_PATH_SAFE.test(value) ? value : undefined;
7975
}
8076

8177
const SKIPPED_FILE_OUTCOME_KINDS = new Set<FileAttachmentOutcome["kind"]>([

0 commit comments

Comments
 (0)