SWS provides 'Basic' HTTP Authentication Scheme using an user:password pair.
This feature is disabled by default and can be controlled by the string --basic-auth option or the equivalent SERVER_BASIC_AUTH env.
The format to use is the following:
username:encrypted_password
Both are separated by a : (punctuation mark) character.
[!INFO] Password Encryption
Only the password must be encoded using the
BCryptpassword-hashing function.
[!WARNING] Bcrypt Password Length Limit
SWS rejects passwords longer than 72 bytes before bcrypt verification. Hashes generated with standard
bcryptutilities or the Apachehtpasswdtool are compatible with SWS for passwords of 72 bytes or fewer.Passwords longer than 72 bytes will not match in SWS, even if the hash was generated by a tool that truncates the password.
Make sure your password is at most 72 bytes long. We recommend using ASCII-only passwords of 72 characters or fewer to avoid encoding issues.
As an example, we will use the Apache htpasswd tool to generate the username:encrypted_password pair.
htpasswd -nBC10 "username"
# New password:
# Re-type new password:
# username:$2y$10$8phm28BB4YpKPDjOpdTT8eUcfVDw0xc85VZPxg2zae1GR8EQqus3i[!TIP] Password Security Advice
The password verification happens at runtime but its verification speed depends on the computing time cost of
bcryptalgorithm used.For example, the
htpasswdtool supports a-Cargument to adjust thebcrypt's computing time.Using a higher value is more secure but slower. The default value is
5and the possible values are ranging from4to17.
[!TIP] Docker Compose Advice
If you are using
SERVER_BASIC_AUTHenv via adocker-compose.ymlfile don't forget to replace the single$(dollar sign) with a$$(double-dollar sign) if you want those individual$dollar signs in your configuration to be treated by Docker as literals.
More details in the Docker Compose file: variable substitution page.
[!INFO] OPTIONS requests
OPTIONSrequests also require credentials, except CORS preflight requests (withOriginandAccess-Control-Request-Methodheaders) when CORS is enabled.
Finally, assign the credentials and run the server.
static-web-server \
--port 8787 \
--root ./my-public-dir \
--basic-auth 'username:$2y$10$8phm28BB4YpKPDjOpdTT8eUcfVDw0xc85VZPxg2zae1GR8EQqus3i'