Skip to content

Conversation

sejas
Copy link
Member

@sejas sejas commented Sep 12, 2025

Related issues

Proposed Changes

  • Add Auth commands:
    • studio auth login
    • studio auth logout
    • studio auth status
  • Currently it receives and saves the token through Studio App. I'm thinking to receive the token in the terminal.

Testing Instructions

  • Run npm run cli:build
  • Enable the studio sites cli beta feature by adding this JSON node in ~/Library/Application Support/Studio/appdata-v1.json:
  "betaFeatures": {
    "studioSitesCli": true
  }
  • Run ENABLE_CLI_V2=true node dist/cli/main.js auth login

  • Click on approve in your browser

  • Observe you are logged in

  • Run node dist/cli/main.js auth login again

  • Observe the browser doesn't open again because you are already logged in.

  • Run ENABLE_CLI_V2=true node dist/cli/main.js auth status

  • Observe that your data is displayed in the CLI

  • Run ENABLE_CLI_V2=true node dist/cli/main.js auth logout

  • Observe you are logged out

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@sejas sejas self-assigned this Sep 12, 2025
openInBrowser( authUrl );

console.log( __( 'Note: This will open the Studio app to complete authentication.' ) );
console.log( __( "If the Studio app doesn't open automatically, please install it first." ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather not require the Studio App. Did you check the authentication command in my prototype, I have a solution for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. I'll take a look at your branch to bring the logic over here.
I initially took this approach to begin drafting the PR.

Copy link

github-actions bot commented Oct 17, 2025

📊 Performance Test Results

Comparing b681381 vs trunk

site-editor

Metric trunk b681381 Diff Change
load 10054.00 ms 10881.00 ms +827.00 ms 🔴 8.2%

site-startup

Metric trunk b681381 Diff Change
siteCreation 15108.00 ms 14034.00 ms -1074.00 ms 🟢 -7.1%
siteStartup 4934.00 ms 4948.00 ms +14.00 ms 🔴 0.3%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

// Get the CLI command using the copied callback handler
const cliCommand = getCLICommand( destCallbackHandler );

const escapedCliCommand = cliCommand.replace( /"/g, '\\"' );

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI 3 days ago

To fix this problem, we should robustly escape both double quotes (") and backslashes (\) in cliCommand before embedding it in the AppleScript script. This is needed because a backslash followed by a quote or other special sequence would defeat the quote escaping logic if not itself escaped. The best way to achieve this is to first escape all backslashes (replace \ with \\), and then escape all double quotes (replace " with \"), both globally. This can be accomplished with two chained .replace() calls using global regular expressions. It would be clearer and more error-proof to factor this into a helper function, e.g. escapeForAppleScript, but since only a single change can be made in the code block shown, we will directly perform the two-step replacement on line 307. No new imports are needed, and all changes will be confined to the assignment to escapedCliCommand.

Suggested changeset 1
cli/lib/protocol-handler.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/cli/lib/protocol-handler.ts b/cli/lib/protocol-handler.ts
--- a/cli/lib/protocol-handler.ts
+++ b/cli/lib/protocol-handler.ts
@@ -304,7 +304,7 @@
 		// Get the CLI command using the copied callback handler
 		const cliCommand = getCLICommand( destCallbackHandler );
 
-		const escapedCliCommand = cliCommand.replace( /"/g, '\\"' );
+		const escapedCliCommand = cliCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
 
 		const appleScript = `on open location this_URL
     set command to "${ escapedCliCommand } '" & this_URL & "'"
EOF
@@ -304,7 +304,7 @@
// Get the CLI command using the copied callback handler
const cliCommand = getCLICommand( destCallbackHandler );

const escapedCliCommand = cliCommand.replace( /"/g, '\\"' );
const escapedCliCommand = cliCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"');

const appleScript = `on open location this_URL
set command to "${ escapedCliCommand } '" & this_URL & "'"
Copilot is powered by AI and may make mistakes. Always verify output.
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