Skip to content

Commit

Permalink
feat: Make it so that the security.txt endpoint bypasses antibot checks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Jul 22, 2024
1 parent 33ec069 commit 0922488
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/common/core/order.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"limit",
"misc",
"cors",
"securitytxt",
"antibot"
],
"headers": [
Expand Down
9 changes: 8 additions & 1 deletion src/common/core/securitytxt/securitytxt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local utils = require "bunkerweb.utils"

local ngx = ngx
local ERR = ngx.ERR
local OK = ngx.OK
local get_phase = ngx.get_phase
local subsystem = ngx.config.subsystem
local get_multiple_variables = utils.get_multiple_variables
Expand Down Expand Up @@ -109,6 +110,13 @@ function securitytxt:init()
return self:ret(true, "successfully loaded security policies")
end

function securitytxt:access()
if self.ctx.bw.uri ~= self.variables["SECURITYTXT_URI"] and self.ctx.bw.uri ~= "/security.txt" then
return self:ret(true, "success")
end
return self:ret(true, "security.txt requested", OK)
end

function securitytxt:content()
-- Check if content is needed
if self.variables["USE_SECURITYTXT"] == "no" then
Expand All @@ -126,7 +134,6 @@ function securitytxt:content()
end

local data = {
server_name = self.ctx.bw.server_name,
scheme = self.ctx.bw.scheme,
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/core/securitytxt/templates/security.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Preferred-Languages: {*preferred_lang*}
Canonical: {*ca*}
{% end %}
{% else %}
Canonical: {*scheme*}://{*server_name*}{*uri*}
Canonical: https://{*server_name*}{*uri*}
{% end %}
{% for _, p in ipairs(policy) do %}
Policy: {*p*}
Expand Down

0 comments on commit 0922488

Please sign in to comment.