Repository navigation
fix(client): stop applying archive mode bits and match ZIP entries by exact path CU-17tkuw5vk8q - #3342
Conversation
🦩 flamingo Code Review✅ Tests and checks passed on this commit (1 lane). 1 finding: 🔴 0 action required · 🟠 1 recommended · 🔵 0 informational Advisory: findings do not block the merge. 1 defect outside any rule
🟠 Recommended (1)
✅ What this change does well
Inline comments: 1 new 2 possible problems checked and ruled out, 1 after reading more of the repository
🧪 Tests and mutationChecks
Stage 2 planned only the OpenGrep lane for this Rust change (passed, no new results); no Rust test or mutation lane ran, so no mutation data exists for the new lines. Run by hand on the same commit c1b04e1 (macOS arm64): make lint clean, make test 817 passed, 0 failed; cargo xwin check --lib for x86_64-pc-windows-msvc clean. The real zip_entry_matches was run over the entry lists of all 786 Windows ZIP releases the server configs point at (meshagent, fleet, osquery, client, chat): same entry as the old suffix match in every one, none missing. 🤖 Prompt for AI agents: fix every findingNext: commit a suggestion, or hand a comment's prompt to your coding agent. React 👍 on a finding that helped and 👎 on one that is wrong: the reviewer learns from both. Review again. New commits are not reviewed until you ask:
Or comment Updated 2026-12-04 09:53 UTC · reviewed from Oleksandr Kelbas's machine |
🦩 flamingo Code Review / security✅ No findings on the current head. Advisory: findings do not block the merge.
1 possible problem checked and ruled out, 1 after reading more of the repository
Review again. New commits are not reviewed until you ask:
Or comment Updated 2026-12-04 10:09 UTC · reviewed from Oleksandr Kelbas's machine |
yevhenii-flamingo
left a comment
There was a problem hiding this comment.
A few follow-ups on upgrade rollback, ZIP matching and coverage.
c1b04e1 to
77fcdee
Compare
|
|
bf916d3 to
649e4f3
Compare
|
Thanks, you're right: |
… exact path macOS tar.gz extract-all and the DMG copy now set 0755 for executables and directories and 0644 for other files, so setuid, setgid and group/other write bits from an archive never reach disk. A failed chmod fails the extraction. Windows ZIP extraction takes an entry only when its whole path matches the target (case-insensitive, either separator), instead of any name ending with it, and the not-found error lists the first entries. CU-17tkuw5vk8q
… the error A ZIP with two entries matching the target is rejected. The not-found error lists entry names escaped and cut to 64 characters. Named the permission constants and added Windows tests for extract_from_zip. CU-17tkuw5vk8q
…r modes The ZIP scan reads entries with by_index_raw, so an entry that cannot be opened no longer fails the extraction of the target. Folders listed in a tar get 0755 like the DMG walk gives them. Added a DMG extraction test that fails without the permission walk. CU-17tkuw5vk8q
…inks in the DMG walk A `./` tar entry no longer changes the mode of the extraction folder, so /Applications keeps 0775. The DMG permission walk opens each item without following symlinks, refuses a file with more than one link and changes the mode through the open file. CU-17tkuw5vk8q
95112e1 to
e0d5b10
Compare
What
The client no longer copies file modes from downloaded archives, and on Windows it takes a file from a ZIP only when the whole entry path matches.
./entry never changes the extraction folder itself, so/Applicationskeeps its mode. A file that fails to chmod now fails the extraction; before, the error was ignored.cp -R, the copied item is walked and set to the same modes, directories 0755. Symlinks are skipped, never followed. Each item is opened withO_NOFOLLOWand changed through the open file, and a file with more than one hard link fails the update, so a link swapped into/Applicationscannot redirect the root chmod. The walk runs inspawn_blocking.zip_entry_matchescompares the whole path. Case is ignored,/and\are the same separator,.and empty parts are ignored. Entry names are read without opening the entries, so an entry that cannot be opened does not block the target. Directory entries are skipped, and a ZIP with two matching entries is rejected. Before, the first entry whose name ended with the target matched, sofleet-osqueryd.exematchedosqueryd.exe.Why
The client runs as root on macOS. A tar entry with setuid, or a group or other write bit, kept that mode on disk, so a tampered or badly built archive could leave a root-owned setuid binary or a file any local user can rewrite. The suffix match on Windows could pick the wrong file when two entries end with the same name.
Worth knowing
archive_permissionsis macOS-only.cp -Ras root already drops setuid, so the DMG walk is defense in depth. The tar path is the real fix.Known limitations
targetFileNamewith a folder goes to folder extraction, which Windows does not support, so a release ZIP that moves the exe into a folder fails the update and no server config can fix it. The release workflows should check the root layout: CU-17tkuw6cgpm.extract_from_tar_gz) still takes the first basename match. No server config uses it with a nested name; it is out of scope here./Applications, which is admin-writable, so the bundle folder itself can still be swapped before the walk lists it. Hard links and symlinked items are refused. Moving the walk into a root-owned staging folder: CU-17tkuw6cgpq.Compatibility check
zip_entry_matchesover each release's entry list.Tests
archive_permissions_tests.rs: modes for executable, plain and directory entries; a tree with setuid, setgid and shared write files is normalized and stays the same on a second run; a symlink pointing outside the tree keeps its target's mode; a hard-linked file is refused and keeps its mode; a missing root is an error.extracted_files_get_agent_decided_modes_not_archive_modesandexisting_setuid_file_is_reset_when_overwritten(macOS): both fail on the old code.existing_directory_listed_in_the_archive_gets_0755covers folders, andcurrent_dir_entry_leaves_the_target_folder_mode_alonechecks a./entry leaves the target at 0775.dmg_extractor_tests.rs(macOS): builds a DMG withhdiutil, extracts it, and checks a 0600 file and a 0700 folder come out 0644 and 0755. It fails without the permission walk.github_download_service_zip_tests.rs, 7 tests on all platforms: case, suffix-only names, both separators,./prefix,..and drive-letter entries do not match, a leading/is ignored like any empty part (harmless: the bytes only go to memory), empty target. 4 more on Windows runextract_from_zipon a built ZIP: a directory entry is skipped and the right file's contents come back, an encrypted entry after the target does not block it, two matching entries are rejected, and the not-found error is one line with escaped, shortened names.make lintclean,make test822 passed, 0 failed.cargo xwin check --libclean.cargo xwin clippy --lib --testsclean. The unit suite ran in a Windows 11 ARM64 VM: 818 passed, 0 failed, and the 10 ZIP tests pass there on the final commit.Device QA
meshagent.exe,openframe-chat.exe,fleet.exeandosqueryd.exe. Client self-update from 1.7.78-dev to 1.7.79 pickedopenframe-client.exe. No "not found in ZIP" lines.Change-Set: fix-harden-archive-extraction
Change set
flamingo-stack/fix-harden-archive-extraction: this pull request is the only one in it so far. Another pull request joins by naming this one in aDepends-Online, or by carrying the sameChange-Setline.Linked work
Linked by the
Depends-On/Change-Setlines in these descriptions; this block is maintained by the hub.