Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Hi,
Currently (python 3.10.6 & 3.11.0):
frompathlibimportPathp=Path('/var/log/../../opt')p.is_relative_to('/var/log')>>>Truep=p.resolve()p.is_relative_to('/var/log')>>>False
Once you knowis_relative_to usesrelative_to, this makes more sense but it's not obvious from the documentation and the examples given. Also it can easily lead to code that looks secure but isn't. Case in point, I was tasked with reviewing this code today (simplified for illustration purposes):
path=Path(ROOT_PATH,user_input_rel_path)ifpath.is_relative_to(ROOT_PATH):path.unlink()else:raisePermissionError('Nope!')
I was unsure if I should open a bug or not because one could easily argue it isn't a bug. I do believe however that a warning in the documentation could save a few devs from making a mistake.