aproxy/scripts/webfinger_allowlist.lua

49 lines
1.1 KiB
Lua
Raw Normal View History

2023-10-27 01:19:08 +00:00
local function webfingerInit(cfg)
local accounts_set = {}
for _, account in ipairs(cfg.accounts) do
accounts_set["acct:" .. account] = true
end
return accounts_set
end
2023-10-27 01:19:08 +00:00
local function webfingerCallback(cfg, accounts_set)
2022-12-06 03:36:15 +00:00
local args, err = ngx.req.get_uri_args()
if err == "truncated" then
return 400, 'uri args too long'
2022-12-06 03:36:15 +00:00
end
local resource = args['resource']
if accounts_set[resource] then
return nil
else
return 404, "Couldn't find user"
2022-12-06 03:36:15 +00:00
end
end
return {
name='WebfingerAllowlist',
author='luna@l4.pm',
title='Webfinger Allowlist',
description=[[
2022-12-06 21:24:25 +00:00
Prevent unnecessary DB load by discarding requests to users that we know
2022-12-06 03:36:15 +00:00
won't exist.
Useful for small instances.
]],
2022-12-06 21:24:25 +00:00
version=1,
init=webfingerInit,
2022-12-06 03:36:15 +00:00
callbacks = {
['/.well-known/webfinger'] = webfingerCallback
},
config={
['accounts'] = {
2022-12-07 17:57:07 +00:00
type='list',
schema={
2022-12-06 03:36:15 +00:00
type='string',
description='ap id'
},
description = 'list of account ids (in email@domain form) to pass through to AP'
}
},
}