Skip to content

fix(windows): trust ScheduledTasks module during elevation - #1821

Merged
Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/trust-scheduledtasks-module
Aug 18, 2026
Merged

fix(windows): trust ScheduledTasks module during elevation#1821
Wibias merged 1 commit into
lidge-jun:devfrom
luvs01:agent/trust-scheduledtasks-module

Conversation

@luvs01

@luvs01 luvs01 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Import the Windows ScheduledTasks module from the absolute manifest beside the already trusted System32 Windows PowerShell executable.
  • Invoke the module's exported Register-ScheduledTask command object and fail closed when the export is unavailable, instead of relying on inherited command/module lookup during elevation.
  • Pin the elevated-script contract so any additional bare Register-ScheduledTask invocation fails the focused regression test.

Verification

  • Exact-head Bun 1.3.14: tests/windows-elevation-spawn.test.ts + tests/ports.test.ts62 pass, 0 fail, 208 assertions.
  • Exact-head bun run typecheck, bun run privacy:scan, and git diff --check — passed.
  • Stable patch ID remains 3da4d08777d0e169590e0e093a70fa6cb17daa62.
  • The broader content-equivalent Windows elevation selection was previously validated on Bun 1.3.14 and Bun 1.4.0-canary.1: 51 pass, 170 assertions.
  • Windows PowerShell 5.1 x64 absolute ScheduledTasks manifest smoke previously passed.
  • Real UAC / Task Scheduler registration and Windows ARM64 were not exercised locally.
  • The prior maintained macOS run failed the unchanged timing-sensitive findAvailablePort retries the preferred port briefly before falling back test. That exact test passes on this Windows exact head, but a clean maintained macOS job is still required before claiming cross-platform CI green.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability and security when creating scheduled tasks through elevated PowerShell.
    • Ensured the required task-registration command is loaded from a trusted system module before use.
    • Added clearer error handling when the scheduled-task command is unavailable.
  • Tests

    • Expanded coverage for module loading, command validation, and invocation behavior.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 16, 2026
@coderabbitai

coderabbitai Bot commented Aug 16, 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: ASSERTIVE

Plan: Pro Plus

Run ID: f86e2e8e-477f-4278-aa04-975dec8838c7

📥 Commits

Reviewing files that changed from the base of the PR and between 4d9738f and fc82c92.

📒 Files selected for processing (2)
  • src/lib/windows-elevation.ts
  • tests/windows-elevation-spawn.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The elevated PowerShell script derives and imports the trusted ScheduledTasks.psd1 module, validates its exported Register-ScheduledTask command, and invokes the resolved command. Tests verify module loading, validation, error text, and indirect invocation.

Changes

Scheduled Task Resolution

Layer / File(s) Summary
Trusted command resolution and validation
src/lib/windows-elevation.ts, tests/windows-elevation-spawn.test.ts
The elevated script resolves the PowerShell executable directory, imports the trusted ScheduledTasks.psd1 module, validates Register-ScheduledTask, and invokes the exported command reference. Tests verify these script requirements and the missing-command error text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to fc82c

This is a localized Windows elevation change with the reported focused tests and checks passing; no actionable merge-blocking risk remains beyond normal review and validation.

Suggested reviewers: wibias, lidge-jun

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: trusting and explicitly importing the ScheduledTasks module during Windows elevation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu @Wibias

@Wibias
Wibias marked this pull request as ready for review August 17, 2026 03:56
@luvs01
luvs01 marked this pull request as draft August 17, 2026 04:09
@luvs01
luvs01 force-pushed the agent/trust-scheduledtasks-module branch from 43dba8d to fc82c92 Compare August 17, 2026 12:25

luvs01 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current dev 4d9738f43601eec2a063658efa89d33420bea5b7; exact head is fc82c92d00d0fda4cffd8995bbdf752a5ef8b2fe.

Exact-head validation passed: typecheck, privacy scan, diff check, and 62 focused Windows-elevation/port tests (208 assertions). Stable patch ID is unchanged. The previously failing macOS port test passes locally on Windows, but the PR remains Draft until a maintained macOS run is green and the exact-head review completes.

Maintainer action requested: please approve the fork-gated Cross-platform CI run 32029800674 and React Doctor run 32029800408.

@github-actions
github-actions Bot marked this pull request as ready for review August 17, 2026 12:26
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Wibias
Wibias merged commit f5bce1b into lidge-jun:dev Aug 18, 2026
36 of 38 checks passed

Wibias commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Thanks @luvs01, merged. This is useful because the elevated Windows path no longer depends on ambient PowerShell command or module resolution at the exact point where we cross UAC. Pinning ScheduledTasks to the trusted System32 PowerShell installation removes that lookup ambiguity, fails closed if the expected export is missing, and the regression test makes the security property much harder to accidentally undo later. Appreciate the focused scope and verification.

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants