-
-
Notifications
You must be signed in to change notification settings - Fork 508
fix(combine): path traversal allows arbitrary directory deletion via repo name #1103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ae84bfa
94192e3
0e26f2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,13 @@ | |
|
|
||
|
|
||
| async def eval_repo(repo: Repo, repo_path: Path) -> None: | ||
| canonicalized_repo_path = repo_path.resolve() | ||
| source_path = canonicalized_repo_path.joinpath(repo.file).resolve() | ||
|
Comment on lines
+17
to
+18
|
||
| try: | ||
| source_path.relative_to(canonicalized_repo_path) | ||
| except ValueError as e: | ||
| raise EvalError(f"{repo.name} has invalid file path: {repo.file}") from e | ||
|
|
||
| with tempfile.TemporaryDirectory() as d: | ||
| eval_path = Path(d).joinpath("default.nix") | ||
| with open(eval_path, "w") as f: | ||
|
|
@@ -23,7 +30,7 @@ async def eval_repo(repo: Repo, repo_path: Path) -> None: | |
| import {EVALREPO_PATH} {{ | ||
| name = "{repo.name}"; | ||
| url = "{repo.url}"; | ||
| src = {repo_path.joinpath(repo.file)}; | ||
| src = {source_path}; | ||
| inherit pkgs lib; | ||
| }} | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,12 +60,23 @@ def __init__( | |
| branch: Optional[str], | ||
| locked_version: Optional[LockedVersion], | ||
| ) -> None: | ||
| name_path = Path(name) | ||
| if ( | ||
| name_path.is_absolute() | ||
| or name in ("", ".", "..") | ||
| or name_path.name != name | ||
| ): | ||
| raise ValueError(f"invalid repository name: {name}") | ||
|
Comment on lines
+63
to
+69
|
||
|
|
||
| self.name = name | ||
| self.url = url | ||
| self.submodules = submodules | ||
| if file_ is None: | ||
| self.file = "default.nix" | ||
| else: | ||
| file_path = Path(file_) | ||
| if file_path.is_absolute() or ".." in file_path.parts: | ||
| raise ValueError(f"invalid repository file path: {file_}") | ||
| self.file = file_ | ||
| self.branch = branch | ||
| self.locked_version = None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TemporaryDirectory(prefix=str(repo_path.parent))uses an absolute path as the name prefix, which is a non-obvious way to influence where the temp dir is created (and can create it as a sibling ofrepos/, not inside it). Consider switching todir=repo_path.parent(with a simple prefix likenur-) to make the intent explicit and avoid path-separator/portability edge cases.