fix(telemetry): create ~/.nansen 0700 and its id/session files 0600 - #582
fix(telemetry): create ~/.nansen 0700 and its id/session files 0600#582devorun wants to merge 1 commit into
Conversation
pr-reviewer Summary for #8e674c2✅ No issues found The code review completed successfully with no findings. Review effort: 1/5 (Trivial) SummaryThis PR correctly fixes a real security bug: The fix is minimal and correct: two named constants ( The tests are well-structured: a fast mock-based assertion on the options passed to Token usage: 12 input, 2,020 output, 144,441 cache read, 28,782 cache write | Usage Guide New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment |
There was a problem hiding this comment.
Auto-approved
This PR was automatically approved because:
- Claude recommends approval
- Claude assessed this as a minimal effort change
- The effort level is within the auto-approval threshold of 2
- No high or critical issues were detected
If you have any concerns, please request a manual review.
Problem
~/.nansenholds the API key (config.json) and the encrypted wallet keystores (wallets/). Every module that writes there creates directories withmode: 0o700and files withmode: 0o600—api.js,wallet.js,keychain.js,privy.js,trading.js,bridge.js,limit-order.js,update-check.js,cost-cache.js,commands/mcp.js.telemetry.jsis the only exception. Its twomkdirSynccalls and threewriteFileSynccalls use default permissions.That matters because
mkdirSync(..., { recursive: true })does not change the mode of a directory that already exists — whichever module creates~/.nansenfirst sets its permissions permanently. Telemetry runs on every non-offline command, so it wins that race whenever no config has been saved yet: most importantly on the documentedNANSEN_API_KEYenv-var path (AGENTS.md, and what the MCP/agent setup uses), wheresaveConfig()never runs at all.Reproduced on Linux with a clean
HOME, calling onlygetAnonymousId()andgetSessionId():nansen doctorclassifies exactly this as insecure —isInsecureMode()insrc/doctor.jsis(mode & 0o077) !== 0, and it tells the user tochmod 700. So the CLI ends up warning about a state it created itself.Fix
Give telemetry's directory and file writes the same modes the rest of the codebase already uses:
0o700for the directory,0o600fortelemetry-idandsession.No behaviour change beyond permissions. The two id files stay exactly where they were, and
modeis ignored for an already-existing file, so upgrading users are unaffected until the files are recreated.Tests
Two regression tests in
src/__tests__/telemetry.test.js:mkdirSync/writeFileSync(runs everywhere);HOME, asserting nothing is group- or world-accessible using the samemode & 0o077predicatedoctor.jsuses. Skipped on Windows, matching the existingplatform !== 'win32'guard indoctor.js.Both fail on
mainand pass with this change.Checklist
npm testpassesnpm run lintpassesconsole.login core, no hardcoded secretspatch)src/schema.jsonunchanged — no commands or options addednpm test: