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

misc/specialisation: escape specialisation name #6422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ToborWinner
Copy link

@ToborWinner ToborWinner commented Feb 9, 2025

The specialisation name is included in home.extraBuilderCommands without being properly escaped and checked. This commit fixes that.

Description

The specialisation name is currently not escaped when included in the command to create the symlink in home.extraBuilderCommands. This PR properly escapes it and adds an assertion to ensure it does not contain a forward slash.

This PR, for example, prevents people from running commands through the specialisation name:

home-manager.users.tobor.specialisation."test && echo 'test' > $out/test.txt".configuration = { };

After rebuilding, the test.txt file is present in the built derivation:

❯ cat .local/state/home-manager/gcroots/current-home/test.txt
test

Note: specialisation.nix was probably implemented by copying how it works in nixpkgs, which currently has the same problem. I will probably submit a PR in nixpkgs later too.

Checklist

  • Change is backwards compatible.

  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all
    or nix build --reference-lock-file flake.lock ./tests#test-all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@ToborWinner
Copy link
Author

The check failure seems to have nothing to do with my PR (nushell is failing because of a hash mismatch).

@ToborWinner ToborWinner force-pushed the fix-specialisation-name-escaping branch from 7b88538 to 4e4565a Compare February 10, 2025 16:56
@ToborWinner
Copy link
Author

I'm pretty new to PRs, so I don't know if I resolved the conversation properly (I don't think it gave you the contribution? Not sure how I should have handled that), so let me know if I did anything wrong. Thank you for the suggestion.

The specialisation name is included in home.extraBuilderCommands without
being properly escaped and checked. This commit fixes that.
@ToborWinner ToborWinner force-pushed the fix-specialisation-name-escaping branch from 4e4565a to 1d8c783 Compare February 10, 2025 17:01
@ToborWinner ToborWinner force-pushed the fix-specialisation-name-escaping branch from 7346d2d to 1d8c783 Compare February 11, 2025 15:18
@ToborWinner
Copy link
Author

ToborWinner commented Feb 11, 2025

I pushed no changes, I just wanted the tests to pass after the nushell test was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants