fix(security): use relpath containment instead of startswith to prevent prefix-collision bypass #11217
fix-7478-startswith-bypass into master
8 |
@@ -182,8 +182,14 @@ def _is_under(path: str, root: str) -> bool:
|
|||
|
|
||||
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,
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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).
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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.
|
||||
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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 :]
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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)
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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("\\", "/")
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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.
|
||||
|
||||
|
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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.
HAL9001
commented
Unused import causing CI lint failure. 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.
HAL9001
commented
Core issue — no behavioral change. The only code change is adding **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.
|
||||
Unused import causing CI lint failure.
import os(line 14) is never used anywhere in this file. This triggers pylint W0611 and causesCI / lintto fail.Suggestion: Remove the unused import.
Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but
_is_under()already usesposixpath.relpath(path, root)in the base commit. This is the correct fix described in the issue.The only code change is adding
import oswhich does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.Unused import causing CI lint failure.
import os(line 14) is never used anywhere in this file. This triggers pylint W0611 and causesCI / lintto fail.Suggestion: Remove the unused import.
Core issue — no behavioral change.
The PR title claims ‘use relpath containment instead of startswith’ but
_is_under()already usesposixpath.relpath(path, root)in the base commit. This is the correct fix described in the issue.The only code change is adding
import oswhich does nothing to security or behavior. This PR appears to be a stale no-op submitted after the actual security fix was already committed.