From fc6e85b6caa05118812a869b03ad948ec571899d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 3 May 2021 11:05:05 +0100 Subject: [PATCH] Make the display of account and version info within nodeinfo metadata opt-in --- daemon.py | 15 +++++++++++++-- epicyon.py | 24 +++++++++++++++++++++++- metadata.py | 23 +++++++++++++++++++---- tests.py | 18 +++++++++++++++--- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/daemon.py b/daemon.py index ad0a7fee9..9a2441a61 100644 --- a/daemon.py +++ b/daemon.py @@ -971,9 +971,15 @@ class PubServer(BaseHTTPRequestHandler): return False if self.server.debug: print('DEBUG: nodeinfo ' + self.path) + + nodeInfoVersion = self.server.projectVersion + if not self.server.showNodeInfoVersion: + nodeInfoVersion = '0.0.0' + info = metaDataNodeInfo(self.server.baseDir, self.server.registration, - self.server.projectVersion) + nodeInfoVersion, + self.server.showNodeInfoAccounts) if info: msg = json.dumps(info).encode('utf-8') msglen = len(msg) @@ -14743,7 +14749,9 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None: break -def runDaemon(brochMode: bool, +def runDaemon(showNodeInfoAccounts: bool, + showNodeInfoVersion: bool, + brochMode: bool, verifyAllSignatures: bool, sendThreadsTimeoutMins: int, dormantMonths: int, @@ -14812,6 +14820,9 @@ def runDaemon(brochMode: bool, print('serverAddress: ' + str(serverAddress)) return False + httpd.showNodeInfoAccounts = showNodeInfoAccounts + httpd.showNodeInfoVersion = showNodeInfoVersion + # ASCII/ANSI text banner used in shell browsers, such as Lynx httpd.textModeBanner = getTextModeBanner(baseDir) diff --git a/epicyon.py b/epicyon.py index a6d265f25..2384a9421 100644 --- a/epicyon.py +++ b/epicyon.py @@ -322,6 +322,16 @@ parser.add_argument("--brochMode", type=str2bool, nargs='?', const=True, default=False, help="Enable broch mode") +parser.add_argument("--nodeinfoaccounts", + dest='showNodeInfoAccounts', + type=str2bool, nargs='?', + const=True, default=False, + help="Show numbers of accounts within nodeinfo metadata") +parser.add_argument("--nodeinfoversion", + dest='showNodeInfoVersion', + type=str2bool, nargs='?', + const=True, default=False, + help="Show version number within nodeinfo metadata") parser.add_argument("--noKeyPress", dest='noKeyPress', type=str2bool, nargs='?', @@ -2600,6 +2610,16 @@ brochMode = \ if brochMode is not None: args.brochMode = bool(brochMode) +showNodeInfoAccounts = \ + getConfigParam(baseDir, 'showNodeInfoAccounts') +if showNodeInfoAccounts is not None: + args.showNodeInfoAccounts = bool(showNodeInfoAccounts) + +showNodeInfoVersion = \ + getConfigParam(baseDir, 'showNodeInfoVersion') +if showNodeInfoVersion is not None: + args.showNodeInfoVersion = bool(showNodeInfoVersion) + YTDomain = getConfigParam(baseDir, 'youtubedomain') if YTDomain: if '://' in YTDomain: @@ -2614,7 +2634,9 @@ if setTheme(baseDir, themeName, domain, print('Theme set to ' + themeName) if __name__ == "__main__": - runDaemon(args.brochMode, + runDaemon(args.showNodeInfoAccounts, + args.showNodeInfoVersion, + args.brochMode, args.verifyAllSignatures, args.sendThreadsTimeoutMins, args.dormantMonths, diff --git a/metadata.py b/metadata.py index 14db42f3e..4b512bffa 100644 --- a/metadata.py +++ b/metadata.py @@ -12,12 +12,27 @@ from utils import noOfAccounts from utils import noOfActiveAccountsMonthly -def metaDataNodeInfo(baseDir: str, registration: bool, version: str) -> {}: +def metaDataNodeInfo(baseDir: str, registration: bool, version: str, + showAccounts: bool) -> {}: """ /nodeinfo/2.0 endpoint + Also see https://socialhub.activitypub.rocks/t/ + fep-f1d5-nodeinfo-in-fediverse-software/1190/4 + + Note that there are security considerations with this. If an adversary + sees a lot of accounts and "local" posts then the instance may be + considered a higher priority target. + Also exposure of the version number and number of accounts could be + sensitive """ - activeAccounts = noOfAccounts(baseDir) - activeAccountsMonthly = noOfActiveAccountsMonthly(baseDir, 1) - activeAccountsHalfYear = noOfActiveAccountsMonthly(baseDir, 6) + if showAccounts: + activeAccounts = noOfAccounts(baseDir) + activeAccountsMonthly = noOfActiveAccountsMonthly(baseDir, 1) + activeAccountsHalfYear = noOfActiveAccountsMonthly(baseDir, 6) + else: + activeAccounts = 1 + activeAccountsMonthly = 1 + activeAccountsHalfYear = 1 + nodeinfo = { 'openRegistrations': registration, 'protocols': ['activitypub'], diff --git a/tests.py b/tests.py index 9c9213ce4..15bdb9ccf 100644 --- a/tests.py +++ b/tests.py @@ -504,8 +504,12 @@ def createServerAlice(path: str, domain: str, port: int, maxFollowers = 10 verifyAllSignatures = True brochMode = False + showNodeInfoAccounts = True + showNodeInfoVersion = True print('Server running: Alice') - runDaemon(brochMode, + runDaemon(showNodeInfoAccounts, + showNodeInfoVersion, + brochMode, verifyAllSignatures, sendThreadsTimeoutMins, dormantMonths, maxNewswirePosts, @@ -601,8 +605,12 @@ def createServerBob(path: str, domain: str, port: int, maxFollowers = 10 verifyAllSignatures = True brochMode = False + showNodeInfoAccounts = True + showNodeInfoVersion = True print('Server running: Bob') - runDaemon(brochMode, + runDaemon(showNodeInfoAccounts, + showNodeInfoVersion, + brochMode, verifyAllSignatures, sendThreadsTimeoutMins, dormantMonths, maxNewswirePosts, @@ -652,8 +660,12 @@ def createServerEve(path: str, domain: str, port: int, federationList: [], maxFollowers = 10 verifyAllSignatures = True brochMode = False + showNodeInfoAccounts = True + showNodeInfoVersion = True print('Server running: Eve') - runDaemon(brochMode, + runDaemon(showNodeInfoAccounts, + showNodeInfoVersion, + brochMode, verifyAllSignatures, sendThreadsTimeoutMins, dormantMonths, maxNewswirePosts,