What does the path '/../' mean?

17

Wondering where a path that looks like this '/../' would point to outside a file? I'm guessing it might be something like always specifying the root directory and then the relative parent directory to the file it was written in?

Eugene Lai

Posted 2016-09-29T01:43:33.467

Reputation: 191

1The parent of root is root so it's the same as / – Sami Kuhmonen – 2016-09-29T01:44:34.340

1So do you mean writing /../ is the same as / then...? – Eugene Lai – 2016-09-29T01:45:38.363

1Yes, it is. You can't go to root's parent so it is directed to root itself – Sami Kuhmonen – 2016-09-29T01:47:01.227

3

However, see unix, difference between path starting with '/' and '//'.

– G-Man Says 'Reinstate Monica' – 2016-09-29T05:30:22.653

/../ is only meaningful if it is within a path. – Amani Kilumanga – 2016-09-29T08:59:13.330

yes I've realised this in the context of the codebase I was in - it was pointing to a path outside it as an absolute path – Eugene Lai – 2016-09-29T09:10:27.170

Did you see this in somebody's code? Someone might prepend this to an arbitrary string (e.g. a command line parameter) to force it to be an absolute path (and also avoid the 'implementation-defined behavior' allowed by the POSIX standard described in @G-Man's link). – Spencer – 2016-09-29T10:41:28.100

It's likely an attempt by a malicious actor to circumvent a restriction - you used to see /../ in URLs, hoping that the web server would translate that directly into a path from the server's data directory. It's certainly something to watch out for if your programs ever access files on behalf of less-trusted users. – Toby Speight – 2016-09-29T10:59:40.057

Answers

32

Lets break /../ down piece by piece

The first /indicates the root of the file system This is the top most level of the filesystem

.. means the parent folder However, since we are at the top most level, we cannot go higher, so we are still at the top most folder

adding / at the end indicates a folder. This is never mandatory, unless specifying a subfolder path or file. So we are still at the top most folder on the file system.

So, /../ is no different than typing /

Keltari

Posted 2016-09-29T01:43:33.467

Reputation: 57 019

24Except when you're in chroot, and the kernel is sufficiently buggy that such tricks let you escape the chroot. (It used to be the case years ago, I think.) – user1686 – 2016-09-29T06:11:01.610

8The trailing slash can be significant in some cases. For example, if /example is a symlink to a directory, ls -l /example will display the symlink, whereas ls -l /example/ will display the contents of the directory. – Flimm – 2016-09-29T08:30:33.870

you could contrast with cd ../abc i.e. where ../ does make a difference. I guess it's only useful for relative paths, not for absolute paths. – barlop – 2016-09-29T11:40:24.900

1@barlop ../ can have an effect for absolute paths: /foo/bar/../quux = /foo/quux. Some more useful examples: 1) realizing you just tab completed a really long directory name, but it wasn't the one you wanted. ../ might be quicker than backspacing 50 times. 2) foo=/long/absolute/path/to/foo; bar=$foo/../bar; – 8bittree – 2016-09-29T13:51:09.473

@TobySpeight I believe that to be the case, yes, as this is mostly Windows-land – cat – 2016-09-29T14:10:57.540

1@grawity Closing the .. escape path if implementing chroot as a jail is as obvious as closing the barn door to keep the animals in; you don't miss a case like that: the most obvious escape path. That leads me to suspect that early chroot implementations might not have had inescapability as a requirement. – Kaz – 2016-09-29T19:00:23.937

@Kaz I think it was even explicitly stated that they didn't. I can't remember where, but there was a description about how chroot was originally nothing more than a helper for buildsystems. – user1686 – 2016-09-30T04:38:24.010