Skip to content

Commit 6baf04b

Browse files
fix(security): autofix Potential file inclusion attack via reading file
1 parent eb40036 commit 6baf04b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

scripts/mutation_gate.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import ast
1919
import contextlib
2020
import importlib.util
21+
import os
2122
import re
2223
import subprocess
2324
import sys
@@ -255,6 +256,10 @@ def _invalidate_bytecode(path: Path) -> None:
255256
def _survives(
256257
path: Path, tree: ast.Module, src: str, mutant: _Mutant, data: coverage.CoverageData
257258
) -> bool:
259+
base_real = os.path.realpath(_PKG)
260+
target_real = os.path.realpath(path)
261+
if os.path.commonpath([base_real, target_real]) != base_real:
262+
raise Exception("Invalid file path")
258263
mutant.apply()
259264
try:
260265
path.write_text(ast.unparse(tree), encoding="utf-8")

0 commit comments

Comments
 (0)