fix(security): use relpath containment instead of startswith to prevent prefix-collision bypass #11217

Closed
HAL9000 wants to merge 8 commits from fix-7478-startswith-bypass into master
+7 -1
View File
8
@@ -182,8 +182,14 @@ def _is_under(path: str, root: str) -> bool:
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
def _relative_to(path: str, root: str) -> str:
"""Return the part of *path* relative to *root*.
Uses :func:`posixpath.relpath` for canonical relative-path extraction,
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
consistent with :func:`_is_under`. This avoids string-slicing prefix-collision
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
attacks where an attacker filename is a literal prefix of the sandbox root
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
(see issue #7478).
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
Assumes :func:`_is_under` has already been checked.
"""
if path == root:
return ""
return path[len(root) + 1 :]
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
rel = posixpath.relpath(path, root)
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
return rel.replace("\\", "/")
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.
Review

Unused import causing CI lint failure.
import os (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes CI / lint to fail.

Suggestion: Remove the unused import.

**Unused import causing CI lint failure.** `import os` (line 14) is never used anywhere in this file. This triggers pylint W0611 and causes `CI / lint` to fail. Suggestion: Remove the unused import.
Review

Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but _is_under() already uses posixpath.relpath(path, root) in the base commit. This is the correct fix described in the issue.

The only code change is adding import os which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.

**Core issue — no behavioral change.** The PR title claims ‘use relpath containment instead of startswith’ but `_is_under()` already uses `posixpath.relpath(path, root)` in the base commit. This is the correct fix described in the issue. The only code change is adding `import os` which does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.