Skip to content

Commit f507bdc

Browse files
committed
fix: block publick access by default for all not-opentopic websocket topics (should be allowed by the config.auth.websocketTopicAuth)
AdminForth/1830/ws-authorization-work
1 parent d91c06d commit f507bdc

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

adminforth/modules/configValidator.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
AdminForthResourcePages,
2929
AdminForthDataTypes,
3030
Predicate,
31+
AdminUser,
3132
} from "../types/Common.js";
3233
import AdminForth from "adminforth";
3334
import { AdminForthConfigMenuItem } from "adminforth";
@@ -1216,6 +1217,16 @@ export default class ConfigValidator implements IConfigValidator {
12161217
}
12171218
}
12181219

1220+
if (!newConfig.auth.websocketTopicAuth) {
1221+
newConfig.auth.websocketTopicAuth = async (topic: string, adminUser: AdminUser) => {
1222+
if (!adminUser) {
1223+
// don't allow anonymous users to subscribe
1224+
return false;
1225+
}
1226+
return true;
1227+
}
1228+
}
1229+
12191230
newConfig.auth.rateLimit = newConfig.auth.rateLimit || [...DEFAULT_AUTH_RATE_LIMIT];
12201231
if (!Array.isArray(newConfig.auth.rateLimit)) {
12211232
errors.push(`auth.rateLimit must be an array of strings in format "500/5m"`);

0 commit comments

Comments
 (0)