-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SSL plugin for managing HTTPS settings and fix https redirect bypass when a client was whitelisted
- Loading branch information
1 parent
5749947
commit d61c10e
Showing
6 changed files
with
72 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
"selfsigned" | ||
], | ||
"access": [ | ||
"ssl", | ||
"whitelist", | ||
"letsencrypt", | ||
"blacklist", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"id": "ssl", | ||
"name": "SSL", | ||
"description": "Handle SSL/TLS related settings.", | ||
"version": "1.0", | ||
"stream": "yes", | ||
"settings": { | ||
"REDIRECT_HTTP_TO_HTTPS": { | ||
"context": "multisite", | ||
"default": "no", | ||
"help": "Redirect all HTTP request to HTTPS.", | ||
"id": "redirect-http-to-https", | ||
"label": "Redirect HTTP to HTTPS", | ||
"regex": "^(yes|no)$", | ||
"type": "check" | ||
}, | ||
"AUTO_REDIRECT_HTTP_TO_HTTPS": { | ||
"context": "multisite", | ||
"default": "yes", | ||
"help": "Try to detect if HTTPS is used and activate HTTP to HTTPS redirection if that's the case.", | ||
"id": "auto-redirect-http-to-https", | ||
"label": "Auto redirect HTTP to HTTPS", | ||
"regex": "^(yes|no)$", | ||
"type": "check" | ||
}, | ||
"SSL_PROTOCOLS": { | ||
"context": "multisite", | ||
"default": "TLSv1.2 TLSv1.3", | ||
"help": "The supported version of TLS. We recommend the default value TLSv1.2 TLSv1.3 for compatibility reasons.", | ||
"id": "https-protocols", | ||
"label": "HTTPS protocols", | ||
"regex": "^(?! )( ?TLSv1\\.[0-3])*$", | ||
"type": "text" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local class = require "middleclass" | ||
local plugin = require "bunkerweb.plugin" | ||
|
||
local ssl = class("ssl", plugin) | ||
|
||
local ngx = ngx | ||
local HTTP_MOVED_PERMANENTLY = ngx.HTTP_MOVED_PERMANENTLY | ||
|
||
function ssl:initialize(ctx) | ||
-- Call parent initialize | ||
plugin.initialize(self, "ssl", ctx) | ||
end | ||
|
||
function ssl:access() | ||
-- Check if we need to redirect to HTTPS | ||
if | ||
self.ctx.bw.scheme == "http" | ||
and ( | ||
(self.ctx.bw.https_configured == "yes" and self.variables["AUTO_REDIRECT_HTTP_TO_HTTPS"] == "yes") | ||
or self.variables["REDIRECT_HTTP_TO_HTTPS"] == "yes" | ||
) | ||
then | ||
return self:ret( | ||
true, | ||
"redirect to HTTPS", | ||
HTTP_MOVED_PERMANENTLY, | ||
"https://" .. self.ctx.bw.http_host .. self.ctx.bw.request_uri | ||
) | ||
end | ||
return self:ret(true, "no redirect to HTTPS needed") | ||
end | ||
|
||
return ssl |