Repository navigation
chore(cursor): Spine sessionStart warm-start - #1
Conversation
Add Cursor sessionStart hook (spine brief --cursor-hook) and AGENTS Spine block per AgentsProtocol ADR-0005.
There was a problem hiding this comment.
Review Summary
This PR adds several valuable features: a sessionStart Cursor hook for the Spine warm-start, a live OpenAI-compatible connection test endpoint (with correct nonce/permission gating), hardened API key field handling (clear-on-save, blank-preserves-existing), URL allowlist enforcement on LLM suggestions, and a cursor-based bulk processing pagination replacement.
Issues Requiring Attention
Security — call_openai() error redaction (LLM_Auto_Redirect.php lines 889–897): The API key is redacted from the error message using a string-exact str_replace. If a provider wraps or encodes the token in its error text (e.g., "key":"sk-..." vs. just the bare token), the redaction will miss it and the key will surface in the error message returned to the admin UI. Consider normalizing or omitting the api_error detail entirely when returning it to the client — the message is already sanitized and truncated, but the partial-leak risk remains.
Defensive correctness — missing return after wp_send_json_error / wp_send_json_success: handle_openai_connection_test_ajax() (line 677) and the early-exit path in handle_bulk_process_ajax() (line 1103) do not return after calling the JSON response helpers. Production WordPress terminates via wp_die() so this is currently safe, but the test harness in test-connection-diagnostics.php uses thrown exceptions for this — meaning a future mock change could silently allow fall-through to wp_send_json_success() after a failure branch. All other AJAX handlers in this file use return defensively; these two new additions should follow the same pattern.
Pre-existing Issues (not introduced by this PR, for visibility)
call_openrouter()unconditionally logs the full raw response body viaerror_log()(lines 963–964). This is a debug artifact that should not be in production code as it may log large LLM responses.call_gemini()passes the API key as a URL query parameter (?key=...) (line 993), which exposes it in server access logs and HTTP proxies. The Gemini API also supports thex-goog-api-keyrequest header as an alternative.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| if ($api_error !== '') { | ||
| if (!empty($api_key)) { | ||
| $api_error = str_replace($api_key, '[redacted]', $api_error); | ||
| } | ||
| $api_error = sanitize_text_field($api_error); | ||
| if (strlen($api_error) > 300) { | ||
| $api_error = substr($api_error, 0, 300) . '…'; | ||
| } | ||
| } |
There was a problem hiding this comment.
🛑 Security Vulnerability: sanitize_text_field() is applied to the raw API error message before checking the string length at line 894, but sanitize_text_field collapses whitespace which may silently shorten the string — more critically, the redaction of the API key via str_replace on line 891 is done on the unsanitized string so the token can still leak if the error message contains it in a form that survives sanitize_text_field. More critically: the token redaction at line 891 is string-exact; if the provider wraps the key in quotes or encodes it, str_replace will miss it and the raw key is surfaced in the error returned to the admin UI.1
Footnotes
-
CWE-312: Cleartext Storage of Sensitive Information - https://cwe.mitre.org/data/definitions/312.html ↩
| if (is_wp_error($result)) { | ||
| wp_send_json_error($result->get_error_message()); | ||
| } |
There was a problem hiding this comment.
🛑 Logic Error: handle_openai_connection_test_ajax() does not return after wp_send_json_error() at line 677. In production WordPress, wp_die() terminates execution so this is safe, but any test environment that mocks wp_send_json_error without throwing/exiting will fall through to wp_send_json_success() on line 680, incorrectly reporting a successful connection despite an error. Add an explicit return; after each wp_send_json_error() call for defensive correctness — this is the same pattern used in all other AJAX handlers in this file.
| wp_send_json_success([ | ||
| 'processed' => 0, | ||
| 'created' => 0, | ||
| 'total' => $total_count, | ||
| 'offset' => $offset, | ||
| 'processed' => 0, | ||
| 'created' => 0, | ||
| 'cursor' => $new_cursor, | ||
| 'complete' => true, | ||
| 'message' => 'No more 404s to process' | ||
| ]); |
There was a problem hiding this comment.
🛑 Logic Error: wp_send_json_success() on line 1103 is not followed by a return statement. In production, wp_die() handles the exit, but the missing return causes execution to fall through to the rest of handle_bulk_process_ajax() in any environment where wp_send_json_success does not terminate (e.g., test mocks that throw instead of exiting). Add return; after the wp_send_json_success() call inside the if (empty($all_results)) block.
Summary
sessionStarthook + AGENTS Spine block (ADR-0005)Test plan
spine --project . brief --cursor-hookreturns JSONMade with Cursor