Prevent cluster worker from overwriting protected master files - #37694
Merged
Merged
Conversation
Assisted-By: Claude Sonnet 5 <noreply@anthropic.com>
Assisted-By: Claude Sonnet 5 <noreply@anthropic.com>
TomasTurina
approved these changes
Jul 15, 2026
9 tasks
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
MasterHandler.process_files_from_workercheckedos.path.basename()on the raw worker-supplied file path for theclient.keysandexcluded_filesguards, but wrote to a path resolved viasafe_join()/os.path.normpath(), which strips trailing slashes. A key like"etc/ossec.conf/"produced an empty basename, bypassing both guards while still resolving to the realossec.conf. Additionally, the function never checked whether a cluster item was allowed to flow from worker to master, so a worker could push any master-sourced file (agent.conf, rules, decoders, lists) with no bypass at all. The fix computes the basename from the already-normalized path and adds an explicitextra_validcheck to reject any file whose cluster item is not marked as eligible for worker-to-master sync.Proposed Changes
framework/wazuh/core/cluster/master.py: inprocess_files_from_worker, computeclient.keys/excluded_filesbasenames from the normalizedfull_pathinstead of the rawfile_path; add a check that rejects any file whosecluster_items['files'][item_key]['extra_valid']is notTrue.framework/wazuh/core/cluster/tests/test_master.py: addedextra_valid: Trueto the test fixture'scluster_item_key/queue/testing/items so existing tests keep exercising their intended code paths; updatedbasenamecall assertions to reflect the normalized-path argument; added two regression tests (test_master_handler_process_files_from_worker_rejects_non_extra_valid_item,test_master_handler_process_files_from_worker_normalizes_path_before_excluded_check).Results and Evidence
git stashonmaster.pyonly).pytest wazuh/core/cluster/tests/test_master.py: 54 passed.pytest wazuh/core/cluster/tests/: 450 passed (full cluster test suite, no regressions).Artifacts Affected
wazuh-clusterd(master-side cluster file sync).Configuration Changes
None.
Documentation Updates
None.
Tests Introduced
test_master_handler_process_files_from_worker_rejects_non_extra_valid_item(framework/wazuh/core/cluster/tests/test_master.py)test_master_handler_process_files_from_worker_normalizes_path_before_excluded_check(framework/wazuh/core/cluster/tests/test_master.py)Credits
Thanks to @TarPeg007 for reporting this issue.
Review Checklist
no-changelog)