Skip to content

Conversation

@andoniaf
Copy link
Member

Context

Adds a new security check defender_safe_attachments_policy_enabled for the m365 provider.

Description

This PR adds a new security check for m365:

  • Check: defender_safe_attachments_policy_enabled
  • Implementation: New check that detects security misconfigurations
  • Tests: Unit tests covering pass, fail, and no-resources scenarios

Steps to review

  1. Review the check implementation at prowler/providers/m365/services/defender/defender_safe_attachments_policy_enabled/
  2. Review the metadata file for correct severity, remediation, and compliance mappings
  3. Run the check tests: poetry run pytest tests/providers/m365/services/defender/defender_safe_attachments_policy_enabled/ -v
  4. Optionally run the check against a test environment

Checklist

Community Checklist
  • This feature/issue is listed in here or roadmap.prowler.com
  • Is it assigned to me, if not, request it via the issue/feature in here or Prowler Community Slack

SDK/CLI

  • Are there new checks included in this PR? Yes
    • If so, do we need to update permissions for the provider? Please review this carefully.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@andoniaf andoniaf requested review from a team as code owners January 20, 2026 09:56
@github-actions github-actions bot added provider/m365 Issues/PRs related with the M365 provider metadata-review labels Jan 20, 2026
Add new security check defender_safe_attachments_policy_enabled for m365 provider.
Includes check implementation, metadata, and unit tests.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

✅ All necessary CHANGELOG.md files have been updated.

@andoniaf andoniaf force-pushed the feat/prowler-708-defender-safe-attachments-policy-enabled branch from caa4de6 to 8eb2e7c Compare January 20, 2026 09:56
@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

Conflict Markers Resolved

All conflict markers have been successfully resolved in this pull request.

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 79.72973% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.41%. Comparing base (31b53f0) to head (d2aa0e9).
⚠️ Report is 1 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (31b53f0) and HEAD (d2aa0e9). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (31b53f0) HEAD (d2aa0e9)
prowler-py3.12-azure 1 0
prowler-py3.9-azure 1 0
prowler-py3.10-azure 1 0
prowler-py3.11-azure 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #9833       +/-   ##
===========================================
- Coverage   86.60%   76.41%   -10.19%     
===========================================
  Files         222      177       -45     
  Lines        5645     9554     +3909     
===========================================
+ Hits         4889     7301     +2412     
- Misses        756     2253     +1497     
Flag Coverage Δ
prowler-py3.10-azure ?
prowler-py3.10-lib 76.41% <79.72%> (?)
prowler-py3.10-m365 88.65% <82.60%> (?)
prowler-py3.11-azure ?
prowler-py3.11-lib 76.35% <79.72%> (?)
prowler-py3.11-m365 88.49% <82.60%> (?)
prowler-py3.12-azure ?
prowler-py3.12-lib 76.35% <79.72%> (?)
prowler-py3.12-m365 88.49% <82.60%> (?)
prowler-py3.9-azure ?
prowler-py3.9-lib 76.35% <79.72%> (?)
prowler-py3.9-m365 88.49% <82.60%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
prowler 76.41% <79.72%> (-10.19%) ⬇️
api ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

🔒 Container Security Scan

Image: prowler:ebad0b1
Last scan: 2026-01-23 13:48:25 UTC

📊 Vulnerability Summary

Severity Count
🔴 Critical 3
Total 3

3 package(s) affected

⚠️ Action Required

Critical severity vulnerabilities detected. These should be addressed before merging:

  • Review the detailed scan results
  • Update affected packages to patched versions
  • Consider using a different base image if updates are unavailable

📋 Resources:

When Microsoft Defender for Office 365 licensing is not available,
PowerShell cmdlets like Get-SafeAttachmentPolicy fail with "not
recognized as a name of a cmdlet" errors.

This change:
- Detects cmdlet not found errors in the PowerShell layer
- Logs a clear WARNING instead of ERROR with licensing guidance
- Allows execution to continue gracefully, skipping affected checks
Test folders should not contain __init__.py files. Only check
implementation folders require them for proper module loading.
When no Safe Attachments policies are found, the check now returns a
FAIL finding instead of no findings. This aligns with Maester/CIS
expectations that absence of required security features indicates
non-compliance.
@HugoPBrito
Copy link
Member

Please also map the check in the corresponding compliances.

…iance

Map the new defender_safe_attachments_policy_enabled check to:
- CIS 4.0 M365 requirement 2.1.4
- CIS 6.0 M365 requirement 2.1.4
@github-actions github-actions bot added the compliance Issues/PRs related with the Compliance Frameworks label Jan 23, 2026
andoniaf and others added 3 commits January 23, 2026 14:39
Move defender_safe_attachments_policy_enabled entry from v5.17.0
(already released) to v5.18.0 unreleased section.
Comment on lines +78 to +94
else:
# For other policies, check if they have secure settings
if policy.enable and policy.action == "Block":
report.status = "PASS"
report.status_extended = f"Safe Attachments policy {policy.name} is enabled with Action=Block."
elif not policy.enable:
report.status = "FAIL"
report.status_extended = (
f"Safe Attachments policy {policy.name} is not enabled."
)
else:
report.status = "FAIL"
report.status_extended = f"Safe Attachments policy {policy.name} has Action={policy.action}, which is less secure than Block."

findings.append(report)

return findings
Copy link
Member

Choose a reason for hiding this comment

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

Default one applies to all users and domains, but custom ones may not. We have to check the higher priority one and ensure all users and domains are selected.
Please use defender_antispam_outbound_policy_configured as reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compliance Issues/PRs related with the Compliance Frameworks metadata-review provider/m365 Issues/PRs related with the M365 provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants