Skip to content

Read real Windows ACLs in ai_tools fsutil.Stat - #50772

Merged
juan-fdz-hawa merged 2 commits into
mainfrom
50703-ai_tools-world_writable-risk-flag-never-fires-on-windows
Aug 10, 2026
Merged

Read real Windows ACLs in ai_tools fsutil.Stat#50772
juan-fdz-hawa merged 2 commits into
mainfrom
50703-ai_tools-world_writable-risk-flag-never-fires-on-windows

Conversation

@juan-fdz-hawa

@juan-fdz-hawa juan-fdz-hawa commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Resolves #50703

Stat() returned Perm{Known: false} unconditionally on Windows, so the world_writable risk flag on agent_instruction rows could never fire no matter what the file's real ACL was.

Split the permission read per platform: perm_unix.go keeps the mode-bit logic, perm_windows.go reads the DACL via GetSecurityInfo, and perm_acl.go holds the platform-neutral ACE decision rules so they are unit-testable anywhere. Known: false now means "could not determine" rather than "Windows".

Everyone (S-1-1-0) and Authenticated Users (S-1-5-11) count as world; BUILTIN\Users is excluded because standard locations grant it create rights by default.

Also adds ./orbit/pkg/table/ai_tools/... to the Windows CI package list, which otherwise never exercises this code.

Screenshot 2026-08-10 at 10 30 26 AM

Checklist for submitter

If some of the following don't apply, delete the relevant line.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

  • Confirmed that the fix is not expected to adversely impact load test results

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added Windows file permission inspection using access control lists.
    • File permissions now identify world-readable and world-writable items when determinable.
    • Added cross-platform permission checks for Windows and Unix systems.
  • Bug Fixes

    • Improved handling of missing files, unsupported entries, inherited permissions, and indeterminate states.
    • Corrected permission evaluation so explicit deny rules are respected without suppressing unrelated grants.
    • Updated platform-specific checks to avoid misinterpreting Windows permissions as Unix mode bits.

@juan-fdz-hawa

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ac0efe5-366f-4c88-b103-86f5228868c5

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae6498 and ebf73b1.

📒 Files selected for processing (3)
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_test.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_windows.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_windows.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go

Walkthrough

The change adds cross-platform permission detection for ai_tools instruction files. Unix systems inspect POSIX mode bits. Windows systems inspect DACL entries for world-readable and world-writable access. The Windows implementation handles missing files, NULL DACLs, bounded ACE traversal, and unsupported ACE types. Unit tests cover ACL evaluation, and Windows tests validate real ACL configurations. The Windows Go test workflow now includes the ai_tools package.

Possibly related PRs

  • fleetdm/fleet#49243: Adds the earlier fsutil.Stat permission logic that this change extends with platform-specific POSIX and Windows ACL handling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: reading real Windows ACLs in ai_tools fsutil.Stat.
Description check ✅ Passed The description explains the bug, implementation, linked issue, and automated testing, with only non-critical checklist items omitted or unchecked.
Linked Issues check ✅ Passed The changes satisfy issue #50703 by reading Windows DACLs and detecting world-writable Everyone and Authenticated Users permissions.
Out of Scope Changes check ✅ Passed The Windows CI update and platform-specific test changes directly support the Windows ACL permission-detection fix.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 50703-ai_tools-world_writable-risk-flag-never-fires-on-windows

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go`:
- Around line 67-72: Update the ACL evaluation logic around the write decision
handling to track FILE_WRITE_DATA, FILE_APPEND_DATA, DELETE, WRITE_DAC, and
WRITE_OWNER independently rather than collapsing them through writeMask. Set
WorldWritable when any of these effective capabilities is allowed, while
preserving per-capability deny precedence; add a regression case covering DELETE
denied followed by FILE_WRITE_DATA allowed.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go`:
- Around line 11-19: Update the permission lookup around os.Lstat in the
relevant Unix permission function to reject non-regular files, including
symlinks, by returning Perm{Known: false} before evaluating mode bits. Only
compute WorldReadable and WorldWritable for regular files, matching the
OpenRegular behavior on Windows.

In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go`:
- Around line 42-45: In the DACL evaluation logic, make incomplete or
unsupported evaluation return an unknown posture: at the AceCount limit check,
return Perm{} when truncation would occur instead of evaluating a shortened ACL,
and in the non-inherit-only unsupported ACE branch return Perm{} rather than
skipping it. Add tests covering both cases and verify Known is false.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 538a6a5f-9195-44dd-ae22-247c041bda8f

📥 Commits

Reviewing files that changed from the base of the PR and between f656ac5 and 01e55fb.

📒 Files selected for processing (7)
  • .github/workflows/test-go-windows.yml
  • orbit/pkg/table/ai_tools/internal/fsutil/fsutil.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_test.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows_test.go

Comment thread orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go Outdated
Comment thread orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go
Comment thread orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.78378% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.53%. Comparing base (3b47482) to head (ebf73b1).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...bit/pkg/table/ai_tools/internal/fsutil/perm_acl.go 85.18% 2 Missing and 2 partials ⚠️
...it/pkg/table/ai_tools/internal/fsutil/perm_unix.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #50772   +/-   ##
=======================================
  Coverage   68.53%   68.53%           
=======================================
  Files        3977     3979    +2     
  Lines      256148   256181   +33     
  Branches    13627    13627           
=======================================
+ Hits       175561   175586   +25     
- Misses      64973    64978    +5     
- Partials    15614    15617    +3     
Flag Coverage Δ
backend 69.64% <83.78%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

Resolves #50703

Stat() returned Perm{Known: false} unconditionally on Windows, so the
world_writable risk flag on agent_instruction rows could never fire no
matter what the file's real ACL was.

Split the permission read per platform: perm_unix.go keeps the mode-bit
logic, perm_windows.go reads the DACL via GetSecurityInfo, and
perm_acl.go holds the platform-neutral ACE decision rules so they are
unit-testable anywhere. Known: false now means "could not determine"
rather than "Windows".

Everyone (S-1-1-0) and Authenticated Users (S-1-5-11) count as world;
BUILTIN\Users is excluded because standard locations grant it create
rights by default.

Also adds ./orbit/pkg/table/ai_tools/... to the Windows CI package list,
which otherwise never exercises this code.
@juan-fdz-hawa
juan-fdz-hawa force-pushed the 50703-ai_tools-world_writable-risk-flag-never-fires-on-windows branch from 01e55fb to 8ae6498 Compare August 10, 2026 14:00
@juan-fdz-hawa

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go`:
- Around line 43-49: Update worldPermFromACEs to expand GENERIC_READ,
GENERIC_WRITE, and GENERIC_ALL in every ACE mask using the Windows file
generic-rights mapping before applying DACL precedence and computing fresh.
Ensure generic denies affect corresponding specific read/write rights, while
preserving the existing writeMask and readMask evaluations.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ff3d9ef6-5e50-4991-9850-beee5d746d0c

📥 Commits

Reviewing files that changed from the base of the PR and between 3b47482 and 8ae6498.

📒 Files selected for processing (10)
  • .github/workflows/test-go-windows.yml
  • orbit/pkg/table/ai_tools/internal/fsutil/fsutil.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_test.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_acl_windows.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_unix.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows.go
  • orbit/pkg/table/ai_tools/internal/fsutil/perm_windows_test.go
  • orbit/pkg/table/ai_tools/internal/instructions/instructions_test.go
  • orbit/pkg/table/ai_tools/internal/mcp/risk_test.go

Comment thread orbit/pkg/table/ai_tools/internal/fsutil/perm_acl.go Outdated

@getvictor getvictor 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.

Approving .github/workflows/test-go-windows.yml change

@juan-fdz-hawa
juan-fdz-hawa merged commit e5777fe into main Aug 10, 2026
57 checks passed
@juan-fdz-hawa
juan-fdz-hawa deleted the 50703-ai_tools-world_writable-risk-flag-never-fires-on-windows branch August 10, 2026 21:30
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.

ai_tools: world_writable risk flag never fires on Windows

4 participants