fix(audit): add 's' unit support to sleep-polling-loop detector (#522) - #615
fix(audit): add 's' unit support to sleep-polling-loop detector (#522)#615AVPthegreat wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesSleep polling detector
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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. Comment |
|
Your PR is awaiting review by a reviewer. Till then you can join the Discord for conversation: https://discord.befailproof.ai |
There was a problem hiding this comment.
Pull request overview
Updates the audit detector for sleep-polling-loop so it correctly detects explicit seconds suffixes (e.g. sleep 30s), aligning behavior with the issue report and the detector’s intent (flagging long sleeps/polling loops).
Changes:
- Extend the standalone
sleepregex to accept an explicitsunit suffix. - Add unit tests covering
sleep 30s(match) andsleep 5s(no match).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/audit/detectors/sleep-polling-loop.ts | Regex updated to recognize sleep <n>s so long sleeps with seconds suffix are detected. |
| tests/audit/detectors.test.ts | Adds coverage for sleep 30s and sleep 5s to prevent regression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| // Standalone long sleep. parseFloat so `sleep 0.5m` (= 30s) isn't dropped. | ||
| const match = /\bsleep\s+(\d+(?:\.\d+)?)(m|h|d)?\b/.exec(cmd); | ||
| const match = /\bsleep\s+(\d+(?:\.\d+)?)(s|m|h|d)?\b/.exec(cmd); |
Summary
Fixes #522 by adding support for explicit
s(seconds) unit suffixes in thesleep-polling-loopaudit detector (e.g.sleep 30s).❌ Root Cause Analysis
In
src/audit/detectors/sleep-polling-loop.ts, the regex pattern used to detect standalonesleepcommands was:Why it failed:
(m|h|d)?supported minutes (m), hours (h), and days (d), but omitted seconds (s).sleep 30s(the most standard bash command format):\bsleep\s+matchedsleep(\d+(?:\.\d+)?)matched30(m|h|d)?matched empty string (becausesis notm,h, ord)\b(word boundary) right after30. Becausesimmediately followed30,sis a word character ([a-zA-Z0-9_]), so the word boundary check failed.null, allowing longsleep 30sloops to bypass the audit detector silently.✅ Fix Details
Updated the regex in
src/audit/detectors/sleep-polling-loop.tsto includesin the optional unit capture group:🧪 Unit Tests & Verification
Added new test cases to
__tests__/audit/detectors.test.ts:Test Results:
vitest run __tests__/audit/detectors.test.ts✓ 26 passed (26)Summary by CodeRabbit
sleepcommands that use explicit seconds, such assleep 30s.sleep 5s, continue to be excluded from detection.