diff --git a/CHANGELOG.md b/CHANGELOG.md index 187b5ea..4b0dc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/mx-tester.yml b/mx-tester.yml index 5baf265..16b9abe 100644 --- a/mx-tester.yml +++ b/mx-tester.yml @@ -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 diff --git a/src/webapis/SynapseHTTPAntispam/PingEndpoint.ts b/src/webapis/SynapseHTTPAntispam/PingEndpoint.ts new file mode 100644 index 0000000..5d0bafd --- /dev/null +++ b/src/webapis/SynapseHTTPAntispam/PingEndpoint.ts @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2025 Gnuxie +// +// SPDX-License-Identifier: Apache-2.0 +// +// SPDX-FileAttributionText: +// This modified file incorporates work from Draupnir +// https://github.com/the-draupnir-project/Draupnir +// + +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", + }); +} diff --git a/src/webapis/SynapseHTTPAntispam/SynapseHttpAntispam.ts b/src/webapis/SynapseHTTPAntispam/SynapseHttpAntispam.ts index 7392d5d..d58edc4 100644 --- a/src/webapis/SynapseHTTPAntispam/SynapseHttpAntispam.ts +++ b/src/webapis/SynapseHTTPAntispam/SynapseHttpAntispam.ts @@ -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) + ); } }