You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extensions/git-id-switcher/docs/ARCHITECTURE.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,57 @@ try {
151
151
152
152
Surfacing these errors would confuse users with irrelevant messages.
153
153
154
+
### Binary Path Cache with TTL
155
+
156
+
`security/binaryResolver.ts` caches resolved binary paths with a **30-minute TTL**:
157
+
158
+
```typescript
159
+
interfaceCacheEntry {
160
+
path:string;
161
+
resolvedAt:number;
162
+
}
163
+
```
164
+
165
+
**Why TTL?** VS Code sessions can last days. Without TTL, a binary replaced after initial resolution would continue to be trusted. The 30-minute window balances security (periodic re-verification) with performance (no per-command filesystem checks).
166
+
167
+
`clearPathCache()` ignores TTL and clears immediately (used during identity switching).
168
+
169
+
### Security Event Rate Limiter
170
+
171
+
`security/securityLogger.ts` includes a per-event-type rate limiter:
172
+
173
+
-**Window**: 10 seconds, **Max events**: 10 per event type
174
+
- Excess events are dropped with a count; next allowed event includes `dropped: N events`
175
+
176
+
**Why?** Prevents log flooding from rapid validation failures (e.g., malformed config triggering repeated errors). Without rate limiting, an attacker could cause I/O exhaustion via log writes.
177
+
178
+
### O_NOFOLLOW Symlink Protection
179
+
180
+
`logging/fileLogWriter.ts` uses `O_NOFOLLOW` when opening log files:
181
+
182
+
```typescript
183
+
fs.constants.O_WRONLY|
184
+
fs.constants.O_CREAT|
185
+
fs.constants.O_APPEND|
186
+
fs.constants.O_NOFOLLOW;
187
+
```
188
+
189
+
Combined with post-open `fstat()` symlink verification. This mitigates TOCTOU between `isSecureLogPath()` and the actual file open.
190
+
191
+
**Platform note**: `O_NOFOLLOW` is Unix-only. On Windows, symlink creation requires admin privileges, making the risk inherently lower.
192
+
193
+
### git.path Binary Verification
194
+
195
+
When `git.path` VS Code setting provides a binary path, `binaryResolver.ts` verifies it by running `execFile(absolutePath, ['--version'])` and checking the output starts with `git version`. This prevents a user-configured path from pointing to a non-git binary.
196
+
197
+
**Note**: Uses `execFile()` directly (not `secureExec()`) to avoid circular dependency.
198
+
199
+
### ESLint `no-restricted-imports` for child_process
200
+
201
+
`eslint.config.mjs` prohibits importing `exec` and `execSync` from `child_process`/`node:child_process`. Only `execFile` and `execFileSync` are permitted.
202
+
203
+
This is a lint-time enforcement of the architectural decision to never use shell-based execution. The grep-based CI check remains as defense-in-depth.
204
+
154
205
---
155
206
156
207
## Code Markers
@@ -186,6 +237,16 @@ These exclusions are intentional and should not be removed:
0 commit comments