Skip to content

Harden omarchy-tui-install against desktop-entry injection - #10692

Closed
xmreur wants to merge 7 commits into
omacom:quattrofrom
xmreur:harden-tui-install
Closed

xmreur wants to merge 7 commits into
omacom:quattrofrom
xmreur:harden-tui-install

Conversation

@xmreur

@xmreur xmreur commented Sep 7, 2026

Copy link
Copy Markdown

Summary

  • Port require_plain_name, desktop_string_escape, and download_icon from omarchy-webapp-install into omarchy-tui-install
  • Escape Name/Comment/Exec/Icon in the written .desktop file (file-syntax only; no Exec-spec re-quoting of APP_EXEC)
  • Index TUI launchers in omarchy-tui-remove and delete the indexed path so pre-fix nested launchers are removable

Files changed

  • bin/omarchy-tui-install
  • bin/omarchy-tui-remove
  • test/shell.d/tui-install-escaping-test.sh

Test results

  • bash -n on touched scripts: pass
  • git diff --check: clean
  • test/shell.d/tui-install-escaping-test.sh: pass (8 assertions)
  • Related: webapp-install-escaping-test.sh, webapp-name-test.sh, webapp-install-test.sh: pass

Triaged as hardening per discussion with @ErikMelton; follow-up to the webapp-installer hardening in 4.0.2.

@ErikMelton

Copy link
Copy Markdown
Member

One quick issue!

  • Legacy launcher removal leaves its icon behind. omarchy-tui-remove derives the icon name from the shortened picker name. For legacy http://127.0.0.1:4000, it deletes 127-0-0-1-4000.png, while installation created http-127-0-0-1-4000.png. The indexed launcher should retain enough information to remove its actual icon, and the new legacy-removal test should assert that too.

…e icon cleanup. Introduced safe_icon_name and desktop_value functions for better name handling and added checks to remove associated icons for nested launchers.
@xmreur

xmreur commented Sep 7, 2026

Copy link
Copy Markdown
Author

Fixed it!

@ErikMelton

Copy link
Copy Markdown
Member

2 issues with the new changes;

  1. Removal deletes icons it does not own. Icon= may reference an existing shared icon. Removing a TUI configured with shared-icon deletes ~/.local/share/icons/.../shared-icon.png, even though the installer never created it. An untrusted Icon=../../... value can also delete unrelated .png files. Only installer-owned, validated icon names should be removed.

  2. Newlines remain valid launcher names but cannot round-trip through the removal picker

…prove icon removal logic. Introduced desktop_string_unescape for better string processing and added robust checks for icon cleanup associated with TUIs. Updated tests to validate new functionality and ensure proper handling of edge cases.
@ErikMelton

Copy link
Copy Markdown
Member
  1. Interactive removal is broken. The picker passes labelpath, but omarchy-menu-select interprets two fields as iconlabel and returns only the path. desktop_file remains unset and the launcher is not removed. Rows need an empty/icon field before label and subtext.

  2. Removal can delete icons it does not own. remove_installed_icon deletes every $slug.*, even when the TUI references an existing shared user icon or when no matching launcher exists. For example, removing My App with shared icon my-app deletes an unrelated my-app.svg. Ownership must be recorded or otherwise proven before deletion.

  3. Duplicate display names can remove the wrong launcher. path_for_tui checks Name= labels before desktop basenames. Callers such as omarchy-remove-launcher-entry pass the desktop ID, so another TUI with the same display name can be selected first and permanently deleted. Basename matching should take precedence.

…con management. Introduced logic to track and remove icons associated with installed applications, improving cleanup processes. Updated tests to validate the new functionality and ensure proper handling of edge cases.
@xmreur

xmreur commented Sep 9, 2026

Copy link
Copy Markdown
Author

should be fixed, let me know if anything needs to be changed!

@ErikMelton

Copy link
Copy Markdown
Member

Three issues remain:

  1. Markerless launchers are treated as legacy icon owners.
    omarchy-tui-remove calls remove_legacy_icon whenever X-Omarchy-OwnedIcon is absent, including for newly installed launchers that use shared icons.

For example:

  • Create ~/.local/share/icons/hicolor/256x256/apps/my-app.png
  • Install My App with icon reference my-app
  • Remove My App

The pre-existing shared my-app.png is deleted even though the installer did not create it. Markerless current launchers need to be distinguishable from legacy launchers, or legacy cleanup must avoid deleting icons without proven ownership.

  1. X-Omarchy-OwnedIcon is written without desktop-entry escaping.
    Newline-containing names are allowed, but safe_icon_name preserves internal newlines. When a copied or downloaded icon is used, the ownership value is written across multiple physical lines. desktop-file-validate then rejects the launcher, and removal leaves the icon behind because it reads only the first line.

For example, an app named:

Line One
Line Two

produces:

X-Omarchy-OwnedIcon=line-one
line-two.png

The owned icon name should be normalized to one line or serialized and decoded safely.

  1. desktop_string_unescape corrupts literal escape sequences.
    It replaces \n, \r, and \t before collapsing \\. A literal name such as Literal\tSequence is written as Literal\tSequence, but removal decodes it into a backslash followed by an actual tab.

That tab collides with the picker’s tab-delimited row format, causing interactive removal to calculate the wrong desktop-file path and leave the launcher installed. The decoder needs to process escapes left-to-right so \\ remains a literal backslash and its following character is not decoded again.

…mline icon slug generation. Introduced owned_icon_slug function for consistent icon naming and updated desktop file writing logic. Enhanced omarchy-tui-remove to ensure proper cleanup of owned icons and improved handling of legacy icons. Updated tests to validate new functionality and edge cases.
@ErikMelton

Copy link
Copy Markdown
Member
  • [P2] Record the extension actually copied. icon_ext is normalized for the ownership marker, but install_user_icon independently uses the raw suffix. A source named icon.foo-bar creates odd-extension.foo-bar while recording odd-extension.png; removal can delete an unrelated PNG and leaves the installed icon behind.

  • [P2] Delete the owned icon from only its actual directory. Current installs write only to ICON_DIR, but removal deletes the marked basename from both ICON_DIR and OLD_ICON_DIR. A same-named legacy icon is therefore deleted without ownership.

  • [P2] Make nested legacy launchers reachable through the Remove menu. The remover now scans recursively, but the menu guard still checks only applications/*.desktop. When a nested legacy launcher is the only TUI, Remove → TUI remains hidden; direct CLI removal succeeds.

  • [P3] Ensure the generated icon slug is nonempty. A permitted punctuation- or emoji-only name creates .png and records .png, but remove_owned_icon rejects that basename, permanently orphaning the icon.

@ErikMelton

Copy link
Copy Markdown
Member

[P2] Owned icon filenames can collide. (bin/omarchy-tui-install:108)
Names such as Alpha Beta and Alpha-Beta both own alpha-beta.png. Installing both overwrites the first icon; removing either deletes the icon while the other launcher remains. Use a collision-resistant basename or avoid deletion while another launcher references the marker.

[P3] Empty applications directory incorrectly enables Remove -> TUI (default/omarchy/omarchy-menu.jsonc:291)
When find matches no desktop files, no -exec runs and find exits successfully. The guard therefore shows the removal action despite there being no TUIs.

[P3] Newline-only names cannot be removed interactively. (bin/omarchy-tui-remove:62)
The installer accepts $'\n' as a name. Command substitution strips the decoded newline, yielding an empty picker label; removal then aborts with “You must select a TUI to remove” despite having the selected path.

@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #9150, which covers the same TUI install hardening. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

@bjarneo bjarneo closed this Sep 21, 2026
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.

3 participants