Skip to content

[lib-audit] S2-18 agent import persists caller dict verbatim (privileged keys, no slugify) - #2818

Merged
jaylfc merged 1 commit into
devfrom
exec/tsk-ztgu6w
Sep 6, 2026
Merged

[lib-audit] S2-18 agent import persists caller dict verbatim (privileged keys, no slugify)#2818
jaylfc merged 1 commit into
devfrom
exec/tsk-ztgu6w

Conversation

@jaylfc

@jaylfc jaylfc commented Sep 6, 2026

Copy link
Copy Markdown
Owner

CARD TITLE (intent, not commit subject): [lib-audit] S2-18 agent import persists caller dict verbatim (privileged keys, no slugify)

Autonomous build of board card tsk-ztgu6w.

The JSON import endpoint (POST /api/agents/import) wrote the caller-supplied
agent dict verbatim into config.yaml, allowing privileged keys (llm_key,
can_read_user_memory, permitted_models, registry_canonical_id) to be injected,
and stored the name unslugified (for example 'My Agent'), producing a container
slug that later routes cannot address.

Fix by introducing AgentImportData, a Pydantic model with an explicit field
allowlist (extra='ignore') that strips operational keys, and slugifying the
name via slugify_agent_name -- the same rule the create route uses
(unique_agent_slug delegates to it). The create path's validate_agent_name and
save_config_locked are reused rather than duplicated.

RED test: test_import_strips_privileged_keys_and_slugifies_name fails on
origin/dev (name persisted as 'My Agent', privileged keys present) and passes
after the fix (name slugified to 'my-agent', privileged keys absent). All 11
tests in test_agent_export_import.py pass; existing import tests and round-trip
continue to pass.

Docs-Reviewed: the import route is not individually documented in
docs/agent-coordination.md; slug derivation is already documented there (lines
555-567) and this change makes import consistent with it. The user-visible
behavior change is captured in the changelog fragment.

Files:
changelog.d/tsk-ztgu6w-import-slugify.md | 3 ++
tests/test_agent_export_import.py | 43 +++++++++++++++++++++
tinyagentos/routes/agents.py | 64 +++++++++++++++++++++++++-------
3 files changed, 96 insertions(+), 14 deletions(-)

Summary by CodeRabbit

  • Bug Fixes
    • Agent imports now ignore unsupported privileged configuration fields, preventing them from being applied during import.
    • Imported agent names are consistently converted to container-safe slugs, including names with spaces or special characters.
    • Imported agents retain their display name and supported presentation settings, such as host and color.
    • Channel and group associations now use the normalized agent identifier for more reliable restoration.

The JSON import endpoint (POST /api/agents/import) wrote the caller-supplied
agent dict verbatim into config.yaml, allowing privileged keys (llm_key,
can_read_user_memory, permitted_models, registry_canonical_id) to be injected,
and stored the name unslugified (for example 'My Agent'), producing a container
slug that later routes cannot address.

Fix by introducing AgentImportData, a Pydantic model with an explicit field
allowlist (extra='ignore') that strips operational keys, and slugifying the
name via slugify_agent_name -- the same rule the create route uses
(unique_agent_slug delegates to it). The create path's validate_agent_name and
save_config_locked are reused rather than duplicated.

RED test: test_import_strips_privileged_keys_and_slugifies_name fails on
origin/dev (name persisted as 'My Agent', privileged keys present) and passes
after the fix (name slugified to 'my-agent', privileged keys absent). All 11
tests in test_agent_export_import.py pass; existing import tests and round-trip
continue to pass.

Docs-Reviewed: the import route is not individually documented in
docs/agent-coordination.md; slug derivation is already documented there (lines
555-567) and this change makes import consistent with it. The user-visible
behavior change is captured in the changelog fragment.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 4b520581-56d6-4c80-981b-b3e9e7b0cb4a

📥 Commits

Reviewing files that changed from the base of the PR and between cf619b5 and dbc5456.

📒 Files selected for processing (3)
  • changelog.d/tsk-ztgu6w-import-slugify.md
  • tests/test_agent_export_import.py
  • tinyagentos/routes/agents.py

Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The agent import endpoint now filters privileged fields through an allowlist model. It slugifies imported names, persists the filtered configuration, and restores channels and groups using the slug.

Changes

Agent import hardening

Layer / File(s) Summary
Import payload allowlist
tinyagentos/routes/agents.py
AgentImportData accepts supported agent fields and ignores unknown or privileged fields.
Slugified import persistence
tinyagentos/routes/agents.py, tests/test_agent_export_import.py, changelog.d/tsk-ztgu6w-import-slugify.md
The import flow slugifies names, persists filtered data, restores related data under the slug, and tests preserved and removed fields.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to dbc54

Agent imports now discard privileged payload fields and store agents under canonical slugified names, with regression coverage for the persisted result. No concrete current-head merge-blocking risk remains.

Sequence Diagram(s)

sequenceDiagram
  participant ImportClient
  participant ImportEndpoint
  participant AgentImportData
  participant ConfigStore
  ImportClient->>ImportEndpoint: POST /api/agents/import
  ImportEndpoint->>AgentImportData: Validate and filter agent payload
  AgentImportData-->>ImportEndpoint: Return allowlisted fields
  ImportEndpoint->>ConfigStore: Save agent under slugified name
  ConfigStore-->>ImportClient: Return imported agent
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the agent import vulnerability addressed by the changes: verbatim persistence of privileged keys and missing name slugification. It is specific and related to the main …
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch exec/tsk-ztgu6w

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gitar-bot

gitar-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@kilo-code-bot

kilo-code-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

@jaylfc

jaylfc commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.


Your included review limit is currently reached under our Fair Usage Limits Policy. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 16 minutes.

@jaylfc

jaylfc commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@jaylfc
jaylfc merged commit c2c60f9 into dev Sep 6, 2026
38 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant