Skip to content

Prevent cluster worker from overwriting protected master files - #37694

Merged
TomasTurina merged 2 commits into
4.14.8from
fix/5533-cluster-worker-overwrite
Jul 15, 2026
Merged

TomasTurina merged 2 commits into
4.14.8from
fix/5533-cluster-worker-overwrite

Conversation

@vikman90

@vikman90 vikman90 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description

MasterHandler.process_files_from_worker checked os.path.basename() on the raw worker-supplied file path for the client.keys and excluded_files guards, but wrote to a path resolved via safe_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 real ossec.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 explicit extra_valid check 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: in process_files_from_worker, compute client.keys/excluded_files basenames from the normalized full_path instead of the raw file_path; add a check that rejects any file whose cluster_items['files'][item_key]['extra_valid'] is not True.
  • framework/wazuh/core/cluster/tests/test_master.py: added extra_valid: True to the test fixture's cluster_item_key/queue/testing/ items so existing tests keep exercising their intended code paths; updated basename call 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

  • Confirmed both new tests fail against the pre-fix code and pass after the fix (verified via git stash on master.py only).
  • 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

  • Code changes reviewed
  • Relevant evidence provided
  • Tests cover the new functionality
  • Configuration changes documented
  • Developer documentation reflects the changes
  • Meets requirements and/or definition of done
  • No unresolved dependencies with other issues
  • PR is linked to the relevant issue(s)
  • Correct labels applied (e.g., no-changelog)

vikman90 added 2 commits July 15, 2026 10:50
Assisted-By: Claude Sonnet 5 <noreply@anthropic.com>
Assisted-By: Claude Sonnet 5 <noreply@anthropic.com>
@vikman90
vikman90 requested a review from a team July 15, 2026 08:51
@vikman90 vikman90 self-assigned this Jul 15, 2026

@jotacarma90 jotacarma90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TomasTurina
TomasTurina merged commit ee22cda into 4.14.8 Jul 15, 2026
16 checks passed
@TomasTurina
TomasTurina deleted the fix/5533-cluster-worker-overwrite branch July 15, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants