Commit Graph

27 Commits

Author SHA1 Message Date
Michael Eischer 274f29fee8 refactor password check into separate function 2022-06-21 00:18:05 +02:00
Michael Eischer 98f0aaca1c convert htpasswd regexes to globals 2022-06-21 00:18:05 +02:00
Michael Eischer 5a6ed2ffdf use constant time comparison for sha1 password hash 2022-06-21 00:18:05 +02:00
Michael Eischer df9eb337d3 Extend htpasswd auth cache entry expiry on use 2022-06-21 00:18:05 +02:00
Michael Eischer 1eeca53812 Try to zero htpasswd cache entries before deletion 2022-06-21 00:18:05 +02:00
Michael Eischer 0bdc420e75 Cache successful basic auth credentials for a minute
This stores a hash of the username + password in map which is indexed by
the username. Indexing by username avoids accidentally introducing a
timing side-channel as a successful/failed lookup only provides
information on whether a cache entry exists for a username or not.

Hashing the username and password together makes it simple to get a
constant-time string comparison as we no longer have to worry about
string length differences.

Expriy is done by a goroutine which every few seconds checks for expired
cache entries and removes those.
2022-06-21 00:18:05 +02:00
Michael Eischer b0036d006b Unexport users map in htpasswd struct 2022-06-21 00:18:05 +02:00
Michael Eischer 48067dc896 htpasswd: allow underscores in usernames 2022-02-12 21:13:40 +01:00
Konrad Wojas 83e78c6cd7 Allow numbers in htpasswd usernames 2021-01-05 00:08:26 +08:00
Juergen Hoetzel 33c41b55bb Security: Prevent loading of usernames containing a slash
"/" is valid char in HTTP authorization headers, but is also used in
rest-server to map usernames to private repos.

This commit prevents loading maliciously composed usernames like
"/foo/config" by restricting the allowed characters to the unicode
character class, numbers, "-", "." and "@".

Closes #131
2020-12-28 11:30:00 +01:00
Aaron Bieber f18a5c16be reload htpasswd on SIGHUP 2019-03-04 16:55:29 -07:00
Aaron Bieber bdaa1ae345 Check for more bcrypt prefixes 2018-02-15 17:19:17 +01:00
Aaron Bieber 733c8da8fc Enable support for bcrypt'd password hashes in htpasswd 2018-02-15 17:19:17 +01:00
Zlatko Čalušić d056b85432 Check errors in many places
Admittedly, in some places just document the fact that we ignore error
return values, 'cause we don't know what to do with it.  At least, the
linter is happy.
2017-10-25 18:31:34 +02:00
Zlatko Čalušić 9b89df0842 Comment global variables 2017-10-25 18:14:07 +02:00
Konrad Wojas 526a2b3837 Limit htpasswd checks to once per 30s 2017-10-24 13:04:23 +02:00
Konrad Wojas 67a0f63773 Run goimports on htpasswd.go 2017-10-24 13:04:23 +02:00
Konrad Wojas 3e4edd3dd8 Automatically reload htpasswd
If htpasswd was modified, it will be automatically reloaded. This check
happens at most once per second and only on incoming requests.

Note that this removes the public `NewHtpasswd()` function.
2017-10-24 13:04:23 +02:00
Matthew Holt 65152c7bf5 Move main function into separate package (closes #12) 2017-06-25 11:48:02 +02:00
Zlatko Čalušić 267ae63276 Remove fs package and dirty tricks it does
The Linux kernel page cache ALWAYS knows better.  Fighting it brings
only worse performance. Usage of fadvise() is wrong 9 out of 10 times.

Removing the whole fs package brings a nice 100% speedup when running
costly prune command. And that is measured on localhost, the improvement
could be much bigger when using network with higher latency.
2016-11-06 20:09:42 +01:00
Zlatko Čalušić e0ac4f7afb Remove needless build tags 2016-11-06 11:26:06 +01:00
Zlatko Čalušić 5de6d4fd00 Reformat comments 2016-11-06 11:24:28 +01:00
Zlatko Čalušić 93d8c2beba Copy errors & fs packages from the restic repo and fix import paths
Tedious, but I see no better way...
2016-11-05 17:33:34 +01:00
Zlatko Čalušić 80196e6df6 Update with changes from github.com/restic/restic tree
Uncompilable right now, due to bad import paths.
2016-11-05 17:18:42 +01:00
Chapuis Bertil 60fe10382a added htpasswd 2015-09-19 14:28:43 +02:00
Chapuis Bertil c19c63325c simple backend 2015-09-16 23:34:11 +02:00
Chapuis Bertil 436de7f687 https support 2015-09-07 15:11:03 +02:00