Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(cursor): accept grok_-prefixed Cursor API keys (#8001)

teo25382d2c3ffb
diff --git a/apps/web/src/features/settings/Harness.test.tsx b/apps/web/src/features/settings/Harness.test.tsx
index f569e7d9e3..7b530bdb2b 100644
--- a/apps/web/src/features/settings/Harness.test.tsx
+++ b/apps/web/src/features/settings/Harness.test.tsx
@@ -347,19 +347,33 @@ describe('Harness', () => {
expect(mocks.save).not.toHaveBeenCalled();
expect(mocks.toastFailure).toHaveBeenCalledWith(
- 'Cursor API keys start with crsr_'
+ 'Cursor API keys start with grok_ or crsr_'
);
- fireEvent.input(apiKeyInput, { target: { value: ' crsr_example ' } });
+ fireEvent.input(apiKeyInput, { target: { value: ' grok_example ' } });
fireEvent.click(saveButton);
await waitFor(() => {
- expect(mocks.save).toHaveBeenCalledWith('crsr_example');
+ expect(mocks.save).toHaveBeenCalledWith('grok_example');
expect(mocks.toastSuccess).toHaveBeenCalledWith('Cursor connected');
expect(apiKeyInput).toHaveProperty('value', '');
});
});
+ it('still accepts a Cursor API key minted with the older crsr_ prefix', async () => {
+ render(() => <Harness />);
+
+ fireEvent.input(screen.getByLabelText('API key'), {
+ target: { value: 'crsr_example' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => {
+ expect(mocks.save).toHaveBeenCalledWith('crsr_example');
+ });
+ expect(mocks.toastFailure).not.toHaveBeenCalled();
+ });
+
it('shows connection status, the default model picker, and disconnect for connected Cursor', async () => {
mocks.status.data = {
registered: true,
diff --git a/apps/web/src/features/settings/Harness.tsx b/apps/web/src/features/settings/Harness.tsx
index 61ee284769..5bca21a97b 100644
--- a/apps/web/src/features/settings/Harness.tsx
+++ b/apps/web/src/features/settings/Harness.tsx
@@ -30,7 +30,8 @@ import { ConnectAction, HarnessIcon, StatusDot } from './integration-ui';
import { SettingsCard, SettingsPage } from './primitives';
import { RuntimePairingPage } from './RuntimePairingPage';
-const CURSOR_KEY_PREFIX = 'crsr_';
+// Cursor now mints `grok_` keys; the `crsr_` keys minted before that still work.
+const CURSOR_KEY_PREFIXES = ['grok_', 'crsr_'];
function failureMessage(error: unknown, fallback: string): string {
return (error instanceof ThrownResultError && error.message) || fallback;
@@ -136,8 +137,10 @@ export function Harness(
const handleSaveCursorApiKey = async () => {
const apiKey = cursorApiKey().trim();
- if (!apiKey.startsWith(CURSOR_KEY_PREFIX)) {
- toast.failure(`Cursor API keys start with ${CURSOR_KEY_PREFIX}`);
+ if (!CURSOR_KEY_PREFIXES.some((prefix) => apiKey.startsWith(prefix))) {
+ toast.failure(
+ `Cursor API keys start with ${CURSOR_KEY_PREFIXES.join(' or ')}`
+ );
return;
}
@@ -265,7 +268,7 @@ export function Harness(
autocomplete="off"
spellcheck={false}
class="settings-input ph-no-capture min-w-0 flex-1"
- placeholder={`${CURSOR_KEY_PREFIX}…`}
+ placeholder="grok_…"
value={cursorApiKey()}
onInput={(event) =>
setCursorApiKey(event.currentTarget.value)
diff --git a/apps/web/src/lib/service-clients/service-auth/client.ts b/apps/web/src/lib/service-clients/service-auth/client.ts
index c53ce3897c..85020b123b 100644
--- a/apps/web/src/lib/service-clients/service-auth/client.ts
+++ b/apps/web/src/lib/service-clients/service-auth/client.ts
@@ -867,7 +867,8 @@ export const authServiceClient = {
* Stores a Cursor API key for the signed-in user, replacing any existing one.
*
* The key is validated on shape alone, so a typo that still starts with
- * `crsr_` is accepted here and only fails when a session tries to use it.
+ * `grok_` or `crsr_` is accepted here and only fails when a session tries to
+ * use it.
*/
async putCursorApiKey(apiKey: string) {
return (
diff --git a/apps/web/src/lib/service-clients/service-auth/generated/schemas/putCursorApiKeyRequest.ts b/apps/web/src/lib/service-clients/service-auth/generated/schemas/putCursorApiKeyRequest.ts
index d7dbbee596..fcaf63cf70 100644
--- a/apps/web/src/lib/service-clients/service-auth/generated/schemas/putCursorApiKeyRequest.ts
+++ b/apps/web/src/lib/service-clients/service-auth/generated/schemas/putCursorApiKeyRequest.ts
@@ -9,6 +9,6 @@
* The key the user pasted.
*/
export interface PutCursorApiKeyRequest {
- /** A `crsr_…` Cursor API key. */
+ /** A Cursor API key: `grok_…`, or `crsr_…` for older keys. */
apiKey: string;
}
diff --git a/apps/web/src/lib/service-clients/service-auth/openapi.json b/apps/web/src/lib/service-clients/service-auth/openapi.json
index 77b99328ee..760f29c380 100644
--- a/apps/web/src/lib/service-clients/service-auth/openapi.json
+++ b/apps/web/src/lib/service-clients/service-auth/openapi.json
@@ -6838,7 +6838,7 @@
"properties": {
"apiKey": {
"type": "string",
- "description": "A `crsr_…` Cursor API key."
+ "description": "A Cursor API key: `grok_…`, or `crsr_…` for older keys."
}
}
},
diff --git a/crates/cursor_api_key/src/cipher.rs b/crates/cursor_api_key/src/cipher.rs
index 3ca788f9f9..e9f6b895b1 100644
--- a/crates/cursor_api_key/src/cipher.rs
+++ b/crates/cursor_api_key/src/cipher.rs
@@ -3,7 +3,7 @@
//! `kms:Encrypt` directly, not the envelope pattern
//! `microsoft_oauth_grants` uses. The envelope exists so that large plaintext
//! can be encrypted locally under a cheap data key that KMS only has to wrap;
-//! a `crsr_` key is around 60 bytes, far inside KMS's 4 KB direct limit, so
+//! a Cursor key is around 60 bytes, far inside KMS's 4 KB direct limit, so
//! there is nothing to amortize. Both designs make one KMS call per operation,
//! so the envelope's cost here is pure: a data key column, a nonce column, an
//! AES-GCM implementation to review, and a nonce-reuse rule for a future reader
@@ -41,8 +41,9 @@ pub const ENCRYPTION_VERSION: i16 = 1;
/// feature cannot be decrypted as a Cursor key even under the same KMS key.
const ENCRYPTION_PURPOSE: &str = "cursor-api-key";
-/// The prefix every Cursor API key carries.
-const CURSOR_KEY_PREFIX: &str = "crsr_";
+/// The prefixes a Cursor API key carries. Cursor now mints `grok_` keys, and
+/// the `crsr_` keys minted before that still authenticate.
+const CURSOR_KEY_PREFIXES: [&str; 2] = ["crsr_", "grok_"];
/// A Cursor API key in plaintext.
///
@@ -68,10 +69,12 @@ impl CursorApiKey {
let trimmed = supplied
.trim()
.trim_matches(|character| character == '"' || character == '\'');
- if !trimmed.starts_with(CURSOR_KEY_PREFIX) {
- return Err(MalformedCursorApiKey);
- }
- if trimmed.len() <= CURSOR_KEY_PREFIX.len() {
+ let has_secret_after_prefix = CURSOR_KEY_PREFIXES.iter().any(|prefix| {
+ trimmed
+ .strip_prefix(prefix)
+ .is_some_and(|secret| !secret.is_empty())
+ });
+ if !has_secret_after_prefix {
return Err(MalformedCursorApiKey);
}
Ok(Self(Zeroizing::new(trimmed.to_owned())))
diff --git a/crates/cursor_api_key/src/cipher/test.rs b/crates/cursor_api_key/src/cipher/test.rs
index a5483544ca..d3db344918 100644
--- a/crates/cursor_api_key/src/cipher/test.rs
+++ b/crates/cursor_api_key/src/cipher/test.rs
@@ -171,7 +171,21 @@ fn key_parsing_accepts_pasted_keys_and_rejects_the_rest() {
.expose(),
"crsr_abc"
);
- for rejected in ["", "crsr_", "sk-ant-abc", "abc_crsr_abc"] {
+ assert_eq!(
+ CursorApiKey::parse("'grok_abc'\n")
+ .expect("keys Cursor mints now are accepted")
+ .expose(),
+ "grok_abc"
+ );
+ for rejected in [
+ "",
+ "crsr_",
+ "grok_",
+ "sk-ant-abc",
+ "xai-abc",
+ "abc_crsr_abc",
+ "abc_grok_abc",
+ ] {
assert!(
CursorApiKey::parse(rejected).is_err(),
"{rejected:?} should be rejected"
diff --git a/crates/cursor_cloud_agents/src/api.rs b/crates/cursor_cloud_agents/src/api.rs
index afa0cc2b67..6df44f4ac4 100644
--- a/crates/cursor_cloud_agents/src/api.rs
+++ b/crates/cursor_cloud_agents/src/api.rs
@@ -132,10 +132,14 @@ impl std::fmt::Debug for ApiKey {
}
}
+/// The prefixes a Cursor API key carries. Cursor now mints `grok_` keys, and
+/// the `crsr_` keys minted before that still authenticate.
+const CURSOR_KEY_PREFIXES: [&str; 2] = ["crsr_", "grok_"];
+
/// Static configuration for a [`CursorClient`].
#[derive(Debug, Clone)]
pub struct CursorConfig {
- /// The API key (`crsr_…`).
+ /// The API key (`grok_…`, or `crsr_…` for older keys).
pub api_key: ApiKey,
/// Base url, `https://api.cursor.com` outside tests.
pub base_url: String,
@@ -157,7 +161,7 @@ pub enum CursorClientError {
/// diagnostics that are safe to print: enough to recognize a placeholder
/// or a stray quote, never enough to reconstruct a real key.
#[error(
- "not a Cursor API key (got {length} chars starting {prefix:?}, expected a \"crsr_\" prefix)"
+ "not a Cursor API key (got {length} chars starting {prefix:?}, expected a \"grok_\" or \"crsr_\" prefix)"
)]
MalformedKey {
/// Length of the offending key.
@@ -297,7 +301,10 @@ impl CursorClient {
/// picks up in transit, so what is checked here is the key itself.
pub fn new(config: CursorConfig) -> Result<Self, CursorClientError> {
let key = config.api_key.expose();
- if !key.starts_with("crsr_") {
+ if !CURSOR_KEY_PREFIXES
+ .iter()
+ .any(|prefix| key.starts_with(prefix))
+ {
return Err(CursorClientError::MalformedKey {
length: key.len(),
prefix: key.chars().take(4).collect(),
diff --git a/crates/cursor_cloud_agents/src/api/test.rs b/crates/cursor_cloud_agents/src/api/test.rs
index 7428511542..dbe8dc8236 100644
--- a/crates/cursor_cloud_agents/src/api/test.rs
+++ b/crates/cursor_cloud_agents/src/api/test.rs
@@ -51,6 +51,17 @@ fn surrounding_quotes_and_whitespace_are_trimmed() {
assert_eq!(ApiKey::new("'crsr_abc'").expose(), "crsr_abc");
}
+#[test]
+fn both_cursor_key_prefixes_build_a_client() {
+ for key in ["crsr_abc", "grok_abc"] {
+ CursorClient::new(CursorConfig {
+ api_key: ApiKey::new(key),
+ ..config()
+ })
+ .unwrap_or_else(|error| panic!("{key:?} should build a client: {error}"));
+ }
+}
+
/// A placeholder must fail at startup with something recognizable, which is
/// why the error deliberately reports a length and a short prefix.
#[test]
diff --git a/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs b/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs
index c01a42b550..4cdb4e433c 100644
--- a/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs
+++ b/crates/cursor_cloud_agents/src/bin/cursor_cloud_agents.rs
@@ -20,7 +20,8 @@
//! work is invisible to it, and its edits land on a Cursor-side branch.
//!
//! Environment:
-//! - `CURSOR_API_KEY` (required): a `crsr_…` user or service-account key.
+//! - `CURSOR_API_KEY` (required): a `grok_…` (or older `crsr_…`) user or
+//! service-account key.
//! - `CURSOR_REF`: starting ref for new agents (default `main`).
//! - `CURSOR_MODEL`: model id (default: server default).
//! - `CURSOR_API_BASE`: API base url (default `https://api.cursor.com`).
diff --git a/crates/cursor_cloud_agents/src/domain/slash_commands.rs b/crates/cursor_cloud_agents/src/domain/slash_commands.rs
index 4e2b3e1823..5fbf3970f9 100644
--- a/crates/cursor_cloud_agents/src/domain/slash_commands.rs
+++ b/crates/cursor_cloud_agents/src/domain/slash_commands.rs
@@ -2,7 +2,7 @@
//!
//! Cursor's Cloud Agents API has a models list (`GET /v1/models`) and no
//! skills list. The website catalog (`cursor.com/api/dashboard/get-managed-skills`)
-//! is cookie-authenticated and not callable with the `crsr_…` key this crate
+//! is cookie-authenticated and not callable with the API key this crate
//! holds. The commands here are the cloud-usable subset of that catalog:
//! skills Cursor's cloud runtime actually honors when `/name` arrives as
//! ordinary prompt text.
diff --git a/docs/CURSOR_AGENT_TRANSPORT.md b/docs/CURSOR_AGENT_TRANSPORT.md
index 3eecf8b92e..dbd9f9c537 100644
--- a/docs/CURSOR_AGENT_TRANSPORT.md
+++ b/docs/CURSOR_AGENT_TRANSPORT.md
@@ -67,7 +67,7 @@ Already an ACP *agent* backed by the Cursor Cloud Agents API, written sans-io:
`TurnAlreadyActive` — which happens to match Cursor's own `409 agent_busy`.
- `domain/ports.rs` — `CursorAgents`, `RunStream`, `SessionNotifier`, `RepoResolver`.
- `domain/translate.rs` — `TranslateMachine`, SSE events → ACP `SessionUpdate`.
-- `cursor/` — the HTTP/SSE client. `CursorClient::new` validates a `crsr_` prefix.
+- `cursor/` — the HTTP/SSE client. `CursorClient::new` validates a `grok_` or `crsr_` prefix.
- `inbound/acp.rs` — stdio JSON-RPC adapter. Handles `initialize`,
`authenticate`, `session/new`, `session/prompt`.
- `replay.rs` + `fixtures/real/*.sse` + insta snapshots — recorded real sessions
@@ -87,7 +87,7 @@ associated type, resolved once.
### 1. Settings → Agents → Harness
A field to enter a Cursor API key. On submit we validate it before storing:
-`GET /v1/me` with the key. A `crsr_`-prefixed key that authenticates is stored;
+`GET /v1/me` with the key. A `grok_`- or `crsr_`-prefixed key that authenticates is stored;
anything else is rejected with a useful message rather than silently saved.
The stored record is per Macro user. Deleting it is supported and revokes
@@ -172,7 +172,7 @@ docs, which are wrong about the first:
combinations as `variants`, one flagged `isDefault`.
So a mid-session model change needs no new agent and no second credential — it is
-a field on the next run, reachable with the user's own scoped `crsr_` key. There
+a field on the next run, reachable with the user's own scoped API key. There
is no agent-level model update: `PATCH`/`PUT`/`POST` on `/v1/agents/{id}` do not
exist.
@@ -326,7 +326,7 @@ Two existing precedents in the repo, one generation apart:
deliberately opaque errors. This is the considered one.
**Recommendation: direct KMS `Encrypt`/`Decrypt`, not the envelope.** KMS handles
-plaintexts up to 4 KB directly and a `crsr_` key is ~60 bytes, so the envelope's
+plaintexts up to 4 KB directly and a Cursor key is ~60 bytes, so the envelope's
benefits do not apply: we are not over 4 KB, we make one KMS round trip either
way, KMS manages its own nonces so there is no GCM nonce-reuse bound to dodge,
and CMK auto-rotation keeps old ciphertext readable so nothing gets re-encrypted.
diff --git a/packages/sdk/generated/auth/types.gen.ts b/packages/sdk/generated/auth/types.gen.ts
index 51efa324d2..7d31029e8b 100644
--- a/packages/sdk/generated/auth/types.gen.ts
+++ b/packages/sdk/generated/auth/types.gen.ts
@@ -1391,7 +1391,7 @@ export type PublicGtmInviteLink = {
*/
export type PutCursorApiKeyRequest = {
/**
- * A `crsr_…` Cursor API key.
+ * A Cursor API key: `grok_…`, or `crsr_…` for older keys.
*/
apiKey: string;
};
diff --git a/packages/sdk/specs/auth.json b/packages/sdk/specs/auth.json
index 77b99328ee..760f29c380 100644
--- a/packages/sdk/specs/auth.json
+++ b/packages/sdk/specs/auth.json
@@ -6838,7 +6838,7 @@
"properties": {
"apiKey": {
"type": "string",
- "description": "A `crsr_…` Cursor API key."
+ "description": "A Cursor API key: `grok_…`, or `crsr_…` for older keys."
}
}
},
diff --git a/services/authentication_service/src/api/cursor_api_key/put_cursor_api_key.rs b/services/authentication_service/src/api/cursor_api_key/put_cursor_api_key.rs
index f734d7961a..8aef69245e 100644
--- a/services/authentication_service/src/api/cursor_api_key/put_cursor_api_key.rs
+++ b/services/authentication_service/src/api/cursor_api_key/put_cursor_api_key.rs
@@ -13,7 +13,7 @@ use crate::api::context::{ApiContext, AuthorizationService};
#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct PutCursorApiKeyRequest {
- /// A `crsr_…` Cursor API key.
+ /// A Cursor API key: `grok_…`, or `crsr_…` for older keys.
pub api_key: String,
}