Skip to content

chore(cursor): Spine sessionStart warm-start - #1

Merged
SPhillips1337 merged 10 commits into
mainfrom
fix/openai-compat-error-diagnostics
Oct 29, 2026
Merged

SPhillips1337 merged 10 commits into
mainfrom
fix/openai-compat-error-diagnostics

Conversation

@SPhillips1337

Copy link
Copy Markdown
Collaborator

Summary

  • Cursor sessionStart hook + AGENTS Spine block (ADR-0005)

Test plan

  • Hooks load; spine --project . brief --cursor-hook returns JSON

Made with Cursor

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 via error_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 the x-goog-api-key request 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.

Comment thread LLM_Auto_Redirect.php
Comment on lines +889 to +897
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) . '…';
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 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

  1. CWE-312: Cleartext Storage of Sensitive Information - https://cwe.mitre.org/data/definitions/312.html ↩

Comment thread LLM_Auto_Redirect.php
Comment on lines +676 to +678
if (is_wp_error($result)) {
wp_send_json_error($result->get_error_message());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 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.

Comment thread LLM_Auto_Redirect.php
Comment on lines 1103 to 1109
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'
]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛑 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.

@SPhillips1337
SPhillips1337 merged commit c408eb5 into main Oct 29, 2026
3 checks passed
@SPhillips1337
SPhillips1337 deleted the fix/openai-compat-error-diagnostics branch October 29, 2026 14:44
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.

1 participant