|
| 1 | +# Debug Findings |
| 2 | + |
| 3 | +## Issue 1: Hub Browser Blank Page |
| 4 | + |
| 5 | +**Root Cause:** `cscli hub list -o json` outputs informational preamble lines to stdout before the JSON: |
| 6 | + |
| 7 | +``` |
| 8 | +Loaded: 161 parsers, 11 postoverflows, 774 scenarios, 9 contexts, 5 appsec-configs, 187 appsec-rules, 160 collections |
| 9 | +Unmanaged items: 1 local, 0 tainted |
| 10 | +{ |
| 11 | + "appsec-configs": [...], |
| 12 | + "collections": [...], |
| 13 | + ... |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +The backend `ListHubItems` handler tried to `json.Unmarshal` the full output (including preamble), which failed. It then returned the raw string as `Data`. The frontend `parseHubItems` attempted `JSON.parse` on it, which also failed due to the preamble text, resulting in `rawParseError: true` and empty items — a blank page. |
| 18 | + |
| 19 | +Additionally, the frontend `HUB_TABS` only listed 4 categories (`scenarios`, `parsers`, `collections`, `postoverflows`) but CrowdSec now returns 7 categories (adding `appsec-configs`, `appsec-rules`, `contexts`). |
| 20 | + |
| 21 | +**Fix (Backend):** `internal/api/handlers/hub.go` — Strip any text before the first `{` character in `ListHubItems` and `ListHubItemsByCategory` before attempting JSON parse. |
| 22 | + |
| 23 | +**Fix (Frontend):** |
| 24 | +- `web/src/pages/HubBrowser.tsx` — Added `appsec-configs`, `appsec-rules`, `contexts` to `HubItemType`, `HUB_TABS`, `EMPTY_HUB_ITEMS`, and `parseHubItems`. |
| 25 | +- `web/src/lib/api/hub.ts` — Added `contexts` to `HubCategoryKey` type. |
| 26 | +- `web/src/pages/HubCategory.tsx` — Added `contexts` to `categoryMeta`. |
| 27 | + |
| 28 | +## Issue 2: Manual Decisions Not Showing in Decisions UI |
| 29 | + |
| 30 | +**Root Cause:** Manual decisions added via `cscli decisions add` produce a different JSON structure. Regular decisions are nested inside alerts (`alert.decisions[]`), but manual decisions appear as flat top-level objects without a `decisions` sub-array. The `GetDecisions` handler only parsed nested decisions, missing the flat ones. |
| 31 | + |
| 32 | +**Fix:** Added fallback parsing in `GetDecisions` and `GetDecisionsAnalysis` — if no nested `decisions` array is found within an alert, check if the top-level item itself has decision fields (e.g. `type`). If so, parse it as a standalone decision. The shared `parseDecisionNode` helper in `common.go` is used for both paths. |
| 33 | + |
| 34 | +## Issue 3: Notification Profiles YAML Formatting |
| 35 | + |
| 36 | +**Root Cause:** `updateProfilesYaml` in `notifications_yaml.go` used `yaml.FlowStyle` for the notifications sequence node, producing `notifications: [discord]` instead of block style. Also used `encoder.SetIndent(2)` instead of matching CrowdSec's default 1-space indent. |
| 37 | + |
| 38 | +**Fix:** Removed `FlowStyle` from sequence nodes and changed `encoder.SetIndent(1)` to match CrowdSec profiles.yaml format. |
0 commit comments