Skip to content

fix: improve settings distributor robustness and security#12

Merged
nikuscs merged 1 commit intomainfrom
feature/run-full-checks
Feb 15, 2026
Merged

fix: improve settings distributor robustness and security#12
nikuscs merged 1 commit intomainfrom
feature/run-full-checks

Conversation

@nikuscs
Copy link
Copy Markdown
Owner

@nikuscs nikuscs commented Feb 15, 2026

Summary

Fixed multiple bugs in the settings distributor module, added process.env fallback for env resolution, and introduced .env.agents for dedicated agent secrets.

Key fixes:

  • TOML string escaping now handles newlines, tabs, carriage returns (prevents invalid TOML)
  • TOML inline table parsing now respects quoted strings with commas (prevents silent data loss)
  • TOML scalar insertion now scoped to top-level keys (prevents accidental overwrites in sections)
  • Added warnings for Cursor project-level permission limitations and unsupported Codex keys
  • Deduplicated constants and logic across modules to prevent silent divergence
  • Env resolution now falls back to process.env for CI/shell-exported variables
  • Default env file lookup now includes .env.agents first for dedicated secrets

Test plan

  • All 52 test files pass (379 tests) with 99.83% coverage
  • 7 env-resolver tests including new process.env fallback cases
  • 20 settings-distributor tests covering all provider formats and edge cases
  • Type check passes clean

🤖 Generated with Claude Code


Open with Devin

- Fix TOML string escaping to handle newlines, tabs, carriage returns
- Fix TOML inline table parsing to handle commas in quoted strings
- Fix TOML scalar insertion to only target top-level keys, avoid section overwrites
- Add warning for Cursor project-level permission limitations per security advisory
- Add warning for unsupported Codex permission keys to clarify what's actually mapped
- Deduplicate SETTINGS_TARGETS constant and resolveTargets logic across modules
- Add process.env fallback for env resolution (after file lookup)
- Add .env.agents to default lookup order for dedicated agent secrets
- Improve test coverage for new fallback behavior

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@nikuscs nikuscs merged commit c70c079 into main Feb 15, 2026
1 check passed
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

Comment on lines +10 to +15
return inner
.replace(/\\n/g, '\n')
.replace(/\\r/g, '\r')
.replace(/\\t/g, '\t')
.replace(/\\"/g, '"')
.replace(/\\\\/g, '\\');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Sequential regex replacements in unquote corrupt values containing escaped backslashes

The unquote function in src/core/env-resolver.ts:10-15 processes escape sequences using sequential regex replacements in an order that cannot correctly handle escaped backslashes preceding other escape characters like \n, \r, or \t.

Root Cause and Impact

For a .env file containing KEY="hello\\nworld" (intended to represent the literal string hello\nworld), the inner content after stripping quotes is the character sequence h,e,l,l,o,\,\,n,w,o,r,l,d.

Step 1 (replace(/\\n/g, '\n')) matches the second backslash + n first, converting it to a newline character. The first backslash is left as-is, producing hello\<newline>world instead of the intended hello\nworld.

Processing \\ last at step 5 cannot fix this because the \n has already been consumed. Reordering the replacements does not help either—processing \\ first would turn \\n into \n, which step 2 would then convert to a newline.

The fix requires a single-pass replacement, e.g.:

inner.replace(/\\([\\nrt"])/g, (_, ch) => {
  const map: Record<string, string> = { '\\': '\\', n: '\n', r: '\r', t: '\t', '"': '"' };
  return map[ch] ?? ch;
});

Impact: Any double-quoted .env value containing a literal escaped backslash before n, r, t, or " (e.g. Windows paths like C:\\new_folder) will be silently corrupted.

Suggested change
return inner
.replace(/\\n/g, '\n')
.replace(/\\r/g, '\r')
.replace(/\\t/g, '\t')
.replace(/\\"/g, '"')
.replace(/\\\\/g, '\\');
return inner
.replace(/\\([\\nrt"])/g, (_, ch) => {
const map: Record<string, string> = { '\\': '\\', n: '\n', r: '\r', t: '\t', '"': '"' };
return map[ch] ?? ch;
});
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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