Skip to content

API Reference parrot.tools.repo.confinement

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.repo.confinement

View source

Path confinement and secret deny-list — the security boundary of FEAT-484.

This module is the single code path every path-taking tool in parrot.tools.repo funnels through. Two independent checks are composed here on purpose (spec §7: "a second implementation is a second chance to get it wrong"):

  1. Containment — resolve_within_root() resolves a caller-supplied path to its real (symlink-following) absolute form and asserts it lives inside root.
  2. Secret deny-list — is_secret_path() (spec §8 Q1) rejects paths that look like credentials, even when they are safely inside the root.

resolve_readable_path() composes both and is what tools should call.

This module is deliberately dependency-free beyond the standard library — no AbstractToolkit, no pydantic models are imported here so it can be exercised in isolation.

Class PathOutsideRootError

Raised when a resolved path is not contained within the repo root.

Class SecretFileError

Raised when a path matches the secret deny-list (spec §8 Q1).

Function is_secret_path

True when rel_path matches the secret deny-list (spec §8 Q1).

Matched case-insensitively on the repo-relative path. Any path segment matching a deny pattern counts, so config/.env and .env both match. A match is overridden — the path is treated as readable — when the filename ends in .example, .sample, .template or .dist.

is_secret_path(rel_path: str) -> bool

Parameter Type Default Description
rel_path str A repo-relative path (relative or absolute string form is accepted; only the POSIX representation is inspected).

Returns: bool — True if the path should be denied, False otherwise.

Attribute logger

Function resolve_readable_path

Resolve candidate within root and enforce the secret deny-list.

This is the composed entry point tools should call: containment first, then the deny-list. Both checks raise; converting the exception to a RepoToolError is the caller's responsibility, so each tool can attach its own error code and context.

resolve_readable_path(root: Path, candidate: str) -> Path

Parameter Type Default Description
root Path The repository root to confine reads to.
candidate str A caller-supplied path, relative or absolute.

Returns: Path — The resolved, absolute, real path.

Raises:

  • PathOutsideRootError — The resolved path escapes root.
  • SecretFileError — The path matches the secret deny-list.

Function resolve_within_root

Resolve candidate and assert containment in root.

root is resolved too, so a root reached via a symlink does not make every containment check wrong. The join happens before resolution, so that .. traversal and a symlink inside the root that points outside it are both collapsed by the same Path.resolve() call.

resolve_within_root(root: Path, candidate: str) -> Path

Parameter Type Default Description
root Path The repository root to confine reads/writes to.
candidate str A caller-supplied path, relative or absolute.

Returns: Path — The resolved, absolute, real path — guaranteed to be inside root.

Raises:

  • PathOutsideRootError — The resolved path (after following symlinks) is not inside root.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally