Skip to content

Mask the SDK key in the invalid-key exception and fetch errors - #50

Open
orien wants to merge 1 commit into
configcat:masterfrom
orien:mask-sdk-key-in-errors
Open

orien wants to merge 1 commit into
configcat:masterfrom
orien:mask-sdk-key-in-errors

Conversation

@orien

@orien orien commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Describe the purpose of your pull request

The SDK key can appear unmasked in an exception and in the error logged as event 1103, which error trackers and log pipelines then record. The changes mask it in both places.

  • Invalid-key exception: the ConfigCatClientException message shows the masked key, as the other messages already do.
  • Invalid request URL: when the request URL cannot be used, the fetcher logs a fixed message with the masked key. It no longer logs the URI exception text, which quotes the whole URL, including any credentials in base_url. This covers a key the URL parser rejects and a base_url with no http(s) scheme.
  • Other fetch errors: the fetcher masks the key in the exception text before logging it. Some libraries quote the request URL in their errors, for example WebMock when real connections are disabled.
  • Key format check: a key must be printable ASCII and match the whole string.

Two changes are visible to callers:

  • A key with surrounding whitespace, such as a trailing newline from a file, raises when the client is created. Before, the client was created and each fetch failed.
  • A key with a control character or a non-ASCII character also raises when the client is created.

Related issues (only if applicable)

Fixes #49

How to test? (only if applicable)

  • spec/configcat/configcatclient_spec.rb has new cases for the masked exception, the invalid request URL message, the masked fetch error, and the stricter key format.
  • The full suite passes on Ruby 3.3, and the client and fetcher specs pass on Ruby 3.2. I have not run Ruby 2.5 to 3.1 locally.

Security (only if applicable)

  • The fetch-error masking matches the key as a literal string. It misses a key that an exception quotes in escaped form, which needs a key containing ", \ or #{ and a library that quotes the URL through inspect. URI errors do not take this path.
  • The mask keeps the last six characters, so a value of six characters or fewer still appears in full in the invalid-key exception.
  • An invalid request URL is still treated as a transient failure, so the fetcher retries it once and logs the error twice.

Requirement checklist (only if applicable)

  • I have covered the applied changes with automated tests.
  • I have executed the full automated test set against my changes.
  • I have validated my changes against all supported platform versions.
  • I have read and accepted the contribution agreement.

The invalid-key exception printed the whole SDK key. A request URL that
could not be used, because the key contained a character such as a
space or a quote or because base_url had no http(s) scheme, appeared in
full in the error logged as event 1103, along with any credentials in
base_url. Any other exception that quoted the request URL put the key
in the same error.

Mask the key in the exception, accept only printable ASCII in the
format check, log a fixed message for an invalid request URL in place
of the exception text that quotes it, and mask the key in the text of
other fetch exceptions.
@sonarqubecloud

Copy link
Copy Markdown

@orien
orien marked this pull request as ready for review November 24, 2026 03:54
@orien
orien requested a review from a team as a code owner November 24, 2026 03:54
@kp-cat

kp-cat commented Nov 25, 2026

Copy link
Copy Markdown
Member

Hey @orien,
Thanks for the PR! We'll take a look with the dev team and get back to you.

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.57%. Comparing base (305e080) to head (979de4f).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
lib/configcat/configfetcher.rb 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #50      +/-   ##
==========================================
- Coverage   98.58%   98.57%   -0.02%     
==========================================
  Files          40       40              
  Lines        3466     3511      +45     
==========================================
+ Hits         3417     3461      +44     
- Misses         49       50       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

SDK key is printed unmasked in a raised exception and in a logged error

2 participants