fix(security): пентест — symlink-escape в архивах, Content-Disposition, /docs

- ARCH-SYMLINK-01: unar материализовал симлинки из архива → парсеры/MCP/скачивание
  читали произвольный файл хоста (/etc/passwd, ~/.claude). Фикс с двух сторон:
  _run_unar удаляет симлинки сразу после распаковки; /api/files добавлен guard
  resolve().relative_to(work_dir) (был только в admin-пути — унифицировано).
- DISP-01: Content-Disposition из safe_name, не из сырого path-param.
- INFO-OPENAPI-01: /docs /redoc /openapi.json выключены (карта API вкл. /api/admin
  не отдаётся анониму).
Тесты: strip-symlink, download-symlink-404, +обновлён mock под Popen. 311 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
anor
2026-07-19 13:33:51 +10:00
co-authored by Claude Opus 4.8
parent 55a17cff5f
commit fba821fb5e
5 changed files with 96 additions and 12 deletions
+18 -7
View File
@@ -27,18 +27,29 @@ def test_no_backend():
def test_extraction_wiring():
orig_b, orig_run = ah._backend, subprocess.run
orig_b, orig_popen = ah._backend, subprocess.Popen
ah._backend = lambda: "unar"
def fake_run(cmd, **kw):
def fake_popen(cmd, **kw):
out = Path(cmd[cmd.index("-o") + 1])
(out / "sub").mkdir(parents=True, exist_ok=True)
(out / "sub" / "смета.xlsx").write_text("x")
class R:
returncode = 0
return R()
subprocess.run = fake_run
class P: # Popen-подобный: сразу завершён успехом
returncode = 0
def poll(self):
return 0
def wait(self, timeout=None):
return
def kill(self):
pass
return P()
subprocess.Popen = fake_popen
try:
wd = Path(tempfile.mkdtemp())
r = ah.extract_rarlike(Path("09.0200.rar"), wd)
@@ -46,7 +57,7 @@ def test_extraction_wiring():
assert r["files"] == 1, r
assert (wd / "09.0200_extracted" / "sub" / "смета.xlsx").exists()
finally:
ah._backend, subprocess.run = orig_b, orig_run
ah._backend, subprocess.Popen = orig_b, orig_popen
if __name__ == "__main__":