The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: refuse redirected native media publication
Tekniume924cf98a39a
diff --git a/gateway/session_ingress_media.py b/gateway/session_ingress_media.pyindex f863db2a964..302fb158ea0 100644--- a/gateway/session_ingress_media.py+++ b/gateway/session_ingress_media.py@@ -50,6 +50,8 @@ def capture_native_media(paths):raise RuntimeStoreError('invalid_params') from excwith source:root = _media_root()+ if root.resolve() != root:+ raise RuntimeStoreError('invalid_params')root.mkdir(mode=0o700, parents=True, exist_ok=True)fd, name = tempfile.mkstemp(prefix='.capture-', dir=root)temporary = Path(name)@@ -67,6 +69,8 @@ def capture_native_media(paths):output.flush()os.fsync(output.fileno())target = root / digest.hexdigest() / path.name+ if target.parent.resolve() != target.parent:+ raise RuntimeStoreError('invalid_params')target.parent.mkdir(mode=0o700, exist_ok=True)reference = {'path': str(target), 'sha256': digest.hexdigest(), 'size': size}if target.exists():diff --git a/tests/gateway/fixtures/native_ingress_media_peer.py b/tests/gateway/fixtures/native_ingress_media_peer.pyindex 43001b5ce27..cf23ccbf1f2 100644--- a/tests/gateway/fixtures/native_ingress_media_peer.py+++ b/tests/gateway/fixtures/native_ingress_media_peer.py@@ -68,6 +68,26 @@ async def probe(mode, peer):channel_context='ORIGINAL_CHANNEL_CONTEXT', channel_prompt='ORIGINAL_CHANNEL_PROMPT',reply_to_message_id='quoted-1', reply_to_text='ORIGINAL_QUOTE',reply_to_author_id='quoted-user', reply_to_author_name='Quoted User')+ # A cache alias must never redirect publication outside managed media.+ import hashlib+ from gateway.platforms.base import get_document_cache_dir+ root = get_document_cache_dir() / 'native-inputs'+ root.mkdir(parents=True, exist_ok=True)+ escaped = state / 'escaped'+ escaped.mkdir()+ digest_dir = root / hashlib.sha256(original.read_bytes()).hexdigest()+ digest_dir.symlink_to(escaped, target_is_directory=True)+ try:+ try:+ snapshot_native(runner, event)+ except RuntimeStoreError as exc:+ assert exc.reason == 'invalid_params', exc.reason+ else:+ raise AssertionError('media publication followed a cache-directory symlink')+ assert not list(escaped.iterdir())+ assert not event._gateway_accepted+ finally:+ digest_dir.unlink()receipt = authority.admit_native(event)assert event._gateway_acceptedsaved = rows(receipt.ref.session_id)[0]