fix(credentials): strip CR/LF from values to prevent INI injection#131
Merged
zeshi-du merged 1 commit intoJul 2, 2026
Merged
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change sanitizes credential values in ChangesCredential Serialization Sanitization
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
zeshi-du
approved these changes
Jul 2, 2026
zeshi-du
left a comment
Contributor
There was a problem hiding this comment.
Reviewed and verified — merging. Thanks for the contribution!
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When the credentials file is serialized, a field value containing a newline (CR/LF) is written across multiple lines. Because the file is INI-style (key = value), an embedded newline lets an attacker inject arbitrary key/value pairs -- or a whole new section header -- into the credentials file.
Why it matters
A valid API key or endpoint URL never contains a newline. But a value that reaches serialization from a compromised environment variable or a MITM'd backend response could smuggle a newline and override the stored api_key that is read back on the next invocation. This is a write-path hardening for a security-sensitive file.
Fix
In serializeCredentials, strip CR/LF from every value before writing it, and skip the field if stripping empties it. IP/URL/key values are unaffected; only embedded newlines are removed.
Tests
Added regression tests to src/lib/credentials.test.ts covering values with embedded \n, \r, and \r\n -- asserting the serialized output stays single-line-per-field and round-trips without injected keys. Fail on main before the fix, pass after.
Local run: the only failing credentials tests are the pre-existing Windows-only ones (file mode 0600 -> 0666 and the ~ path check); they pass on Linux CI. typecheck + prettier clean.
Summary by CodeRabbit
Bug Fixes
Tests