From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 4/5] attr: do not respect symlinks for in-tree .gitattributes
Date: Wed, 9 Nov 2016 16:22:12 +0700 [thread overview]
Message-ID: <CACsJy8ASMBk+Yak7LyybANFYkoU_Poi1ZGY=ufKtq1vSkoYCXQ@mail.gmail.com> (raw)
In-Reply-To: <20161108222127.mejb74maewzhn3qg@sigill.intra.peff.net>
On Wed, Nov 9, 2016 at 5:21 AM, Jeff King <peff@peff.net> wrote:
> On Tue, Nov 08, 2016 at 08:38:55AM +0700, Duy Nguyen wrote:
>
>> > Another approach is to have a config option to disallow symlinks to
>> > destinations outside of the repository tree (I'm not sure if it should
>> > be on or off by default, though).
>>
>> Let's err on the safe side and disable symlinks to outside repo by
>> default (or even all symlinks on .gitattributes and .gitignore as the
>> first step)
>
> Both of those are actually much harder than you might think.
>
> For matching specific names, we have to deal with case-folding. It's
> easy to hit the common ones like ".GITIGNORE" with fspathcmp(). But if
> this is actually protection against malicious repositories, we have to
> match all of the horrible filesystem-specific junk that we did for
> ".git".
We could realpath() it and check if the result path is inside
realpath($GIT_WORK_TREE). The real work would be done by OS. We will
need to check if it points to .git/something, but I think we have that
covered. The approach is a bit heavy for such a sanity check though
> Symlinks are likewise tricky. If we see that a symlink points to
> "foo/../bar", then we don't know if it leaves the repository unless we
> also look at "foo" to see if it is also a symlink. So you really end up
> having to resolve the symlink yourself (and when checking out multiple
> files, there's an ordering dependency).
We do have this dependency problem right now (e.g. files A and
.gitattributes are checked out at the same time and .gitattributes has
some attribute on A). It looks like we resolve it by reading the index
version at checkout time. We probably can do the same for gitattribute
symlinks.
> I think it might be enough to check:
>
> - leading "../" tokens in the symlink's destination can be checked
> against the symlink's path. So "../foo" is OK for path "one/two",
> but not for path "one".
>
> - interior "../" can be disallowed entirely. Technically
> "foo/../bar/../baz" _can_ be a fine symlink destination, but why?
> It's identical to "baz" unless you are following a bunch of interior
> symlinks. And if those are interior symlinks, it's still confusing
> and unnecessarily obfuscated, and a good sign that somebody is
> trying to do something tricky.
Sounds good.
> So one reasonable fix might be to have a config option like
> "core.saneSymlinks" that enforces both of those rules for _all_ symlinks
> that we checkout to the working tree. And it could either refuse to
> check them out, or replace them with a file containing the symlink
> content (as we do on systems that don't support symlinks, IIRC).
I wonder if anyone want core.saneSymlinks on, but they have some links
that do not meet the above checks and still want to follow them
anyway. One way to add such an exception is mark the path with an
attribute "follow". Yeah I have a dependency loop :(
--
Duy
next prev parent reply other threads:[~2016-11-09 9:22 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-02 13:04 [PATCH 0/5] disallow symlinks for .gitignore and .gitattributes Jeff King
2016-11-02 13:06 ` [PATCH 1/5] add open_nofollow() helper Jeff King
2016-11-02 13:06 ` [PATCH 2/5] attr: convert "macro_ok" into a flags field Jeff King
2016-11-02 13:07 ` [PATCH 3/5] exclude: convert "check_index" " Jeff King
2016-11-02 13:08 ` [PATCH 4/5] attr: do not respect symlinks for in-tree .gitattributes Jeff King
2016-11-07 10:03 ` Duy Nguyen
2016-11-07 21:10 ` Jeff King
2016-11-07 21:15 ` Jeff King
2016-11-08 1:38 ` Duy Nguyen
2016-11-08 22:21 ` Jeff King
2016-11-09 9:22 ` Duy Nguyen [this message]
2016-11-09 16:45 ` Jeff King
2016-11-09 20:41 ` Junio C Hamano
2016-11-09 20:43 ` Jeff King
2016-11-09 22:58 ` Junio C Hamano
2016-11-09 23:17 ` Jeff King
2016-11-10 0:18 ` Junio C Hamano
2016-11-10 0:23 ` Jeff King
2016-11-10 11:00 ` Duy Nguyen
2016-11-02 13:09 ` [PATCH 5/5] exclude: do not respect symlinks for in-tree .gitignore Jeff King
2016-11-02 19:46 ` [PATCH 0/5] disallow symlinks for .gitignore and .gitattributes Stefan Beller
2016-11-02 19:56 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACsJy8ASMBk+Yak7LyybANFYkoU_Poi1ZGY=ufKtq1vSkoYCXQ@mail.gmail.com' \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).