feat(docs): add interactive Swagger & API Explorer for Portal, Artemis OpenAPI, and Bumblebee ISAPI #2
No reviewers
Labels
No labels
blocked
bug
enhancement
high-priority
low-priority
needs-info
needs-triage
ready-for-agent
ready-for-human
referenced
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gabogg/hikcentral!2
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/api-docs-and-swagger-explorer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📚 Interactive Swagger & API Documentation Portal
Branch:
feat/api-docs-and-swagger-explorer→masterRelated Scope: Interactive Swagger UI, HikCentral Artemis OpenAPI (189 Endpoints), Bumblebee ISAPI Explorer, and Live Credential Injection.
📋 Executive Summary
This PR introduces a unified, interactive API Documentation & Swagger Explorer Portal served at
/api-docs. It bridges local platform endpoints with the external HikCentral Professional platform, providing interactive testing capabilities with on-the-fly credential management and automated cryptographic signature generation.🔑 Dynamic Credential Header Ribbon
Always visible at the top of the portal, allowing developers and administrators to configure or switch targets dynamically:
Server Host / IP,Port,App Key (AK), andApp Secret (SK)with automatic HMAC-SHA256 signature calculation.Server Host / IP,Username,Password, andActive SIDwith an integrated "Login & Fetch SID" action.📑 4-in-1 Architecture & Documentation Tabs
🌐 Portal API (Local Swagger UI):
/openapi.jsoncovering all local platform endpoints (Doors, diagnostics, sensor overrides, HLS video streams, webhooks, auth).🛡️ HikCentral Artemis OpenAPI Explorer (189 APIs):
OpenAPI Developer Guide.zipacross 12 modules:🐝 HikCentral Bumblebee ISAPI Explorer:
/ISAPI/Bumblebee/Platform/V0/...,/ISAPI/Security/...,/ISAPI/AccessControl/...).📖 Developer & Architecture Manual:
📂 Key Files Created & Modified
app/docs/build_catalog.py: Extraction parser for Word / OpenAPI docx specifications.app/docs/artemis_catalog.json: Structured JSON catalog of 189 Artemis endpoints.app/docs/artemis_openapi.json: Standard OpenAPI 3.0.3 specification for Artemis.app/docs/bumblebee_catalog.json: Curated Bumblebee ISAPI catalog.app/controllers/docs_controller.py: Endpoints for catalog delivery and signed live execution proxies (/api/docs/execute/*).app/static/docs.html: Web portal with Swagger UI and interactive execution panes.tests/test_docs.py: Automated tests for documentation routes, catalogs, and RBAC execution proxies.🧪 Automated Test Verification
🛡️ Adversary & Codebase Design Review: Interactive Swagger & API Explorer
PR: #2 (feat/api-docs-and-swagger-explorer)
Review Scope: Security, Frontend Auth & Exception Handling, Disk I/O Concurrency, and Deep Module Interface Design
Test Suite Status: 36 passed, 1 warning in 18.43s.
📋 Executive Summary
This PR delivers an extensive 4-in-1 API documentation portal and interactive testing suite covering 189 Artemis OpenAPI endpoints, Bumblebee ISAPI endpoints, and local Swagger UI. The RBAC boundaries for execution (
require_admin) are properly enforced. However, our adversary analysis identified several frontend authentication disconnects, unescaped DOM rendering, and disk I/O bottlenecks that should be addressed before merging.🚨 Adversary Security & Failure Mode Findings
1. Frontend Unauthenticated Fetch & Script Crash
app/static/docs.html(L377-381)docs_controller.pyenforcesuser: Dict[str, Any] = Depends(require_auth)for catalogs. However, indocs.html:fetch()sends noAuthorization: Bearer <token>header. If a user visits/api-docswithout an activehc_sessioncookie, the backend returns{"detail": "Unauthorized"}.artemisCatalogbecomes an object instead of an array, causingartemisCatalog.map(...)on line 385 to crash withTypeError: artemisCatalog.map is not a function.artemisCatalog = Array.isArray(data) ? data : [];.localStorageor URL query parameter and includeheaders: { 'Authorization': 'Bearer ' + token }on allfetch()calls.2. Synchronous Disk I/O & JSON Parsing on Every Request
app/controllers/docs_controller.py(L43-63)artemis_openapi.jsonis 9,382 lines (~300 KB).get_artemis_openapi_spec()andget_artemis_catalog()execute synchronousopen()andjson.load()on every single HTTP GET request. Under concurrent traffic from multiple developers, this blocks the asynchronous event loop.Load and parse the JSON files into module-level memory variables once at startup (or lazy-load on first request):
3. Unescaped DOM Insertion in Catalog Lists
app/static/docs.html(L407-415, L507-515)In
renderArtemisList()andrenderBumblebeeList(),api.nameandapi.pathare concatenated directly intocontainer.innerHTML: If custom OpenAPI specifications or dynamic descriptions containing HTML entities are added in the future, this allows stored XSS.Apply an
escapeHtml()utility across all interpolated catalog strings before innerHTML injection.4. Authorization Disparity on Artemis OpenAPI Spec
app/controllers/docs_controller.py(L49-55)/api/docs/artemis/catalogrequiresrequire_auth, but/api/docs/artemis/openapi.jsonis completely unauthenticated.If the OpenAPI schema should be public for Swagger UI tools, document this explicitly. Otherwise, add
user: Dict[str, Any] = Depends(require_auth).🏗️ Codebase Design & Architecture Review
docs_controller.pysits cleanly at the HTTP controller seam, reusing existingArtemisClientandBumblebeeClientmodules rather than duplicating cryptographic signing routines (HMAC-SHA256) or AES-challenge state machines.ArtemisClient:docs_controller.py:L96-103,generate_artemis_signature()is invoked redundantly just to assemble the"debug"dictionary.ArtemisClient.request_async()could return its computed signature and target metadata directly in its response object, keeping all signature knowledge strictly insideArtemisClient.docs_controller.py,docs.html, andapp/docs/leaves zero impact on core door state management, access cycle aggregation, or video streaming proxies.📝 Recommended Action Checklist
Authorization: Bearer ...) and non-array response guard indocs.html:loadCatalogs().artemis_catalog.json,artemis_openapi.json,bumblebee_catalog.json) in memory to eliminate synchronous file I/O on every request.escapeHtml()todocs.htmlcatalog list renderers./api/docs/artemis/openapi.jsonwith/catalog.🛠️ PR Review Remediation Report
All 4 security, performance, and frontend resiliency findings from Review #1 (ID: 258) have been resolved in commit
43b6c00.🛡️ Remediations Applied
Frontend Auth Header Forwarding & Array Safeguards:
authFetch()inapp/static/docs.htmlto automatically forward activelocalStorageJWT orhc_sessioncookie inAuthorization: Bearer <token>headers.Array.isArray()guards to catalog state setters to eliminate any possibleTypeError: map is not a functionscript crashes.In-Memory Caching (Zero Event-Loop Blocking):
app/controllers/docs_controller.py, wrappedartemis_catalog.json,artemis_openapi.json, andbumblebee_catalog.jsonwith thread-safe module-level in-memory caching (_ARTEMIS_CATALOG_CACHE,_ARTEMIS_OPENAPI_CACHE,_BUMBLEBEE_CATALOG_CACHE). Disk I/O and synchronousjson.load()are completely bypassed on subsequent requests.Frontend XSS Defense-in-Depth:
escapeHtml()sanitization across all dynamic endpoint elements rendered inrenderArtemisList()andrenderBumblebeeList()inapp/static/docs.html.Deepening Signature Knowledge in
ArtemisClient:ArtemisClient.request_async()to return its computedsignatureandapp_keydirectly, removing duplicate signature computation fromdocs_controller.py.🧪 Automated Test Verification
✅ PR Approved: Ready for Merge
Final Verification Summary
authFetch()header forwarding and array defensive guards inloadCatalogs().docs_controller.py.escapeHtml()application across dynamic catalog endpoint list renderers indocs.html.ArtemisClientreturns computed request signatures directly in response payloads.37 passed, 1 warning in 29.66s).Verdict: Fully verified and approved for merge into
master.