Skip to content

Commit 95ee328

Browse files
committed
Block custom internal endpoint that should never be called
- Is not spec'd - Will not be spec'd - Is 100% internal as per its authors
1 parent 72a1794 commit 95ee328

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/main/java/io/kamax/mxisd/HttpMxisd.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package io.kamax.mxisd;
2222

2323
import io.kamax.mxisd.config.MxisdConfig;
24+
import io.kamax.mxisd.http.undertow.handler.InternalInfoHandler;
2425
import io.kamax.mxisd.http.undertow.handler.OptionsHandler;
2526
import io.kamax.mxisd.http.undertow.handler.SaneHandler;
2627
import io.kamax.mxisd.http.undertow.handler.as.v1.AsNotFoundHandler;
@@ -117,6 +118,9 @@ public void start() {
117118
.put(AsTransactionHandler.Path, asTxnHandler)
118119
.put("/transactions/{" + AsTransactionHandler.ID + "}", asTxnHandler) // Legacy endpoint
119120

121+
// Banned endpoints
122+
.get(InternalInfoHandler.Path, SaneHandler.around(new InternalInfoHandler()))
123+
120124
).build();
121125

122126
httpSrv.start();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* mxisd - Matrix Identity Server Daemon
3+
* Copyright (C) 2019 Kamax Sarl
4+
*
5+
* https://www.kamax.io/
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as
9+
* published by the Free Software Foundation, either version 3 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
package io.kamax.mxisd.http.undertow.handler;
22+
23+
import io.undertow.server.HttpServerExchange;
24+
25+
import java.util.concurrent.ThreadLocalRandom;
26+
27+
public class InternalInfoHandler extends BasicHttpHandler {
28+
29+
/*
30+
* This endpoint should never be called as being entierly custom as per instructions of New Vector,
31+
* the author of that endpoint.
32+
*
33+
* Used for the first time at https://github.com/matrix-org/synapse/pull/4681/files#diff-a73c645c44a17da6ab70f256da6b60afR41
34+
*
35+
* Full context: https://matrix.to/#/!YkZelGRiqijtzXZODa:matrix.org/$15510967621328WMKVu:kamax.io?via=matrix.org
36+
* Room name: #matrix-spec
37+
* Room alias: #matrix-spec:matrix.org
38+
*/
39+
public static final String Path = "/_matrix/identity/api/{version}/internal-info";
40+
41+
@Override
42+
public void handleRequest(HttpServerExchange exchange) throws Exception {
43+
// We will return a random status code in all possible error codes
44+
int type = ThreadLocalRandom.current().nextInt(4, 6) * 100; // Random 4 or 5, times 100
45+
int status = type + ThreadLocalRandom.current().nextInt(0, 100); // Random 0 to 99
46+
47+
respond(exchange, status, "M_FORBIDDEN", "This endpoint is under quarantine and possibly wrongfully labeled stable.");
48+
}
49+
50+
}

0 commit comments

Comments
 (0)