Skip to content

fix(solution): Stop committing the ContextStream API key - #41

Merged
kploch merged 1 commit into
mainfrom
fix/leaked-contextstream-key
Aug 28, 2026
Merged

fix(solution): Stop committing the ContextStream API key#41
kploch merged 1 commit into
mainfrom
fix/leaked-contextstream-key

Conversation

@kploch

@kploch kploch commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

.cursor/mcp.json carried a live 48-character credential as a literal under the X-ContextStream-API-Key header. Committed in a8fdb29 and pushed to this public repository, so it has been readable by anyone since. It is now on main: merging #11 carried it to the default branch of this public repository as of d73d3d9. This removes it from the branch going forward; it does not remove it from main's history, and merging this PR does not either.

Found by GitHub Copilot's PR reviewer on #11.

Closes #40.

Change

-        "X-ContextStream-API-Key": "<48-character literal>",
+        "X-ContextStream-API-Key": "${env:CONTEXTSTREAM_API_KEY}",

Nothing else in the file changed; it still parses as JSON. Anyone using this configuration now sets CONTEXTSTREAM_API_KEY in their environment.

Status changed since this PR was opened

When this was written the credential was confined to the #11 branch. #11 has since been merged, so the
literal is now in .cursor/mcp.json on main — the default branch of a public repository — and in the
history of every clone, fork and mirror taken since. That moves rotation from "outstanding" to the only
control that actually revokes anything; removing the value cannot.

What this does not do

It does not undo the exposure. The value is still in the branch's commit history and has been public for as long as the branch has been pushed.

Rotating the key in ContextStream is the only action that actually revokes access, and it is still outstanding. This PR stops the value travelling any further; it does not make the old one safe.

Why nothing caught it earlier

Secret scanning is disabled on this repository, so GitHub's push protection — the control that would have blocked this at push time rather than surfacing it at review — never ran. Worth enabling org-wide.

Note that #39 excluded .cursor/** from Codacy. Trivy does secret detection and is enabled here, so that exclusion now also removes this directory from Trivy's reach. Narrowing the exclusion to markdown only, or carving .cursor/ back in for Trivy specifically, is worth doing — tracked on #40.

Related

Summary by Sourcery

Bug Fixes:

  • Replace the committed ContextStream API key with an environment-variable reference to prevent further credential exposure.

CodeAnt-AI Description

Stop exposing the ContextStream API key in the repository

What Changed

  • The ContextStream configuration now reads the API key from the CONTEXTSTREAM_API_KEY environment variable instead of storing the credential directly
  • Users must provide the environment variable to authenticate ContextStream

Impact

✅ Prevents new credential exposure
✅ Keeps API keys out of committed configuration
✅ Preserves ContextStream configuration behavior

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Security
    • Updated API key configuration to read from an environment variable instead of storing the key directly in configuration.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@codeant-ai

codeant-ai Bot commented Aug 23, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Incremental review completed 43e636e Aug 28, 2026 · 11:58 11:59
✅ Reviewed your PR 61f7671 Aug 23, 2026 · 22:25 22:25

@sourcery-ai

sourcery-ai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replace a hard-coded ContextStream API key in the Cursor MCP config with an environment-based reference so the live credential is no longer committed to the repository.

File-Level Changes

Change Details Files
Stop committing a live ContextStream API key by sourcing it from an environment variable in the MCP configuration.
  • Replaced the literal 48-character API key value in the X-ContextStream-API-Key header with an environment variable reference CONTEXTSTREAM_API_KEY.
  • Ensured the .cursor/mcp.json configuration continues to parse as JSON while using the env: substitution syntax.
.cursor/mcp.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bito-code-review

Copy link
Copy Markdown

Bito Automatic Review Skipped - Branch Excluded

Bito didn't auto-review because the source or target branch is excluded from automatic reviews.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the branch exclusion settings here, or contact your Bito workspace admin at kris@ploch.dev.

@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Aug 23, 2026
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 63c3d54c-af24-4481-8e77-f3789b11355a

📥 Commits

Reviewing files that changed from the base of the PR and between d73d3d9 and 43e636e.

📒 Files selected for processing (1)
  • .cursor/mcp.json

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The ContextStream MCP configuration now reads X-ContextStream-API-Key from CONTEXTSTREAM_API_KEY instead of storing a literal key.

Changes

ContextStream credential handling

Layer / File(s) Summary
Replace the hardcoded API key
.cursor/mcp.json
The X-ContextStream-API-Key header now uses ${env:CONTEXTSTREAM_API_KEY}.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 43e63

This localized configuration change removes the committed credential from active configuration while preserving the existing integration contract; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR fulfills the coding objective in [#40] by replacing the literal credential with ${env:CONTEXTSTREAM_API_KEY} and preserving the JSON configuration. Key rotation, environment setup, secret scann…
Out of Scope Changes check ✅ Passed The only change updates the ContextStream API-key value in .cursor/mcp.json. It directly supports the linked issue and introduces no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Title check ✅ Passed The title clearly identifies the main change: removing the committed ContextStream API key from the repository.
Description check ✅ Passed The description clearly explains the change, issue number, security impact, configuration usage, and required key rotation. It does not reproduce the repository checklist section or provide a direct i…
Full details: Linked Issues check

Explanation

The PR fulfills the coding objective in [#40] by replacing the literal credential with ${env:CONTEXTSTREAM_API_KEY} and preserving the JSON configuration. Key rotation, environment setup, secret scanning, push protection, and history cleanup are operational follow-up actions rather than code requirements.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description clearly explains the change, issue number, security impact, configuration usage, and required key rotation. It does not reproduce the repository checklist section or provide a direct issue link, but it is otherwise complete and relevant.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/leaked-contextstream-key

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production 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.

Pull Request Overview

This PR addresses a critical security issue by removing a hardcoded API key from .cursor/mcp.json. The Codacy analysis indicates the changes are 'Up to Standards', with no new quality issues detected.

However, the credentials must be considered compromised because they were previously committed to the repository. Furthermore, there is no automated verification included in the PR to ensure the ${env:VAR} syntax is supported by the tool consuming this configuration. Functionality should be verified before merging to avoid breaking the MCP integration.

About this PR

  • Sensitive credentials remain in the Git commit history. Removing them from the current version of the file does not prevent them from being accessed via historical commits. Manual rotation and revocation of the ContextStream API key in the provider's dashboard are required.

Test suggestions

  • Verify that the Cursor/MCP client correctly interpolates the environment variable ${env:CONTEXTSTREAM_API_KEY}.
  • Verify that .cursor/mcp.json is syntactically valid JSON after the change.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify that the Cursor/MCP client correctly interpolates the environment variable `${env:CONTEXTSTREAM_API_KEY}`.
2. Verify that `.cursor/mcp.json` is syntactically valid JSON after the change.
Low confidence findings
  • There is no verification provided that the ${env:VAR} syntax is supported by the target MCP tool. If the tool expects a literal string and does not perform interpolation, the integration will fail.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread .cursor/mcp.json
.cursor/mcp.json carried a live 48-character credential as a literal
under the X-ContextStream-API-Key header. It was committed in a8fdb29
and pushed to this public repository, so it has been readable by anyone
since. It is not on main.

The literal is replaced with an environment-variable reference, so the
value stops travelling with the repository and never reaches main:

    "X-ContextStream-API-Key": "${env:CONTEXTSTREAM_API_KEY}"

Anyone using this configuration now sets CONTEXTSTREAM_API_KEY in their
environment instead. The file still parses as JSON and nothing else in
it changed.

This does not undo the exposure. The value remains in the branch's
commit history, so rotating the key in ContextStream is the only action
that actually revokes access, and it is still outstanding. Secret
scanning is disabled on this repository, which is why nothing caught
this at push time.

Found by GitHub Copilot's pull request reviewer on #11.

Refs: #40
Copilot AI balanced review requested due to automatic review settings August 28, 2026 11:58
@kploch
kploch force-pushed the fix/leaked-contextstream-key branch from 61f7671 to 43e636e Compare August 28, 2026 11:58
@codeant-ai codeant-ai Bot added size:XS This PR changes 0-9 lines, ignoring generated files and removed size:XS This PR changes 0-9 lines, ignoring generated files labels Aug 28, 2026

@sourcery-ai sourcery-ai 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.

Sourcery assessment

Approved.

Copilot AI 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.

Pull request overview

Replaces the committed ContextStream credential with an environment-variable reference, preventing further exposure.

Changes:

  • Reads the API key from CONTEXTSTREAM_API_KEY.
  • Preserves the existing MCP configuration.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sonarqubecloud

Copy link
Copy Markdown

@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/coverlet

The overall line coverage in commit 43e636e in the fix/leaked-contextst... branch remains at 99%, unchanged from commit d73d3d9 in the main branch.

@bito-code-review

bito-code-review Bot commented Aug 28, 2026

Copy link
Copy Markdown

Bito Automatic Review Skipped - Files Excluded

Bito didn't auto-review this change because all changed files are in the exclusion list for automatic reviews. No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change the excluded files settings here, or contact your Bito workspace admin at kris@ploch.dev.

@kploch
kploch merged commit e69198c into main Aug 28, 2026
13 checks passed
@kploch
kploch deleted the fix/leaked-contextstream-key branch August 28, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live ContextStream API key committed in .cursor/mcp.json

2 participants