Implement synapse-http-antispam /ping. (#897)

2a36ef305b
This commit is contained in:
Gnuxie
2025-06-09 11:43:19 +01:00
committed by GitHub
parent aa66056816
commit f46ff4dddd
4 changed files with 52 additions and 0 deletions

View File

@@ -12,6 +12,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] - 2025-XX-XX
### Added
- Implemented `/ping` for
[synapse-http-antispam](https://the-draupnir-project.github.io/draupnir-documentation/bot/synapse-http-antispam).
It is now possible to check if synapse is misconfigured by searching for
`Successfully pinged antispam server with request ID` in any worker log.
## [v2.3.1] - 2025-05-29
### Fixed

View File

@@ -46,6 +46,7 @@ modules:
config:
base_url: http://host.docker.internal:8082/api/1/spam_check
authorization: DEFAULT
do_ping: true
enabled_callbacks:
- user_may_invite
- user_may_join_room

View File

@@ -0,0 +1,37 @@
// SPDX-FileCopyrightText: 2025 Gnuxie <Gnuxie@protonmail.com>
//
// SPDX-License-Identifier: Apache-2.0
//
// SPDX-FileAttributionText: <text>
// This modified file incorporates work from Draupnir
// https://github.com/the-draupnir-project/Draupnir
// </text>
import { Type } from "@sinclair/typebox";
import { Request, Response } from "express";
import { isError, Logger, Value } from "matrix-protection-suite";
const log = new Logger("PingEndpoint");
const PingBody = Type.Object({
id: Type.Unknown(),
});
export function handleHttpAntispamPing(
request: Request,
response: Response
): void {
const decodedBody = Value.Decode(PingBody, request.body);
if (isError(decodedBody)) {
log.error("Error decoding request body:", decodedBody.error);
response.status(400).send({
errcode: "M_INVALID_PARAM",
error: "Error decoding request body",
});
return;
}
response.status(200).send({
id: decodedBody.ok.id,
status: "ok",
});
}

View File

@@ -16,6 +16,7 @@ import {
CheckEventForSpamEndpoint,
CheckEventForSpamListenerArguments,
} from "./CheckEventForSpamEndpoint";
import { handleHttpAntispamPing } from "./PingEndpoint";
const SPAM_CHECK_PREFIX = "/api/1/spam_check";
const AUTHORIZATION = new RegExp("Bearer (.*)");
@@ -81,5 +82,9 @@ export class SynapseHttpAntispam {
);
})
);
webController.post(
`${SPAM_CHECK_PREFIX}/ping`,
makeAuthenticatedEndpointHandler(this.secret, handleHttpAntispamPing)
);
}
}