Commit 3311ce7
feat(api): account lockout
We're implementing an "account lockout" feature in the login route to
manage repeated failed login attempts due to incorrect passwords for the
same user.
Account lockout is the system's ability to automatically restrict source
access based on the number of login attempts. The system permits sources
two login attempts before initiating a lockout. Upon a third attempt
with an incorrect password, the API will block further attempts.
Consumers trying to log in must inspect the `X-Account-Lockout` header,
which indicates the end of the lockout period in UTC seconds. When no
lockout is active, the header value will be 0. Importantly, a lockout
only affects login attempts from the same source. Logins from other
sources using the same user credentials will proceed without
encountering a lockout.
The lockout duration is calculated based on the number of attempts made,
increasing exponentially by a factor of 4 after the third attempt.
Attempts must last for half of the double lockout duration.
This means that a user who was locked out for 4 minutes must have the
attempts stored for 10 minutes (or 6 minutes after the timeout). Any
wrong attempt within this time will increase the lockout once again.
After this, the attempts will be reset, and new wrong attempts will
start the attempt counter from 0.
The following equations are used to calculate both lockout and attempt
duration, with 'x' representing the lockout duration and 'y' the attempt
duration:
```
F(x) = min(4^(a - 3), M)
F(y) = min((x) * 2.5, M)
```
Where:
```
x is the lockout duration in minutes.
y is the attempt duration in minutes.
a is the attempt number.
M is the maximum duration value.
```
Examples for M = 32768 (15 days) and a = n:
```
n = 3 | 4 | 5 | 8 | 11
_________________________________
F(x) = 1 | 4 | 16 | 1024 | 32768
F(y) = 2.5 | 10 | 40 | 2560 | 32768
```
The M value is controlled with the "MAXIMUM_ACCOUNT_LOCKOUT" environment
variable. When it equals 0, this feature is disabled. The default value
is 60, representing 1 hour.1 parent 4ea88ac commit 3311ce7
File tree
13 files changed
+577
-54
lines changed- api
- routes
- services
- mocks
- pkg/cache
- mocks
13 files changed
+577
-54
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
211 | 217 | | |
212 | 218 | | |
213 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
222 | | - | |
| 221 | + | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
242 | | - | |
| 241 | + | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
250 | 270 | | |
251 | 271 | | |
252 | 272 | | |
| |||
258 | 278 | | |
259 | 279 | | |
260 | 280 | | |
261 | | - | |
| 281 | + | |
262 | 282 | | |
263 | 283 | | |
264 | 284 | | |
| |||
271 | 291 | | |
272 | 292 | | |
273 | 293 | | |
274 | | - | |
| 294 | + | |
275 | 295 | | |
276 | 296 | | |
277 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
149 | 153 | | |
150 | 154 | | |
151 | 155 | | |
152 | | - | |
| 156 | + | |
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
| |||
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
163 | | - | |
| 167 | + | |
164 | 168 | | |
165 | 169 | | |
166 | 170 | | |
167 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
168 | 186 | | |
169 | 187 | | |
170 | 188 | | |
171 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
172 | 206 | | |
173 | 207 | | |
174 | 208 | | |
175 | 209 | | |
176 | | - | |
| 210 | + | |
177 | 211 | | |
178 | 212 | | |
179 | 213 | | |
| |||
205 | 239 | | |
206 | 240 | | |
207 | 241 | | |
208 | | - | |
| 242 | + | |
209 | 243 | | |
210 | 244 | | |
211 | 245 | | |
212 | 246 | | |
213 | | - | |
| 247 | + | |
214 | 248 | | |
215 | 249 | | |
216 | 250 | | |
| |||
238 | 272 | | |
239 | 273 | | |
240 | 274 | | |
241 | | - | |
| 275 | + | |
242 | 276 | | |
243 | 277 | | |
244 | 278 | | |
| |||
0 commit comments