Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #1374

Merged
merged 51 commits into from
May 22, 2024
Merged

Various fixes #1374

merged 51 commits into from
May 22, 2024

Commits on May 17, 2024

  1. Configuration menu
    Copy the full SHA
    f3d5a69 View commit details
    Browse the repository at this point in the history
  2. add validation for path components and tree-names

    ----
    
    Note that this commit also streamlines obtaininig a relative
    path for a directory, which previously could panic.
    Byron committed May 17, 2024
    Configuration menu
    Copy the full SHA
    0d78db2 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2024

  1. feat: add validation for path components

    That way it's easier to assure that forbidden names are never used
    as part of path components.
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    eff4c00 View commit details
    Browse the repository at this point in the history
  2. fix!: validate all components pushed onto the stack when creating lea…

    …ding paths.
    
    This way, everyone using the stack with the purpose of
    altering the working tree will run additional checks to prevent callers
    from sneaking in forbidden paths.
    
    Note that these checks don't run otherwise, so one has to be careful
    to not forget to run these checks whenever needed.
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    874cfd6 View commit details
    Browse the repository at this point in the history
  3. feat!: Stack::at_path() replaces is_dir parameter with mode.

    That way, detailed information about the path-to-be is available not
    only for evaluating attributes or excludes, but also for validating
    path components (in this case, relevant for `.gitmodules`).
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    595fe87 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    9564699 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    1ca6a3c View commit details
    Browse the repository at this point in the history
  6. feat: checkout respects options for core.protectHFS and `core.prote…

    …ctNTFS`.
    
    This also adds `gitoxide.core.protectWindows` as a way to enforce
    additional restrictions that are usually only available on Windows.
    
    Note that `core.protectNFS` is always enabled by default, just like
    [it is in Git](git/git@9102f95).
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    886d6b5 View commit details
    Browse the repository at this point in the history
  7. doc: make clear that indices can contain invalid or dangerous paths.

    It's probably best not to try to protect against violations of constraints
    in this free-to-mutate data-structure and instead suggest to validate entry
    paths before using them on disk (or use the `gix_worktree::Stack`).
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    b6a67d7 View commit details
    Browse the repository at this point in the history
  8. feat: defend against CON device names and more if `gitoxide.core.pr…

    …otectWindows` is enabled.
    
    Note that trailing `.` are forbidden for some reason, but trailing ` ` (space) is forbidden
    as it's just ignored when creating directories or files, allowing them to be clobbered
    and merged silently.
    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    a67d82d View commit details
    Browse the repository at this point in the history
  9. thanks clippy

    Byron committed May 19, 2024
    Configuration menu
    Copy the full SHA
    1076375 View commit details
    Browse the repository at this point in the history
  10. Start on demo script making repo with .. trees, deploying above repo

    This should not be incorporated into automated tests in its current
    form. It is a proof of concept to generate repositories that attempt
    to install real executables in directories where they may be run,
    whereas test fixtures should completely limit all effects to testing
    directories, even in the event of regressions or unexpected failures.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    7fa0185 View commit details
    Browse the repository at this point in the history
  11. Hard-code target to fix remaining replacement bugs

    + Refactor for brevity.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    bf49d73 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    4e3b77d View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    474bf0d View commit details
    Browse the repository at this point in the history
  14. Set LC_ALL=C when using sed on a binary file

    Because some sed implementations, at least the one on macOS, detect
    invalid text in the current locale's encoding and error out. See:
    
    https://stackoverflow.com/questions/19242275/re-error-illegal-byte-sequence-on-mac-os-x
    
    This makes the script work on macOS.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    9180dde View commit details
    Browse the repository at this point in the history
  15. No need to actually create the directories

    Because committing the staged paths creates the necessary Git tree
    objects irrespective of what directories exist or are otherwise
    represented.
    
    In addition to simplifying the proof-of-concept repository, this
    also makes it so its entries are properly ordered in its Git object
    database, so `git fsck` does not report errors about that, and
    exits reporting success (though of course still warns about the
    presence of `..` components).
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    0d15e5c View commit details
    Browse the repository at this point in the history
  16. Don't bother running git show --stat

    Because the output of `git commit` should show that information.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    845c6bc View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    0581966 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    a59c05a View commit details
    Browse the repository at this point in the history
  19. Start on demo script making repo with NTFS stream

    The repo this script makes attempts to check out entries traversing
    the default `$INDEX_ALLOCATION` directory stream of the `.git`
    directory, whose stream name is documented to be `$I30`.
    
    However, although I am able to access directories under this naming
    scheme through other applications, the repositories this script
    currently creates do not appear to trigger the bug in gitoxide. The
    next step is to try specifying the stream type explicitly.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    49eb14c View commit details
    Browse the repository at this point in the history
  20. Use .git::$INDEX_ALLOCATION instead of .git:$I30

    This seems more effective at revealing such a vulnerability.
    
    I don't know why, since both should in principle work fine.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    7041e73 View commit details
    Browse the repository at this point in the history
  21. Start on demo script making repo with .git/… filename

    The repo the script makes contains a filename with slash characters
    in it that, if not rejected, will install a pre-commit hook.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    7daca49 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    981cf5b View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    9436f3f View commit details
    Browse the repository at this point in the history
  24. Reword to be more portable and self-documenting

    This requires xxd now, but it honors its /bin/sh hashbang line, no
    longer assuming printf understands \xNN in a format string.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    89ee180 View commit details
    Browse the repository at this point in the history
  25. Pass --literally to hash-object when making tree

    This is needed on some Git versions. It seems it was not needed
    on older versions, even though their git-fsck detected the unusual
    filenames when run. It is supported even on those older versions,
    so the script should still run on them.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    6846c90 View commit details
    Browse the repository at this point in the history
  26. Start on demo script making repo with ../… filename

    The repo this script makes contains a filename with a slash character
    in it that, if not rejected, will create a file above the working tree.
    
    This is a modification of make_traverse_dotgit_slashes.sh. Both
    require some further revision, and since most of their content is
    duplicated, it may be worthwhile to combine them to avoid that.
    EliahKagan committed May 19, 2024
    Configuration menu
    Copy the full SHA
    4c684ca View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. Apply suggestions from code review

    Co-authored-by: Eliah Kagan <[email protected]>
    Byron and EliahKagan committed May 20, 2024
    Configuration menu
    Copy the full SHA
    bad9a79 View commit details
    Browse the repository at this point in the history
  2. address review comments

    - assure `con` is checked for, and that it's not overzealous.
    - reduce code duplication
    - improve documentation about more obscure parts of the code,
      based on the description in [this commit](git/git@e7cb0b4)
    - upper-case device names in comparisons as this is their canonical form, which also is more recognizable for people who
      are looking for them.
    - make clear why there is asymmetry between COM and LPT numbers.
    - Don't make a partial control-character check, but a complete one (i.e. *b < 32|0x20)
    - Add more variants for stream type tests (as regression protection, the code doesn't really care)
    - various clarifications in path-related tests on Windows
    
    Co-authored-by: Eliah Kagan <[email protected]>
    Byron and EliahKagan committed May 20, 2024
    Configuration menu
    Copy the full SHA
    fcc3b69 View commit details
    Browse the repository at this point in the history

Commits on May 21, 2024

  1. Apply suggestions from code review

    The [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file) article does not state that control characters or non-printable characters are in general forbidden in filenames. Instead, it says that it is okay to
    
    > Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
    
    and then lists various things that are not allowed, where the one that is relevant to control characters is:
    
    > Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. *[...]*
    
    No mention is made of 127 (0x7F).
    
    On Windows 10, I used PowerShell 7 for this experiment, which I believe would also work in PowerShell 6, but not Windows PowerShell, which doesn't support `` `u ``. First, as a baseline, I checked what happened if I tried to create a file whose name contained a low-numbered control character:
    
    ```text
    C:\Users\ek\source\repos\unusual-filenames [main]> echo hello > a`u{8}b
    Out-File: The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\ek\source\repos\unusual-filenames\b'
    C:\Users\ek\source\repos\unusual-filenames [main]> echo hello > a`u{08}b
    Out-File: The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\ek\source\repos\unusual-filenames\b'
    ```
    
    I created a file whose name contained the `DEL` character, and even a file whose entire name is that character:
    
    ```text
    C:\Users\ek\source\repos\unusual-filenames [main]> echo hello > a`u{7F}b
    C:\Users\ek\source\repos\unusual-filenames [main +1 ~0 -0 !]> echo goodbye > `u{7F}
    C:\Users\ek\source\repos\unusual-filenames [main +2 ~0 -0 !]> ls
    
        Directory: C:\Users\ek\source\repos\unusual-filenames
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a---           5/20/2024  5:59 PM              9
    -a---           5/20/2024  5:59 PM              7 ab
    ```
    
    Thus this appears to work fine on Windows, and it seems fine that Git permits it:
    
    ```text
    C:\Users\ek\source\repos\unusual-filenames [main +2 ~0 -0 !]> git status
    On branch main
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            "a\177b"
            "\177"
    
    nothing added to commit but untracked files present (use "git add" to track)
    C:\Users\ek\source\repos\unusual-filenames [main +2 ~0 -0 !]> git add .
    C:\Users\ek\source\repos\unusual-filenames [main +2 ~0 -0 ~]> git commit -m 'Initial commit'
    [main (root-commit) 543ccd5] Initial commit
     2 files changed, 2 insertions(+)
     create mode 100644 "a\177b"
     create mode 100644 "\177"
    ```
    
    Thus, gitoxide should probably permit it too.
    
    To be sure, I also tried creating such a file in Python 3.12 on the same system, by calling the `touch` method on a `Path` object. That worked, too.
    
    Co-authored-by: Eliah Kagan <[email protected]>
    Byron and EliahKagan committed May 21, 2024
    Configuration menu
    Copy the full SHA
    ccbc119 View commit details
    Browse the repository at this point in the history
  2. Adjust make_traverse_dotdot_slashes.sh for environment

    These are changes that do not significantly affect behavior but use
    the set of tools that should be availalble in testing environments,
    as well as refactorings that are useful to do not before really
    making this usable as a fixture.
    
    - Use bash shebang, enable pipefail.
    - Don't require xxd.
    - Don't create an extra temporary file.
    - Shorten, simplify, and clarify some logic.
    EliahKagan committed May 21, 2024
    Configuration menu
    Copy the full SHA
    fe8c2c9 View commit details
    Browse the repository at this point in the history
  3. Combine "slashes" scripts and make it a fixture

    Keeping the changes to make_traverse_dotdot_slashes.sh, this folds
    the make_traverse_dotgit_slsahes.sh logic into it, extracting the
    twice-used parts (which are most of the script) into a function
    that both call. Other changes:
    
    - No longer use command-line arguments. There are two repositories
      that are currently useful to make in this way, and this calls the
      function for each of them.
    
    - Change the style to mostly match that of other fixture scripts,
      including decreasing the indent from 4 to 2 and using the
      function keyword when defining functions.
    
    - Shorten variable names in cases where doing so is unambiguous
      (but not otherwise).
    
    - Eliminate the emit_payload function, since the new make_repo
      function now receives the content on standard input, which can
      be provided by whatever means is convenient (the current calls
      use a here string for the one-line file and a heredoc otherwise).
    EliahKagan committed May 21, 2024
    Configuration menu
    Copy the full SHA
    7e9c769 View commit details
    Browse the repository at this point in the history
  4. Combine non-"slashes" (i.e. trees) scripts and make it a fixture

    At least for now, this does not test the creation of multiple files
    at a time outside of a repository, nor multi-step upward traversal
    with many `../../..` components, since tests using such fixtures
    would be complicated, and may or may not be warranted in the test
    suite.
    
    However, this combines substantial elements of the scripts that
    create repositories with unexpected tree objects (e.g., `..` trees)
    to make a make_traverse_trees.sh script that, when run, produces
    repositories for testing that traverse:
    
    - Upward with a `..` tree: `traverse_dotdot_tree`
    - Downward with `.git` and `hooks` trees: `traverse_dotgit_trees`
    - Similar but with an NTFS stream alias: `traverse_dotgit_stream`
    
    This replaces the `make_traverse_dotdot_trees.sh` and
    `make_traverse_ntfs_streams.sh` scripts with one script that takes
    no command-line arguments and creates multiple repos by calling
    a function. This is thus architecturally similar, broadly speaking,
    to `make_traverse_literal_slashes.sh`, but that produces repos with
    very strangely named blobs, rather than with strangly named trees.
    EliahKagan committed May 21, 2024
    Configuration menu
    Copy the full SHA
    6f44aca View commit details
    Browse the repository at this point in the history
  5. Make more test repos with traversal-attempting blob names

    The approach in make_traverse_literal_slases.sh works about equally
    well for any top level file with strange characters. Before, it was
    only generating such repositores where the filename has slashes,
    causing traversal on all platforms. This has is generate two more
    repositories, with backslashes instead of slashes. That script's
    name is accordingly updated to make_traverse_literal_separators.sh.
    
    Note that while such names with backslashes may be blocked on
    multiple systems under various circumstances, they will only
    perform traversal on Windows.
    EliahKagan committed May 21, 2024
    Configuration menu
    Copy the full SHA
    f3edaa3 View commit details
    Browse the repository at this point in the history
  6. further testing of .git path variants

    This is to see if anything should be done to more effectively
    prevent paths containing `.git` (icase).
    
    In conclusion, I think it's fine to keep allowing it as none
    of the component-validations really kicks in on Linux if backslashes
    are used as path separator. Thus, `.git` shouldn't be more special than
    `..` for example.
    
    The only way to fix this on Linux would be to either enable Windows protections,
    or to disallow `\` as path seprator by default which seems too limitting.
    
    Windows Users will naturally be protected as path-splitting will turn
    these into components, with each of them checked as normal.
    Byron committed May 21, 2024
    Configuration menu
    Copy the full SHA
    4791e31 View commit details
    Browse the repository at this point in the history
  7. better detection of pre-requisites for symlink test (#1373)

    If we are dependent on symlinks, we should be sure that the probe
    actually detects symlinks.
    Byron committed May 21, 2024
    Configuration menu
    Copy the full SHA
    00a1c47 View commit details
    Browse the repository at this point in the history
  8. fix: multi-process safe parallel filesystem capabilities probing (#1373)

    This is achieved by making filenames unique so they won't clash.
    Byron committed May 21, 2024
    Configuration menu
    Copy the full SHA
    bec648d View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    a6710c5 View commit details
    Browse the repository at this point in the history
  10. fix compile warnings

    Byron committed May 21, 2024
    Configuration menu
    Copy the full SHA
    f961687 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    2683235 View commit details
    Browse the repository at this point in the history

Commits on May 22, 2024

  1. fix!: State::from_tree() now performs name validation.

    Previously, malicious trees could be used to create a index with
    invalid names, which is one step closer to actually abusing it.
    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    2ea87f0 View commit details
    Browse the repository at this point in the history
  2. adapt to changes in gix-index

    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    5f86e6b View commit details
    Browse the repository at this point in the history
  3. feat: add path::component_is_windows_device()

    That way it's easy to determine if a component contains a windows device name
    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    f1f0ba5 View commit details
    Browse the repository at this point in the history
  4. fix!: assure that special device names on Windows aren't allowed.

    Otherwise it's possible to read or write to devices when interacting
    with references of the 'right' name.
    
    This behaviour can be controlled with the new `prohibit_windows_device_names` flag,
    which is adjustable on the `Store` instance as field, and which now has to be
    passed during instantiation as part of the new `store::init::Options` struct.
    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    9555efe View commit details
    Browse the repository at this point in the history
  5. adapt to changes in gix-ref

    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    d2ae9d5 View commit details
    Browse the repository at this point in the history
  6. Apply suggestions from code review

    Co-authored-by: Eliah Kagan <[email protected]>
    Byron and EliahKagan committed May 22, 2024
    Configuration menu
    Copy the full SHA
    1242151 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    79dce79 View commit details
    Browse the repository at this point in the history
  8. fix-CI

    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    6f55f2a View commit details
    Browse the repository at this point in the history
  9. update dependencies

    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    cd4de83 View commit details
    Browse the repository at this point in the history
  10. fix: symlink support for zip archives

    This started working with the upgradde of the `zip` crate.
    Byron committed May 22, 2024
    Configuration menu
    Copy the full SHA
    e955770 View commit details
    Browse the repository at this point in the history