Skip to content

Commit f46ff4d

Browse files
authored
Implement synapse-http-antispam /ping. (#897)
maunium/synapse-http-antispam@2a36ef3
1 parent aa66056 commit f46ff4d

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1212
and this project adheres to
1313
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1414

15+
## [Unreleased] - 2025-XX-XX
16+
17+
### Added
18+
19+
- Implemented `/ping` for
20+
[synapse-http-antispam](https://the-draupnir-project.github.io/draupnir-documentation/bot/synapse-http-antispam).
21+
It is now possible to check if synapse is misconfigured by searching for
22+
`Successfully pinged antispam server with request ID` in any worker log.
23+
1524
## [v2.3.1] - 2025-05-29
1625

1726
### Fixed

mx-tester.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ modules:
4646
config:
4747
base_url: http://host.docker.internal:8082/api/1/spam_check
4848
authorization: DEFAULT
49+
do_ping: true
4950
enabled_callbacks:
5051
- user_may_invite
5152
- user_may_join_room
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-FileCopyrightText: 2025 Gnuxie <[email protected]>
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// SPDX-FileAttributionText: <text>
6+
// This modified file incorporates work from Draupnir
7+
// https://github.com/the-draupnir-project/Draupnir
8+
// </text>
9+
10+
import { Type } from "@sinclair/typebox";
11+
import { Request, Response } from "express";
12+
import { isError, Logger, Value } from "matrix-protection-suite";
13+
14+
const log = new Logger("PingEndpoint");
15+
16+
const PingBody = Type.Object({
17+
id: Type.Unknown(),
18+
});
19+
20+
export function handleHttpAntispamPing(
21+
request: Request,
22+
response: Response
23+
): void {
24+
const decodedBody = Value.Decode(PingBody, request.body);
25+
if (isError(decodedBody)) {
26+
log.error("Error decoding request body:", decodedBody.error);
27+
response.status(400).send({
28+
errcode: "M_INVALID_PARAM",
29+
error: "Error decoding request body",
30+
});
31+
return;
32+
}
33+
response.status(200).send({
34+
id: decodedBody.ok.id,
35+
status: "ok",
36+
});
37+
}

src/webapis/SynapseHTTPAntispam/SynapseHttpAntispam.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
CheckEventForSpamEndpoint,
1717
CheckEventForSpamListenerArguments,
1818
} from "./CheckEventForSpamEndpoint";
19+
import { handleHttpAntispamPing } from "./PingEndpoint";
1920

2021
const SPAM_CHECK_PREFIX = "/api/1/spam_check";
2122
const AUTHORIZATION = new RegExp("Bearer (.*)");
@@ -81,5 +82,9 @@ export class SynapseHttpAntispam {
8182
);
8283
})
8384
);
85+
webController.post(
86+
`${SPAM_CHECK_PREFIX}/ping`,
87+
makeAuthenticatedEndpointHandler(this.secret, handleHttpAntispamPing)
88+
);
8489
}
8590
}

0 commit comments

Comments
 (0)