Repository navigation
Commit f335613
authored
Fixes #1018
### Overview
Addresses security finding **F-030 (weak cryptography / CWE-330)** where
`nostream setup` could report success while retaining the default
placeholder secret in `.env`.
### Problem
When running setup via the CLI, the package entry point preloads `.env`
into `process.env`. If `.env` contains the default placeholder
(`change_me_to_something_long_and_random`), `process.env.SECRET`
inherits that value.
Previously:
1. `resolveSecret()` checked `if (process.env.SECRET?.trim())` and
returned it without verifying whether it was the default placeholder.
2. `ensureEnvFile()` persisted this value back to `.env` without
secondary validation, resulting in setup completing while retaining an
insecure, predictable session signing secret.
3. The interactive secret prompt only validated that the input was
non-empty, allowing the default placeholder to be entered manually.
### Changes
- **Reject Inherited Placeholder**: Updated `resolveSecret()` in
`src/cli/commands/setup.ts` to check
`!needsSecretReplacement(inheritedSecret)` before accepting
`process.env.SECRET`.
- **Interactive Validation**: Extended prompt validation in
`setupPrompts.text` to reject the default placeholder string in addition
to empty input.
- **Defense-in-Depth Persistence Guard**: Added a validation check in
`ensureEnvFile()` before writing to disk; if the resolved secret is
empty or matches the placeholder, a secure 64-byte random hex secret
(`crypto.randomBytes(64)`) is generated.
- **Process Memory Synchronization**: Ensured `process.env.SECRET` is
updated with the final secret so downstream steps in the same process
(such as `runStart`) use the new secret immediately.
- **Unit Tests**: Added test coverage in `test/unit/cli/setup.spec.ts`
covering:
- Rejecting an inherited placeholder from `process.env.SECRET` and
generating a fresh random secret.
- Interactive prompt validation rejecting empty strings and placeholder
values.
- Final fallback replacement if interactive input somehow resolved to
the placeholder.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **Bug Fixes**
* Setup rejects the default placeholder when supplied through inherited
environment variables or interactive input. Prompted secrets must be
non-empty and cannot contain `#` or newlines.
* If the resolved secret is missing or remains a placeholder, setup
generates a secure secret and makes it available to the running process.
* Quoted secrets—including values with escaped quotes or `#`—are parsed
correctly. Valid secrets from the environment file are also made
available to the running process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
3 files changed
Lines changed: 198 additions & 8 deletions
File tree
- .changeset
- src/cli/commands
- test/unit/cli
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
32 | 72 | | |
33 | 73 | | |
34 | 74 | | |
35 | 75 | | |
36 | 76 | | |
37 | 77 | | |
38 | 78 | | |
39 | | - | |
40 | | - | |
| 79 | + | |
| 80 | + | |
41 | 81 | | |
42 | 82 | | |
43 | 83 | | |
44 | 84 | | |
45 | 85 | | |
46 | 86 | | |
47 | | - | |
| 87 | + | |
| 88 | + | |
48 | 89 | | |
49 | 90 | | |
50 | 91 | | |
51 | | - | |
52 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
53 | 95 | | |
54 | 96 | | |
55 | 97 | | |
56 | 98 | | |
57 | 99 | | |
58 | 100 | | |
59 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
60 | 117 | | |
61 | 118 | | |
62 | 119 | | |
63 | 120 | | |
64 | 121 | | |
65 | 122 | | |
66 | 123 | | |
67 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
68 | 128 | | |
69 | 129 | | |
70 | 130 | | |
| |||
119 | 179 | | |
120 | 180 | | |
121 | 181 | | |
122 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
123 | 187 | | |
124 | 188 | | |
125 | 189 | | |
| |||
133 | 197 | | |
134 | 198 | | |
135 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
136 | 205 | | |
137 | 206 | | |
138 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
117 | 231 | | |
0 commit comments