Skip to content

Keep four commands from building a path that climbs out of its directory - #9425

Open
VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:fix/confine-path-arguments
Open

Keep four commands from building a path that climbs out of its directory#9425
VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:fix/confine-path-arguments

Conversation

@VykosMolt

Copy link
Copy Markdown

omarchy-hook, omarchy-hyprland-toggle, omarchy-toggle and omarchy-state each join an argument straight into a path they then execute, delete or write, and nothing stops the argument from leaving the directory it was meant for.

omarchy-done already refuses ., .. and a name holding a slash, so the rule was in the tree already, in one command, written inline. It cannot be that rule exactly here: omarchy-crash-mute keeps a flag per program under crash-ignore/<program> and omarchy-crash-watch reads it back the same way, so omarchy-toggle has to keep accepting a slash. What climbs is a . or .. component, not a separator.

omarchy-path-guard holds that rule once and the four commands source it. A name is refused when it is empty, when it is absolute, or when any component of it is . or ... crash-ignore/chromium keeps working, crash-ignore/../../escape does not. Ordinary filenames that merely begin with dots (..., ..leading) stay legal, and so do the glob characters omarchy-state clear is given.

The source line is source omarchy-path-guard || exit 1 rather than a bare source, because two of these commands do not set -e, and a guard that can go missing without stopping the command is not a guard.

Testing

Each escape below was run against unmodified quattro with HOME pointed at a scratch directory, and each one worked:

omarchy-hook ../../../../outside-hook
  -> ran that script, four directories above the hooks directory

omarchy-hyprland-toggle ../../../../../../outside off
  -> deleted outside.lua, six above the toggles directory

omarchy-toggle ../../../../../outside-toggle on
  -> created a file five above the state directory

omarchy-state set ../../../../outside-state
  -> created a file four above the state directory

The hook is the worst of the four, since it is execution rather than a write.

test/cli gains eight assertions: the four escapes, checked by whether the file appears, disappears or runs; that crash-ignore/chromium still gets its flag; that crash-ignore/../../escape does not; that weird...name and ..leading are still accepted; and that omarchy-state clear 'globb*' still matches a glob. The first fails on unmodified quattro.

./test/cli passes in full, including the metadata check over bin/.

./test/shell — 217 of 221 files pass; the four failures (config-test, runtime-smoke-test, snapper-test, unowned-system-paths-test) fail identically on unmodified quattro on this machine. crash-capture-test.sh, which exercises the crash-ignore/ namespace through omarchy-toggle, passes with the guard in place.

This comes out of https://github.com/VykosMolt/omarchy-desktop, where I have been running the Quattro shell as a plain Arch session and fixing what turned up.

omarchy-hook, omarchy-hyprland-toggle, omarchy-toggle and omarchy-state each
join an argument straight into a path they then execute, delete or write, with
nothing stopping the argument from leaving the directory it was meant for.
Against a sandboxed HOME on current quattro:

  omarchy-hook ../../../../outside-hook
    runs that script, four directories above the hooks directory

  omarchy-hyprland-toggle ../../../../../../outside off
    deletes outside.lua, six above the toggles directory

  omarchy-toggle ../../../../../outside-toggle on
    creates a file five above the state directory

  omarchy-state set ../../../../outside-state
    creates a file four above the state directory

The hook is the worst of the four, because it is execution rather than a write.

omarchy-done already refuses `.`, `..` and a name holding a slash, so the rule
was already in the tree, in one command, inline. It cannot be that rule exactly:
omarchy-crash-mute keeps a flag per program under `crash-ignore/<program>`, and
omarchy-crash-watch reads it back the same way, so omarchy-toggle has to keep
accepting a slash. What climbs is a `.` or `..` component, not a separator.

omarchy-path-guard holds that rule once and the four commands source it. A name
is refused when it is empty, when it is absolute, or when any component of it is
`.` or `..`, which leaves `crash-ignore/chromium` working and rejects
`crash-ignore/../../escape`. Ordinary filenames that merely start with dots
(`...`, `..leading`) stay legal, and so do the glob characters omarchy-state's
clear pattern is given.

Sourcing is `source omarchy-path-guard || exit 1` rather than a bare source,
because two of these commands do not set -e and a guard that can go missing
without stopping the command is not a guard.

The new tests are the four escapes above, each checked by whether the file
appears, disappears or runs, plus the crash-ignore namespace and the ordinary
names that have to keep working. The first fails on unmodified quattro.
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.

1 participant