Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(security): keep pet lookups inside their folders and strip HTML comments fully

rubenluetke10-beepfbbe96302664
diff --git a/jarvis/ui/pets/loader.py b/jarvis/ui/pets/loader.py
index 903822dd65..2dd8c4f861 100644
--- a/jarvis/ui/pets/loader.py
+++ b/jarvis/ui/pets/loader.py
@@ -13,6 +13,7 @@ from __future__ import annotations
import json
import logging
+import os
from collections.abc import Mapping
from dataclasses import dataclass, field
from pathlib import Path
@@ -89,16 +90,29 @@ def find_pet_dir(pet_id: str, *, data_dir: Path | None = None) -> tuple[Path, bo
if not isinstance(pet_id, str) or pet_id == NO_PET_ID:
return None
if BUILTIN_ID_RE.match(pet_id) and not USER_ID_RE.match(pet_id):
- folder = builtin_root() / pet_id
- if (folder / MANIFEST_NAME).is_file():
+ folder = _child_folder(builtin_root(), pet_id)
+ if folder is not None and (folder / MANIFEST_NAME).is_file():
return folder, True
if USER_ID_RE.match(pet_id):
- folder = custom_root(data_dir) / pet_id
- if (folder / MANIFEST_NAME).is_file():
+ folder = _child_folder(custom_root(data_dir), pet_id)
+ if folder is not None and (folder / MANIFEST_NAME).is_file():
return folder, False
return None
+def _child_folder(root: Path, name: str) -> Path | None:
+ """``root / name`` when it stays a direct child of ``root``, else ``None``.
+
+ The id patterns already rule out separators and dots; this second check
+ keeps the guarantee local to the one place a request value becomes a path.
+ """
+ base = os.path.normpath(os.path.abspath(root))
+ full = os.path.normpath(os.path.join(base, name))
+ if not full.startswith(base + os.sep) or os.path.dirname(full) != base:
+ return None
+ return Path(full)
+
+
def read_manifest(pet_dir: Path, *, builtin: bool) -> PetManifest:
"""Parse ``pet.json`` in ``pet_dir`` and check it against its sheet's size.
diff --git a/jarvis/ui/web/frontend/src/views/assistant/FilesSection.tsx b/jarvis/ui/web/frontend/src/views/assistant/FilesSection.tsx
index 2d467eef56..3129f3a557 100644
--- a/jarvis/ui/web/frontend/src/views/assistant/FilesSection.tsx
+++ b/jarvis/ui/web/frontend/src/views/assistant/FilesSection.tsx
@@ -30,10 +30,19 @@ export function useFileMeta(): (file: SoulFile) => string {
};
}
+/** Drops HTML comments, including nested leftovers and an unclosed opener. */
+function withoutComments(text: string): string {
+ let previous: string;
+ do {
+ previous = text;
+ text = text.replace(/<!--[\s\S]*?-->/g, "");
+ } while (text !== previous);
+ return text.replace(/<!--|-->/g, "");
+}
+
/** Inline Markdown made readable: emphasis markers and comments dropped. */
function clean(line: string): string {
- return line
- .replace(/<!--.*?-->/g, "")
+ return withoutComments(line)
.replace(/\*\*(.+?)\*\*/g, "$1")
.replace(/(^|\s)_([^_]+)_(?=[\s.,;:!?]|$)/g, "$1$2")
.replace(/^_|_$/g, "")
@@ -57,7 +66,7 @@ export function previewLines(file: SoulFile, max = 4): string[] {
};
for (const raw of file.content.split("\n")) {
const trimmed = raw.trim();
- if (!trimmed || trimmed.startsWith("#") || /^<!--.*-->$/.test(trimmed)) {
+ if (!trimmed || trimmed.startsWith("#") || (trimmed.startsWith("<!--") && trimmed.endsWith("-->"))) {
flush();
} else if (/^[-*]\s+/.test(trimmed)) {
flush();