Skip to content

security: sanitize error messages in API routes (CodeQL js/stack-trace-exposure) - #2209

Merged
diegosouzapw merged 5 commits into
release/v3.8.0from
claude/fix-security-issues-bq251
May 13, 2026
Merged

diegosouzapw merged 5 commits into
release/v3.8.0from
claude/fix-security-issues-bq251

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Summary

  • Replace error.message forwarding in HTTP 500 responses with generic "Internal server error" messages across 9 API routes, fixing CodeQL js/stack-trace-exposure alerts
  • Add CodeQL suppression comment (lgtm[js/insufficient-password-hash]) for intentional SHA-256 usage in src/lib/sync/tokens.ts (hashing high-entropy random tokens, not passwords)
  • Upgrade console.logconsole.error for error logging in affected routes

Affected files

File Issue
src/app/api/oauth/kiro/social-authorize/route.ts error.message in 500 response
src/app/api/oauth/kiro/social-exchange/route.ts error.message in 500 response
src/app/api/oauth/kiro/import/route.ts error.message in 500 response
src/app/api/oauth/kiro/auto-import/route.ts error.message in 500 response
src/app/api/oauth/cursor/import/route.ts error.message in 500 response
src/app/api/oauth/cursor/auto-import/route.ts error.message in 500 response (2 locations)
src/app/api/oauth/[provider]/[action]/route.ts error.message in 500 response (4 locations)
src/app/api/model-combo-mappings/route.ts error.message in 500 response
src/app/api/model-combo-mappings/[id]/route.ts error.message in 500 response (3 locations)
src/lib/sync/tokens.ts False-positive js/insufficient-password-hash suppression

Test plan

  • Verify that 500 error responses no longer include internal error details
  • Confirm errors are still logged server-side for debugging
  • Check CodeQL scan passes on the branch

Generated by Claude Code

diegosouzapw and others added 3 commits May 10, 2026 23:36
* "Claude PR Assistant workflow"

* "Claude Code Review workflow"
Bumps [mermaid](https://github.com/mermaid-js/mermaid) from 11.14.0 to 11.15.0.
- [Release notes](https://github.com/mermaid-js/mermaid/releases)
- [Commits](https://github.com/mermaid-js/mermaid/compare/mermaid@11.14.0...mermaid@11.15.0)

---
updated-dependencies:
- dependency-name: mermaid
  dependency-version: 11.15.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…e exposure

Replace direct error.message forwarding in HTTP responses with generic
messages across OAuth and model-combo-mappings routes (CodeQL js/stack-trace-exposure).
Add CodeQL suppression for intentional SHA-256 token hashing in sync/tokens.ts.

Affected routes: kiro/social-authorize, kiro/social-exchange, kiro/import,
kiro/auto-import, cursor/import, cursor/auto-import, [provider]/[action],
model-combo-mappings (list/create/get/update/delete).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves error handling and observability across several API routes by replacing detailed client-side error messages with generic ones and upgrading server-side logging from console.log to console.error. It also includes security scanner suppression comments for SHA-256 usage. Feedback includes a suggestion to log a swallowed error in the Cursor auto-import route and a recommendation to use the modern codeql prefix for suppression comments instead of the legacy lgtm format.

} catch (error) {
db?.close();
return { found: false, error: `Failed to read database: ${(error as any).message}` };
return { found: false, error: "Failed to read database" };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The error is being swallowed here without logging. Since this PR aims to improve observability by upgrading console.log to console.error while sanitizing client-side messages, the internal error should be logged server-side for debugging purposes.

    console.error("Failed to read Cursor IDE database:", error);
    return { found: false, error: "Failed to read database" };

Comment thread src/lib/sync/tokens.ts
Comment on lines +19 to +22
// CodeQL: Intentionally SHA-256, NOT password hashing. Sync tokens are
// high-entropy random values (osync_ + 32 random bytes) — not user passwords.
// lgtm[js/insufficient-password-hash]
return createHash("sha256").update(rawToken).digest("hex"); // nosemgrep: insufficient-password-hash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use the modern codeql[...] prefix for suppression comments instead of the legacy lgtm[...] format. While GitHub currently supports both for backward compatibility, codeql is the standard for GitHub Advanced Security and explicitly matches the tool mentioned in the PR title.

Suggested change
// CodeQL: Intentionally SHA-256, NOT password hashing. Sync tokens are
// high-entropy random values (osync_ + 32 random bytes) — not user passwords.
// lgtm[js/insufficient-password-hash]
return createHash("sha256").update(rawToken).digest("hex"); // nosemgrep: insufficient-password-hash
// CodeQL: Intentionally SHA-256, NOT password hashing. Sync tokens are
// high-entropy random values (osync_ + 32 random bytes) — not user passwords.
// codeql[js/insufficient-password-hash]
return createHash("sha256").update(rawToken).digest("hex"); // nosemgrep: insufficient-password-hash

- Add tests/unit/error-message-sanitization.test.ts: covers model-combo-mappings
  routes (success, 400, 404 paths) and sync token hashing (satisfies PR Test Policy)
- Log swallowed error in cursor/auto-import tryIdeAuth() catch block (Gemini #1)
- Use codeql[...] prefix instead of legacy lgtm[...] in sync/tokens.ts (Gemini #2)
@github-actions

github-actions Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

CI Coverage Report

  • Coverage job: cancelled
  • PR test policy: success

Coverage artifact was not available for this run.

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.0 May 13, 2026 02:17
@diegosouzapw
diegosouzapw marked this pull request as ready for review May 13, 2026 02:17

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b57068588f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard Claude PR review when auth secret is unavailable

This workflow runs on every pull_request, but it always passes secrets.CLAUDE_CODE_OAUTH_TOKEN to anthropics/claude-code-action without checking whether the secret exists. On forked or Dependabot PRs, GitHub does not provide repository secrets, so this input becomes empty and the Claude action fails authentication, creating a failing check on those PRs. Add an if guard (or skip logic) for actors/events where secrets are unavailable so external PRs don't fail solely because the token is inaccessible.

Useful? React with 👍 / 👎.

Comment on lines +16 to +19
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict Claude mention triggers to trusted users

The job condition only checks whether a comment/body contains @claude, so any public user can trigger a full workflow run by posting that string. Even if the action later rejects non-writers, the runner and action startup still execute, which enables easy workflow-spam and unnecessary CI spend. Add an author-permission gate (for example, require collaborator/write association) in the if expression before starting the job.

Useful? React with 👍 / 👎.

@diegosouzapw
diegosouzapw merged commit 20b35c4 into release/v3.8.0 May 13, 2026
1 of 2 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner Author

✅ Merged into release/v3.8.0 — thank you for the thorough security fix! The CodeQL js/stack-trace-exposure remediation across all 9 routes is clean, the SHA-256 suppression annotation in tokens.ts is well-justified, and the 204-line test suite covering both the sanitized error paths and sync token helpers is a great addition. This will be included in the upcoming v3.8.0 release.

One minor enhancement was applied during merge conflict resolution: the kiro auto-import route's log message was updated to [kiro auto-import] save error: (matching the format introduced in the release branch) while keeping your sanitized "Internal server error" response — best of both.


Generated by Claude Code

diegosouzapw added a commit that referenced this pull request May 14, 2026
Deep audit of all 320 commits since v3.7.9 found:
- 18 merged PRs not documented in CHANGELOG (4 features, 10 bug fixes, 1 security, 2 chores, 1 debug improvement)
- 3 contributors entirely missing from credits table (@NomenAK with 12 PRs, @kang-heewon, @one-vs)
- 4 existing contributors with inaccurate PR counts (@oyi77 8→12, @ddarkr 2→3, @andrewmunsell 2→3, @nickwizard 2→3)

New entries added:
- feat: #2135 (1proxy settings), #2227 (antigravity project ID), #2238 (Z.AI Search), #2240 (CLI Suite)
- fix: #2217, #2218, #2219, #2221, #2222, #2223, #2224, #2231, #2233, #2236, #2242, #2243
- security: #2209 (stack trace exposure)
- chore: #2228, #2234

Total contributors updated from 50+ to 55+.
This was referenced May 14, 2026
@diegosouzapw
diegosouzapw deleted the claude/fix-security-issues-bq251 branch May 14, 2026 18:03
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
Deep audit of all 320 commits since v3.7.9 found:
- 18 merged PRs not documented in CHANGELOG (4 features, 10 bug fixes, 1 security, 2 chores, 1 debug improvement)
- 3 contributors entirely missing from credits table (@NomenAK with 12 PRs, @kang-heewon, @one-vs)
- 4 existing contributors with inaccurate PR counts (@oyi77 8→12, @ddarkr 2→3, @andrewmunsell 2→3, @nickwizard 2→3)

New entries added:
- feat: diegosouzapw#2135 (1proxy settings), diegosouzapw#2227 (antigravity project ID), diegosouzapw#2238 (Z.AI Search), diegosouzapw#2240 (CLI Suite)
- fix: diegosouzapw#2217, diegosouzapw#2218, diegosouzapw#2219, diegosouzapw#2221, diegosouzapw#2222, diegosouzapw#2223, diegosouzapw#2224, diegosouzapw#2231, diegosouzapw#2233, diegosouzapw#2236, diegosouzapw#2242, diegosouzapw#2243
- security: diegosouzapw#2209 (stack trace exposure)
- chore: diegosouzapw#2228, diegosouzapw#2234

Total contributors updated from 50+ to 55+.
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
Deep audit of all 320 commits since v3.7.9 found:
- 18 merged PRs not documented in CHANGELOG (4 features, 10 bug fixes, 1 security, 2 chores, 1 debug improvement)
- 3 contributors entirely missing from credits table (@NomenAK with 12 PRs, @kang-heewon, @one-vs)
- 4 existing contributors with inaccurate PR counts (@oyi77 8→12, @ddarkr 2→3, @andrewmunsell 2→3, @nickwizard 2→3)

New entries added:
- feat: diegosouzapw#2135 (1proxy settings), diegosouzapw#2227 (antigravity project ID), diegosouzapw#2238 (Z.AI Search), diegosouzapw#2240 (CLI Suite)
- fix: diegosouzapw#2217, diegosouzapw#2218, diegosouzapw#2219, diegosouzapw#2221, diegosouzapw#2222, diegosouzapw#2223, diegosouzapw#2224, diegosouzapw#2231, diegosouzapw#2233, diegosouzapw#2236, diegosouzapw#2242, diegosouzapw#2243
- security: diegosouzapw#2209 (stack trace exposure)
- chore: diegosouzapw#2228, diegosouzapw#2234

Total contributors updated from 50+ to 55+.
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