Skip to content

Commit 36f5393

Browse files
docs(release): document v3.0.0 credential backend changes
- add breaking-change release notes for keychain-first credential storage and legacy plaintext deprecation - document backend selection env vars and windows powershell setup examples - update docker/headless auth guidance for env read-only mode - include merged PR #5 newline-formatting fix in release notes Signed-off-by: night-slayer18 <samanuaia257@gmail.com>
1 parent 3425a78 commit 36f5393

5 files changed

Lines changed: 130 additions & 20 deletions

File tree

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -410,32 +410,37 @@ leetcode/
410410

411411
## Authentication
412412

413-
This CLI uses cookie-based authentication. To login:
413+
This CLI uses cookie-based authentication from your LeetCode browser session.
414414

415415
1. Open [leetcode.com](https://leetcode.com) in your browser
416416
2. Login to your account
417417
3. Open DevTools (F12) → Application → Cookies → leetcode.com
418418
4. Run `leetcode login` and paste your `LEETCODE_SESSION` and `csrftoken` values
419419

420-
## Configuration File
421-
422-
Config is stored at `~/.leetcode/config.json`:
423-
424-
```json
425-
{
426-
"credentials": {
427-
"session": "...",
428-
"csrfToken": "..."
429-
},
430-
"config": {
431-
"language": "java",
432-
"editor": "code",
433-
"workDir": "/path/to/leetcode",
434-
"repo": "https://github.com/username/leetcode-solutions.git"
435-
}
436-
}
420+
### Credential Backend
421+
422+
- Default backend: system keychain (`keytar`)
423+
- Explicit encrypted-file backend: set `LEETCODECLI_CREDENTIAL_BACKEND=file`
424+
- File backend requires `LEETCODECLI_MASTER_KEY`
425+
- Env read-only mode: set both `LEETCODE_SESSION` and `LEETCODE_CSRF_TOKEN`
426+
427+
If both env vars are present, the CLI uses them directly and `login/logout` run in read-only env mode.
428+
429+
Windows (PowerShell) quick setup:
430+
431+
```powershell
432+
$env:LEETCODECLI_CREDENTIAL_BACKEND = "keychain"
433+
# or encrypted file backend:
434+
# $env:LEETCODECLI_CREDENTIAL_BACKEND = "file"
435+
# $env:LEETCODECLI_MASTER_KEY = "<your_master_key>"
437436
```
438437

438+
### Config File
439+
440+
Workspace config is stored at:
441+
442+
- `~/.leetcode/workspaces/<name>/config.json`
443+
439444
## Requirements
440445

441446
- Node.js >= 20.0.0
@@ -532,7 +537,7 @@ You can run the CLI using Docker without installing Node.js.
532537
-v "$HOME/.leetcode:/root/.leetcode" \
533538
leetcode-cli list
534539
```
535-
_Note: We mount `~/.leetcode` to persist login credentials and `leetcode` folder to save solution files._
540+
_Note: We mount `~/.leetcode` to persist CLI data (workspace config, snapshots, optional file-backend credentials) and `leetcode` folder to save solution files._
536541

537542
## License
538543

docs/commands.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ See [TUI Guide](tui.md) for complete behavior and screen-specific shortcuts.
4343

4444
Login to LeetCode with browser cookies.
4545

46+
Notes:
47+
- Default credential backend is system keychain.
48+
- Set `LEETCODECLI_CREDENTIAL_BACKEND=file` with `LEETCODECLI_MASTER_KEY` for encrypted file mode.
49+
- If both `LEETCODE_SESSION` and `LEETCODE_CSRF_TOKEN` are set, login runs in read-only env mode.
50+
4651
**Usage**: `leetcode login`
4752

4853
---
@@ -51,6 +56,9 @@ Login to LeetCode with browser cookies.
5156

5257
Clear stored credentials.
5358

59+
Note:
60+
- In env auth mode (`LEETCODE_SESSION` + `LEETCODE_CSRF_TOKEN`), unset env vars in your shell to log out.
61+
5462
**Usage**: `leetcode logout`
5563

5664
---

docs/config.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,48 @@ The CLI requires your LeetCode authentication cookies.
1313
```
1414
5. Paste the values.
1515

16+
## Credential Storage
17+
18+
Credential backend is selected via environment variable:
19+
20+
- Default: `LEETCODECLI_CREDENTIAL_BACKEND=keychain` (system keychain)
21+
- Optional: `LEETCODECLI_CREDENTIAL_BACKEND=file` (encrypted file backend)
22+
- File backend requires: `LEETCODECLI_MASTER_KEY`
23+
- Read-only env mode: set both `LEETCODE_SESSION` and `LEETCODE_CSRF_TOKEN`
24+
25+
When env mode is active, `login/logout` do not persist or clear credentials.
26+
27+
## Windows (PowerShell) Examples
28+
29+
Set backend selection:
30+
31+
```powershell
32+
$env:LEETCODECLI_CREDENTIAL_BACKEND = "keychain"
33+
```
34+
35+
Use encrypted file backend:
36+
37+
```powershell
38+
$env:LEETCODECLI_CREDENTIAL_BACKEND = "file"
39+
$env:LEETCODECLI_MASTER_KEY = "<your_master_key>"
40+
```
41+
42+
Use env read-only auth mode:
43+
44+
```powershell
45+
$env:LEETCODE_SESSION = "<session_cookie>"
46+
$env:LEETCODE_CSRF_TOKEN = "<csrf_cookie>"
47+
```
48+
49+
Clear env variables:
50+
51+
```powershell
52+
Remove-Item Env:LEETCODECLI_CREDENTIAL_BACKEND -ErrorAction SilentlyContinue
53+
Remove-Item Env:LEETCODECLI_MASTER_KEY -ErrorAction SilentlyContinue
54+
Remove-Item Env:LEETCODE_SESSION -ErrorAction SilentlyContinue
55+
Remove-Item Env:LEETCODE_CSRF_TOKEN -ErrorAction SilentlyContinue
56+
```
57+
1658
## Config Command
1759

1860
Use `leetcode config` to view or modify settings.
@@ -55,7 +97,7 @@ Settings are now stored per-workspace for isolation:
5597
| Timer | `~/.leetcode/workspaces/<name>/timer.json` | Per-workspace |
5698
| Collab | `~/.leetcode/workspaces/<name>/collab.json` | Per-workspace |
5799
| Snapshots | `~/.leetcode/workspaces/<name>/snapshots/` | Per-workspace |
58-
| Credentials | `~/.leetcode/credentials.json` | Shared |
100+
| Credentials | Keychain (default) or `~/.leetcode/credentials.v2.enc.json` (file backend) | Shared |
59101
| Bookmarks | `~/.leetcode/bookmarks.json` | Shared |
60102

61103
Use `leetcode workspace current` to see which workspace is active.

docs/docker.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ leetcode submit 1
6161

6262
`-it` is required for TUI mode. The shell function shown above already includes it.
6363

64+
### Authentication in Docker/Headless Environments
65+
66+
System keychain is usually unavailable inside containers, so interactive `leetcode login` is not supported there.
67+
Use env credentials instead:
68+
69+
```bash
70+
docker run -it --rm \
71+
-e LEETCODE_SESSION=\"<your_session_cookie>\" \
72+
-e LEETCODE_CSRF_TOKEN=\"<your_csrf_cookie>\" \
73+
-w /root/leetcode \
74+
-v \"$(pwd)/leetcode:/root/leetcode\" \
75+
nightslayer/leetcode-cli:latest list
76+
```
77+
78+
When both env vars are set, the CLI runs in read-only env auth mode.
79+
6480
## Build Locally
6581

6682
If you prefer to build it yourself:

docs/releases.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
# Release Notes
22

3+
## v3.0.0
4+
5+
> **Release Date**: 2026-03-10
6+
> **Focus**: Credential Backend Overhaul (Keychain-First) + Auth Hardening
7+
8+
### ⚠️ Breaking Changes
9+
10+
- Credential persistence model is now backend-driven and no longer reads legacy plaintext `~/.leetcode/credentials.json`.
11+
- Existing users with only legacy plaintext credentials must run `leetcode login` again.
12+
- Default credential backend is now OS keychain (`keytar`).
13+
14+
### 🔐 Security & Auth
15+
16+
- Added deterministic credential backend resolver:
17+
- `env-readonly` mode when `LEETCODE_SESSION` and `LEETCODE_CSRF_TOKEN` are both set.
18+
- `keychain` backend by default.
19+
- Explicit encrypted-file backend via `LEETCODECLI_CREDENTIAL_BACKEND=file` + `LEETCODECLI_MASTER_KEY`.
20+
- Added typed auth storage status/reason handling across CLI and TUI:
21+
- `ENV_PARTIAL`, `KEYCHAIN_UNAVAILABLE`, `KEYCHAIN_ERROR`, `FILE_MISSING_MASTER_KEY`, `FILE_DECRYPT_FAILED`, `LEGACY_CREDENTIALS_IGNORED`.
22+
- Updated `login`, `logout`, `whoami`, and shared auth checks with consistent remediation messaging.
23+
24+
### ⚙️ Runtime & Platform
25+
26+
- Added Linux keychain prerequisites in CI for deterministic native module builds (`libsecret-1-dev`, `pkg-config`).
27+
- Updated Docker image build/runtime dependencies for keytar compatibility in Linux containers.
28+
- Docker/headless guidance now documents env-readonly auth usage.
29+
30+
### 🧪 Testing
31+
32+
- Added dedicated credential-store tests for resolver precedence, reason states, encrypted file read/write, and legacy-ignore behavior.
33+
- Added CLI and TUI auth tests for env-readonly mode and keychain-unavailable handling.
34+
35+
### 🔧 Additional Merged Fixes
36+
37+
- Included merged PR [#5](https://github.com/night-slayer18/leetcode-cli/pull/5):
38+
- **Config file write normalization**: `config` writes now include a trailing newline for POSIX-friendly file formatting.
39+
40+
---
41+
342
## v2.4.1
443

544
> **Release Date**: 2026-03-08

0 commit comments

Comments
 (0)