Skip to content

fix: resolve all P1/P2 security and crash issues (#6–#33)#84

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-p1-p2-issues
Draft

fix: resolve all P1/P2 security and crash issues (#6–#33)#84
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-p1-p2-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

Summary

This PR fixes all 25 P1/P2 issues found in the issue tracker, covering shell injection, path traversal, XSS, authentication, memory safety, crash/panic scenarios, and logic bugs.


Changes

🔴 P1 Security

Issue File Fix
#33/#19 android/device.rs Shell-quote every adb argument with POSIX single-quote wrapping to prevent metacharacter injection
#32 handlers/system.rs Cap HTTP scrape response body at 10 MB; reject oversized content-length early
#31 platform/macos/ax.rs Replace get_unchecked() on CFArray with safe .get() to prevent UB on inconsistent AX API lengths
#28 android/input.rs Escape \n and \r in adb input text — they were treated as command terminators by the device shell
#27 android/input.rs Validate press_key argument against KEYCODE_[A-Z0-9_]+ allowlist
#26 android/navigation.rs Validate launch_app package name against [a-zA-Z0-9._] to prevent shell injection
#25 main/index.ts Validate tabId with /^[\w-]+$/ before using it in file paths; validation moved to top of handler
#24 main/index.ts Restrict coworkerFetchUrl local file reads to within the user's home directory
#23 Settings/shared.tsx Configure marked renderer to strip raw HTML blocks, preventing XSS via dangerouslySetInnerHTML
#7 main.rs + nativecore-service.ts + computer-use.ts Generate a cryptographically-random 64-char bearer token at startup; enforce Authorization: Bearer <token> on every HTTP MCP request; thread token through all MCP config injection paths

🔴 P1 Crash / Safety

Issue File Fix
#30 handlers/system.rs Return an error when HOME is unset instead of silently resolving ~/x as /x
#29 hover_tracker.rs, screen_recorder.rs Replace .unwrap() on Mutex::lock() with .unwrap_or_else(|e| e.into_inner()) to avoid cascading panics on mutex poison
#10 parent_watch.rs Exit the process on thread spawn failure instead of silently ignoring — prevents orphaned processes

🔴 P1 Correctness

Issue File Fix
#9 handlers/system.rs Use -KILL/-TERM flag for pkill; -s is a session-ID filter, not a signal selector
#8 singleton.rs Acquire flock(LOCK_EX) around the read-kill-write critical section to eliminate the TOCTOU race

🟡 P2

Issue File Fix
#18 gateway/adapter.ts Replace unbounded Map with BoundedMap(100) — evicts least-recently-inserted entries above limit
#17 nativecore-service.ts Replace proc.stdout! non-null assertion with explicit null guard and early rejection
#16 find_image.rs Return 0.0 when denominator is zero or non-finite in NCC, rather than propagating NaN
#15 gateway/bridge/input.ts Map any role that is not 'assistant' to 'user' to prevent Anthropic API 400 errors
#14 cron.ts Clamp setTimeout delay to 2^31 - 1 ms (≈24.8 days); reschedule without firing when capped
#13 handlers/system.rs Use tasklist /FO CSV /NH on Windows instead of Unix-only ps -axo
#12 handlers/system.rs Canonicalize the search root path via std::fs::canonicalize to prevent find ../../etc traversal
#11 handlers/system.rs Check cp exit status and return an error when it fails
#6 find_image.rs Guard search_region boundaries against u32 underflow before performing ss_w - r.x

Test Results

  • Rust: 80/81 tests pass; the 1 failure (test_execute_command_osascript) is pre-existing (macOS-only test, Linux CI environment lacks osascript)
  • TypeScript: 413/414 tests pass; the 1 failure (injectOpencodeMcpUrl) is pre-existing (XDG_CONFIG_HOME set in CI overrides the test's home parameter)
  • No new test failures introduced by these changes

Copilot AI and others added 2 commits May 12, 2026 13:28
- #33/#19: Shell-quote all args passed to Android adb shell (device.rs)
- #32: Cap HTTP scrape body at 10 MB to prevent OOM (system.rs)
- #31: Replace get_unchecked() with safe CFArray.get() (ax.rs)
- #30: Return error when HOME is unset instead of resolving ~/x as /x
- #29: Use unwrap_or_else(|e| e.into_inner()) for all Mutex locks
- #28: Escape \n and \r in adb input text to prevent injection
- #27: Validate press_key against KEYCODE_* allowlist
- #26: Validate launch_app package_name against [a-zA-Z0-9._] regex
- #25: Validate tabId with /^[\w-]+$/ before using in file paths
- #24: Restrict coworkerFetchUrl local file reads to home directory
- #23: Configure marked renderer to strip raw HTML (XSS prevention)
- #18: Replace unbounded Maps with BoundedMap(100) in gateway adapter
- #17: Guard proc.stdout null assertion with explicit null check
- #16: Fix NaN score when denom is 0.0 or non-finite in NCC
- #15: Map unknown message roles to 'user' for Anthropic API
- #14: Cap setTimeout delay at 2^31-1 ms to prevent overflow wraparound
- #13: Use tasklist on Windows instead of Unix-only ps flags
- #12: Canonicalize search root path to prevent path traversal in find
- #11: Check cp exit status and return error on failure
- #10: Exit on thread spawn failure instead of silently ignoring
- #9: Use -KILL/-TERM flag for pkill (not -s which is session filter)
- #8: Use flock(LOCK_EX) to eliminate TOCTOU race in singleton.rs
- #7: Generate random bearer token; enforce Authorization on HTTP MCP
- #6: Guard search_region against u32 underflow before subtraction

Agent-Logs-Url: https://github.com/unbug/tday/sessions/8970ef9a-ecea-4326-845b-afe8d08d83ed

Co-authored-by: unbug <799578+unbug@users.noreply.github.com>
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.

2 participants