Increase security and reformat
This commit is contained in:
@@ -216,7 +216,9 @@ def _next_unique_slug(*, user_id: int, requested_slug: str) -> str:
|
||||
raise ValueError("slug cannot be empty")
|
||||
candidate = base
|
||||
idx = 2
|
||||
while KnowledgeArticle.objects.filter(user_id=int(user_id), slug=candidate).exists():
|
||||
while KnowledgeArticle.objects.filter(
|
||||
user_id=int(user_id), slug=candidate
|
||||
).exists():
|
||||
suffix = f"-{idx}"
|
||||
candidate = f"{base[: max(1, 255 - len(suffix))]}{suffix}"
|
||||
idx += 1
|
||||
@@ -645,9 +647,7 @@ def tool_wiki_update_article(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
)
|
||||
if status_marker and status == "archived" and article.status != "archived":
|
||||
if not approve_archive:
|
||||
raise ValueError(
|
||||
"approve_archive=true is required to archive an article"
|
||||
)
|
||||
raise ValueError("approve_archive=true is required to archive an article")
|
||||
|
||||
if title:
|
||||
article.title = title
|
||||
@@ -705,7 +705,9 @@ def tool_wiki_list(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
def tool_wiki_get(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
article = _get_article_for_user(arguments)
|
||||
include_revisions = bool(arguments.get("include_revisions"))
|
||||
revision_limit = _safe_limit(arguments.get("revision_limit"), default=20, low=1, high=200)
|
||||
revision_limit = _safe_limit(
|
||||
arguments.get("revision_limit"), default=20, low=1, high=200
|
||||
)
|
||||
payload = {"article": _article_payload(article)}
|
||||
if include_revisions:
|
||||
revisions = article.revisions.order_by("-revision")[:revision_limit]
|
||||
@@ -714,7 +716,9 @@ def tool_wiki_get(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def tool_project_get_guidelines(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
max_chars = _safe_limit(arguments.get("max_chars"), default=16000, low=500, high=50000)
|
||||
max_chars = _safe_limit(
|
||||
arguments.get("max_chars"), default=16000, low=500, high=50000
|
||||
)
|
||||
base = Path(settings.BASE_DIR).resolve()
|
||||
file_names = ["AGENTS.md", "LLM_CODING_STANDARDS.md", "INSTALL.md", "README.md"]
|
||||
payload = []
|
||||
@@ -734,7 +738,9 @@ def tool_project_get_guidelines(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def tool_project_get_layout(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
max_entries = _safe_limit(arguments.get("max_entries"), default=300, low=50, high=4000)
|
||||
max_entries = _safe_limit(
|
||||
arguments.get("max_entries"), default=300, low=50, high=4000
|
||||
)
|
||||
base = Path(settings.BASE_DIR).resolve()
|
||||
roots = ["app", "core", "scripts", "utilities", "artifacts"]
|
||||
items: list[str] = []
|
||||
@@ -754,7 +760,9 @@ def tool_project_get_layout(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
|
||||
def tool_project_get_runbook(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
max_chars = _safe_limit(arguments.get("max_chars"), default=16000, low=500, high=50000)
|
||||
max_chars = _safe_limit(
|
||||
arguments.get("max_chars"), default=16000, low=500, high=50000
|
||||
)
|
||||
base = Path(settings.BASE_DIR).resolve()
|
||||
file_names = [
|
||||
"INSTALL.md",
|
||||
@@ -792,7 +800,11 @@ def tool_docs_append_run_note(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
path = Path("/tmp/gia-mcp-run-notes.md")
|
||||
else:
|
||||
candidate = Path(raw_path)
|
||||
path = candidate.resolve() if candidate.is_absolute() else (base / candidate).resolve()
|
||||
path = (
|
||||
candidate.resolve()
|
||||
if candidate.is_absolute()
|
||||
else (base / candidate).resolve()
|
||||
)
|
||||
allowed_roots = [base, Path("/tmp").resolve()]
|
||||
if not any(str(path).startswith(str(root)) for root in allowed_roots):
|
||||
raise ValueError("path must be within project root or /tmp")
|
||||
@@ -812,7 +824,11 @@ def tool_docs_append_run_note(arguments: dict[str, Any]) -> dict[str, Any]:
|
||||
TOOL_DEFS: dict[str, dict[str, Any]] = {
|
||||
"manticore.status": {
|
||||
"description": "Report configured memory backend status (django or manticore).",
|
||||
"inputSchema": {"type": "object", "properties": {}, "additionalProperties": False},
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"additionalProperties": False,
|
||||
},
|
||||
"handler": tool_manticore_status,
|
||||
},
|
||||
"manticore.query": {
|
||||
|
||||
Reference in New Issue
Block a user