Skip to content

fix: validate app ID via shell:AppsFolder instead of string check#112

Merged
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:fix/resolve-known-folder-guid-path
Mar 17, 2026
Merged

fix: validate app ID via shell:AppsFolder instead of string check#112
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:fix/resolve-known-folder-guid-path

Conversation

@JezaChen
Copy link
Contributor

Problem

The previous app ID validation in launch_app was too simplistic — it stripped a hardcoded set of special characters (\, _, ., -, !) and then checked whether the remainder was purely alphanumeric (isalnum()). This approach suffered from both false negatives and false positives:

  • False negatives: Legitimate app IDs containing characters not in the whitelist (e.g. Microsoft.AutoGenerated.{525860DE-BA83-3DA3-C7D9-9E4A0AEA596C}) would be incorrectly rejected.
  • False positives: Any arbitrary string composed of alphanumeric characters plus the whitelisted special characters would pass validation, even if no such application exists on the system.

Solution

Replace the string-format heuristic with an actual lookup against the Windows shell. A new _is_valid_app_id method queries the shell:AppsFolder COM object via Shell.Application.NameSpace('shell:AppsFolder').ParseName(appId) to determine whether the app ID corresponds to a real installed application. This eliminates both false positives and false negatives.

Changes

  • Add _is_valid_app_id method that queries shell:AppsFolder to verify the app ID exists
  • Remove the old character-stripping validation logic from launch_app

The previous alphanumeric validation was too fragile — legitimate app
IDs could be rejected and invalid ones could pass. Query the
shell:AppsFolder COM object to check whether the app ID actually exists
before attempting to launch it.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copilot AI review requested due to automatic review settings March 17, 2026 16:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Windows app launching by replacing the previous AppID “string shape” validation with a real existence check against shell:AppsFolder, reducing both false negatives (valid but complex AppIDs) and false positives (valid-looking but nonexistent IDs).

Changes:

  • Added _check_app_exists() to validate an AppID by querying Shell.Application.NameSpace('shell:AppsFolder').ParseName(...) via PowerShell.
  • Removed the previous character-stripping/isalnum() heuristic in launch_app.
  • Updated launch_app to reject AppIDs that don’t resolve in shell:AppsFolder.
Comments suppressed due to low confidence (1)

src/windows_mcp/desktop/service.py:502

  • launch_app now runs an extra PowerShell subprocess for every non-path AppID (first _check_app_exists, then Start-Process). This adds noticeable overhead given execute_command spawns a new shell each time. Consider folding validation into the same PowerShell invocation as the launch (e.g., ParseName + Start-Process in one script, returning a clear error if not found) to avoid the double round-trip.
            if not self._check_app_exists(appid):
                return (f"Invalid app identifier: {appid}", 1, 0)
            
            safe = ps_quote(f"shell:AppsFolder\\{appid}")
            command = f"Start-Process {safe}"
            response, status = self.execute_command(command)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +468 to +469
def _check_app_exists(self, app_id: str) -> bool:
"""Check if an app with the given AppID exists in shell:AppsFolder."""
Comment on lines +497 to 498
if not self._check_app_exists(appid):
return (f"Invalid app identifier: {appid}", 1, 0)
@Jeomon Jeomon merged commit 7c19b42 into CursorTouch:main Mar 17, 2026
3 of 4 checks passed
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.

3 participants