mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 17:03:49 +01:00
Make inbox signature verification compatible with Mastodon
This commit is contained in:
parent
07543da160
commit
aaf8397128
@ -11,16 +11,32 @@ app.use(bodyParser.json());
|
||||
app.post('/@:user/inbox', async (req, res) => {
|
||||
let parsed;
|
||||
|
||||
req.headers.authorization = 'Signature ' + req.headers.signature;
|
||||
|
||||
try {
|
||||
parsed = parseRequest(req);
|
||||
} catch (exception) {
|
||||
return res.sendStatus(401);
|
||||
}
|
||||
|
||||
const user = await User.findOne({
|
||||
host: { $ne: null },
|
||||
'account.publicKey.id': parsed.keyId
|
||||
});
|
||||
const keyIdLower = parsed.keyId.toLowerCase();
|
||||
let query;
|
||||
|
||||
if (keyIdLower.startsWith('acct:')) {
|
||||
const { username, host } = parseAcct(keyIdLower.slice('acct:'.length));
|
||||
if (host === null) {
|
||||
return res.sendStatus(401);
|
||||
}
|
||||
|
||||
query = { usernameLower: username, hostLower: host };
|
||||
} else {
|
||||
query = {
|
||||
host: { $ne: null },
|
||||
'account.publicKey.id': parsed.keyId
|
||||
};
|
||||
}
|
||||
|
||||
const user = await User.findOne(query);
|
||||
|
||||
if (user === null) {
|
||||
return res.sendStatus(401);
|
||||
|
Loading…
Reference in New Issue
Block a user