From b6eae3c8f9617d17781b80adbce2ad02edf8b6ab Mon Sep 17 00:00:00 2001
From: "OpenGenesis (MPL 2.0)"
<153564363+opengenesislink@users.noreply.github.com>
Date: Thu, 15 Oct 2026 03:46:45 +0200
Subject: [PATCH] fix(worldapi): single-path admin login and resilient public
statistics
* fix(worldapi): run admin password login and authorized panel through the same /api/v1/docs URL
* fix(worldapi): reuse native UserLevel-200 password authentication for docs login
* fix(worldapi): wire same-path Control Center authentication in Robust
* fix(worldapi): keep embedded dashboard login on the same KeyHelp-safe docs path
* ci(worldapi): require single-path docs login, scoped bearer and password+level check
* ci(worldapi): reflect same-path admin login in Experiences Control Center guard
* ci(worldapi): ensure same-path POST responds as an auth endpoint rather than HTTP 200 shell
* docs(worldapi): document simple same-path KeyHelp login and no-secret test commands
* fix(worldapi): return available resident statistics when optional GridUser history fails, mark unknown metrics null
* fix(worldapi): load public statistics without stale explorer tokens and display partial data transparently
* test(worldapi): guard partial statistics with unknown, not fabricated zero, values
* ci(worldapi): require graceful missing-GridUser statistics with truthful unknown values
* docs(worldapi): document truthful partial stats versus missing account authority
* fix(worldapi): avoid duplicate security headers on authenticated same-path docs GET
---
.github/workflows/nexjast-ci.yml | 13 ++
NexVerse/Server/Api/NexApiDocsPage.cs | 21 ++-
NexVerse/Server/Api/NexStatisticsApi.cs | 124 ++++++++++++------
NexVerse/Server/Api/NexVerseUserApi.cs | 10 ++
.../Server/Api/NexVerseWorldApiConnector.cs | 7 +
NexVerse/Server/Api/OglApiDocsAccess.cs | 61 ++++++++-
doc/NexVerse/WORLD_API.md | 11 +-
.../WORLD_API_CONTROL_CENTER.md | 86 +++++++++---
tools/ci/verify_experiences_nexbus_enabled.py | 2 +-
tools/ci/verify_ogl_docs_admin_ui.py | 18 ++-
tools/ci/verify_statistics_fallback.py | 41 ++++++
11 files changed, 322 insertions(+), 72 deletions(-)
create mode 100644 tools/ci/verify_statistics_fallback.py
diff --git a/.github/workflows/nexjast-ci.yml b/.github/workflows/nexjast-ci.yml
index b8d49324..1fe85fd1 100644
--- a/.github/workflows/nexjast-ci.yml
+++ b/.github/workflows/nexjast-ci.yml
@@ -293,6 +293,10 @@ jobs:
shell: bash
run: python3 tools/ci/verify_region_mutations.py
+ - name: Verify World API public statistics degraded-mode correctness
+ shell: bash
+ run: python3 tools/ci/verify_statistics_fallback.py
+
- name: Verify World API online region listing
shell: bash
run: python3 tools/ci/verify_region_listing.py
@@ -1139,6 +1143,15 @@ jobs:
curl --silent --fail --max-time 2 http://127.0.0.1:19090/api/v1/docs > /tmp/nexverse-api-docs.html
grep -F 'OpenGenesisLINK – Control Center' /tmp/nexverse-api-docs.html
+ # Same-path POST must reach the dedicated auth handler, never return
+ # the HTML login shell with a misleading HTTP 200. This synthetic
+ # smoke runs in public-only mode, so real admin login is disabled.
+ DOCS_LOGIN_STATUS="$(curl --silent --max-time 3 --output /tmp/ogl-docs-login.json --write-out '%{http_code}' \
+ -X POST -H 'Content-Type: application/json' \
+ --data '{"username":"ci-user","password":"not-a-real-password"}' \
+ http://127.0.0.1:19090/api/v1/docs)"
+ test "$DOCS_LOGIN_STATUS" = 503
+ grep -F '"error":"admin_login_unavailable"' /tmp/ogl-docs-login.json
# Full Control Center HTML must never be returned without a
# server-verified local administrator token, regardless of UI scripts.
DOCS_STATUS="$(curl --silent --output /tmp/ogl-docs-denied.txt --write-out '%{http_code}' --max-time 3 http://127.0.0.1:19090/api/v1/docs/panel)"
diff --git a/NexVerse/Server/Api/NexApiDocsPage.cs b/NexVerse/Server/Api/NexApiDocsPage.cs
index 4888a276..c5c4a350 100644
--- a/NexVerse/Server/Api/NexApiDocsPage.cs
+++ b/NexVerse/Server/Api/NexApiDocsPage.cs
@@ -585,7 +585,7 @@ Archivprüfungen bleiben auch für freigegebene Importe aktiv.
-
Der Login verwendet die Grid-Benutzeranmeldung POST /api/v1/auth/session und prüft den UserLevel auf dem Server. Das Access-Token wird nur im Arbeitsspeicher dieser Seite gehalten, nicht als Cookie oder im Browserspeicher abgelegt.
+
Der Login prüft Grid-Benutzername, Passwort und UserLevel ab 200 direkt am OGL-Server. Das Access-Token wird nur im Arbeitsspeicher dieser Seite gehalten, nicht als Cookie oder im Browserspeicher abgelegt.
@@ -721,18 +721,18 @@ async function adminLogin(){
try{
const body={username,password};
if(totp)body.totp=totp;
- const res=await fetch('/api/v1/auth/session',{
+ const res=await fetch('/api/v1/docs',{
method:'POST',headers:{'Content-Type':'application/json','Accept':'application/json'},
body:JSON.stringify(body),cache:'no-store',credentials:'same-origin'
});
const data=await res.json().catch(()=>null);
if(!res.ok)throw new Error('HTTP '+res.status+' ('+(data&&data.error||'login_failed')+')');
if(!data||typeof data!=='object'||Array.isArray(data)||!Number.isInteger(data.user_level))
- throw new Error('Ungültige World-API-Login-Antwort (HTTP '+res.status+'). /api/v1/auth/session und Reverse-Proxy-Routing prüfen.');
+ throw new Error('Die Anmeldung konnte nicht bestätigt werden. Der Server liefert keine gültige Benutzerantwort.');
if(Number(data.user_level)<200)
throw new Error('Zugriff verweigert: UserLevel 200 erforderlich.');
if(typeof data.access_token!=='string'||data.access_token.length<24)
- throw new Error('World API: Login-Antwort ohne gültiges access_token (HTTP '+res.status+'). Backend und Proxy prüfen.');
+ throw new Error('Anmeldung nicht möglich: Der Server konnte keine Sitzung erstellen.');
adminSessionToken=data.access_token;
adminSessionExpiry=Date.now()+Math.max(0,Number(data.expires_in||0)-30)*1000;
if(!adminIsActive())throw new Error('Administratorsitzung bereits abgelaufen.');
@@ -998,6 +998,9 @@ function renderStatistics(data){
erzeugt_am:data.generated_at,
kontostatus:states,
datenqualitaet:{
+ vollstaendig:quality.complete,
+ griduser_datenquelle:quality.griduser_source,
+ fehlende_kennzahlen:quality.missing_metrics||[],
registrierungsquelle:qv(quality.registered_source),
online_quelle:qv(quality.online_source),
historische_aktivitaet:qv(quality.historical_activity),
@@ -1008,8 +1011,12 @@ function renderStatistics(data){
}
async function loadStatistics(){
const headers={'Accept':'application/json'};
- const bearer=$('statsBearer').value.trim()||$('bearer').value.trim()||adminAuthToken();
- const key=$('statsApiKey').value.trim()||$('apiKey').value.trim();
+ // Do not reuse arbitrary credentials typed into the API Explorer:
+ // expired/incorrect bearer or API keys turn otherwise public aggregates
+ // into 401/403. Only the verified admin session or explicit stats
+ // credentials should be sent to the statistics endpoint.
+ const bearer=$('statsBearer').value.trim()||adminAuthToken();
+ const key=$('statsApiKey').value.trim();
if(bearer)headers.Authorization='Bearer '+bearer;
if(key)headers['X-NexVerse-Api-Key']=key;
$('statsStatus').textContent='Lade Statistik…';$('statsDot').className='dot';
@@ -1023,7 +1030,7 @@ async function loadStatistics(){
return;
}
renderStatistics(data||{});
- $('statsStatus').textContent='Live · '+(data.protected_details?'Details':'Aggregiert')+' · '+formatStatDate(data.generated_at);
+ $('statsStatus').textContent='Live · '+(data.data_quality&&data.data_quality.complete===false?'Teilweise (Datenquelle fehlt)':data.protected_details?'Details':'Aggregiert')+' · '+formatStatDate(data.generated_at);
$('statsDot').className='dot good';
}catch(err){
$('statsStatus').textContent='Statistik nicht erreichbar';$('statsDot').className='dot bad';$('statsQuality').textContent=String(err);
diff --git a/NexVerse/Server/Api/NexStatisticsApi.cs b/NexVerse/Server/Api/NexStatisticsApi.cs
index 5e74eae7..2e3363ac 100644
--- a/NexVerse/Server/Api/NexStatisticsApi.cs
+++ b/NexVerse/Server/Api/NexStatisticsApi.cs
@@ -99,16 +99,22 @@ namespace NexVerse.Server.Api
return;
}
- if (m_UserAccounts == null || m_GridUsers == null)
+ if (m_UserAccounts == null)
{
WriteError(
response,
HttpStatusCode.ServiceUnavailable,
"statistics_data_unavailable",
- "UserAccount or GridUser statistics storage is not available.");
+ "UserAccount statistics storage is not available.");
return;
}
+ // A GridUser storage issue must not take down the entire public
+ // statistics endpoint when authoritative resident account totals
+ // can still be read. Mark activity/visitor metrics as unknown.
+ // If account enumeration ALSO fails, return 503 instead of
+ // inventing a grid with zero registered users.
+
try
{
BuildSummary(response, includeProtectedDetails);
@@ -133,7 +139,21 @@ namespace NexVerse.Server.Api
DateTimeOffset weekCutoff = now.AddDays(-7);
DateTimeOffset monthCutoff = now.AddDays(-30);
- GridUserData[] rawRows = m_GridUsers.GetAll(string.Empty) ?? Array.Empty();
+ bool gridUserAvailable = m_GridUsers != null;
+ GridUserData[] rawRows = Array.Empty();
+ if (gridUserAvailable)
+ {
+ try
+ {
+ rawRows = m_GridUsers.GetAll(string.Empty) ?? Array.Empty();
+ }
+ catch (Exception e)
+ {
+ m_Log.Warn("[NEX-STATS]: GridUser statistics unavailable; serving partial account aggregates.", e);
+ gridUserAvailable = false;
+ }
+ }
+
List parsed = rawRows.Select(ParseActivity).Where(x => x != null).ToList();
Dictionary localActivity =
@@ -153,6 +173,9 @@ namespace NexVerse.Server.Api
.ToDictionary(x => x.Key, x => MostRecent(x), StringComparer.OrdinalIgnoreCase);
List accounts = LoadAccounts(localActivity, out bool completeAccountEnumeration);
+ if (!gridUserAvailable && !completeAccountEnumeration)
+ throw new InvalidOperationException(
+ "Both GridUser history and complete UserAccount enumeration are unavailable.");
Dictionary accountById =
accounts.GroupBy(x => x.PrincipalID.ToString(), StringComparer.OrdinalIgnoreCase)
@@ -262,12 +285,18 @@ namespace NexVerse.Server.Api
StringComparer.OrdinalIgnoreCase)
.ToDictionary(x => x.Key, x => x.Count(), StringComparer.OrdinalIgnoreCase);
- int neverLoggedIn =
- accounts.Count(account =>
- {
- string id = account.PrincipalID.ToString();
- return !localActivity.TryGetValue(id, out ActivityRecord record) || !record.LoginAt.HasValue;
- });
+ int? neverLoggedIn = gridUserAvailable
+ ? accounts.Count(account =>
+ {
+ string id = account.PrincipalID.ToString();
+ return !localActivity.TryGetValue(id, out ActivityRecord record) || !record.LoginAt.HasValue;
+ })
+ : null;
+
+ // A missing GridUser history alone does not imply that everybody
+ // is offline. If the PresenceService is authoritative, resident
+ // online counts remain meaningful, otherwise report unknown.
+ bool residentOnlineKnown = gridUserAvailable || presenceAvailable;
string correlationId = Correlation(response);
@@ -283,39 +312,48 @@ namespace NexVerse.Server.Api
accounts.Count(x => IsRecent(FromUnix(x.Created), weekCutoff)),
registrations_last_30_days =
accounts.Count(x => IsRecent(FromUnix(x.Created), monthCutoff)),
- online_now = residentsOnline.Count,
- active_last_24_hours =
- accounts.Count(x => HasRecentActivity(x, localActivity, dayCutoff)),
- active_last_7_days =
- accounts.Count(x => HasRecentActivity(x, localActivity, weekCutoff)),
- active_last_30_days =
- accounts.Count(x => HasRecentActivity(x, localActivity, monthCutoff)),
+ online_now = residentOnlineKnown ? residentsOnline.Count : (int?)null,
+ active_last_24_hours = gridUserAvailable
+ ? accounts.Count(x => HasRecentActivity(x, localActivity, dayCutoff))
+ : (int?)null,
+ active_last_7_days = gridUserAvailable
+ ? accounts.Count(x => HasRecentActivity(x, localActivity, weekCutoff))
+ : (int?)null,
+ active_last_30_days = gridUserAvailable
+ ? accounts.Count(x => HasRecentActivity(x, localActivity, monthCutoff))
+ : (int?)null,
never_logged_in = neverLoggedIn
},
hypergrid = new
{
- online_now = hypergridOnline.Count,
- known_visitors_total = knownHypergrid.Count,
- visitors_last_7_days =
- knownHypergrid.Count(x => IsRecent(x.LastActivityAt, weekCutoff)),
- visitors_last_30_days =
- knownHypergrid.Count(x => IsRecent(x.LastActivityAt, monthCutoff)),
- known_home_grids =
- knownHypergrid.Select(x => x.HomeGrid)
- .Where(x => !string.IsNullOrWhiteSpace(x))
- .Distinct(StringComparer.OrdinalIgnoreCase)
- .Count(),
- home_grids_online_now =
- hypergridOnline.Select(x => x.HomeGrid)
+ online_now = gridUserAvailable ? hypergridOnline.Count : (int?)null,
+ known_visitors_total = gridUserAvailable ? knownHypergrid.Count : (int?)null,
+ visitors_last_7_days = gridUserAvailable
+ ? knownHypergrid.Count(x => IsRecent(x.LastActivityAt, weekCutoff))
+ : (int?)null,
+ visitors_last_30_days = gridUserAvailable
+ ? knownHypergrid.Count(x => IsRecent(x.LastActivityAt, monthCutoff))
+ : (int?)null,
+ known_home_grids = gridUserAvailable
+ ? knownHypergrid.Select(x => x.HomeGrid)
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct(StringComparer.OrdinalIgnoreCase)
.Count()
+ : (int?)null,
+ home_grids_online_now = gridUserAvailable
+ ? hypergridOnline.Select(x => x.HomeGrid)
+ .Where(x => !string.IsNullOrWhiteSpace(x))
+ .Distinct(StringComparer.OrdinalIgnoreCase)
+ .Count()
+ : (int?)null
},
- detail_level = includeProtectedDetails ? "authenticated" : "aggregate",
+ detail_level = !gridUserAvailable
+ ? "partial"
+ : includeProtectedDetails ? "authenticated" : "aggregate",
protected_details = includeProtectedDetails,
online = new
{
- total = allOnline.Count,
+ total = gridUserAvailable ? allOnline.Count : (int?)null,
users = includeProtectedDetails
? allOnline.Select(OnlinePayload).ToArray()
: Array.Empty