Compare commits
73 Commits
feature/cv
...
af951fdc12
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af951fdc12
|
||
|
|
7f7d3a2977
|
||
|
|
034d3963b9
|
||
|
|
c8b3626ac5
|
||
|
|
8e377bb85f
|
||
|
|
5a9df2103f | ||
|
|
bfa52c7f8f | ||
|
|
3202b0707c | ||
|
|
15abf8bae4 | ||
| 8df961cce8 | |||
|
|
7a179f19a1 | ||
|
|
4f960d0866 | ||
|
|
caa1d539cc | ||
|
|
b1069b1a05 | ||
|
|
1186f9f807 | ||
|
|
e13b18c169 | ||
|
|
05d47c91a8 | ||
|
|
b0c3daba01 | ||
|
|
675847de0c | ||
|
|
623b57ca06 | ||
|
|
06c6821d85 | ||
|
|
8da62f0f14 | ||
|
|
5a9dc007db | ||
|
|
3f9e1da2a3 | ||
|
|
7ea4ceb8df | ||
|
|
00a6f7ae0f | ||
|
|
69809955a9 | ||
|
|
6ee68f5521 | ||
|
|
5ffedad02f | ||
|
|
8bf8dc55dd | ||
|
|
53439b2af8 | ||
|
|
4c04c9870a | ||
|
|
e1b000870c | ||
|
|
f3ba322403 | ||
|
|
0bea387ac9 | ||
|
|
aa3ce3bae9 | ||
|
|
0cdaecf890 | ||
|
|
043c85cc69 | ||
|
|
6082721452 | ||
|
|
a214393723 | ||
|
|
f141fa58a1 | ||
|
|
e1b0236874 | ||
|
|
ed48522932 | ||
|
|
938dda400a | ||
|
|
732873dd6a | ||
|
|
0fe8e94d51 | ||
|
|
28bce28fc9 | ||
|
|
72fd79ea42 | ||
|
|
f63c286458 | ||
|
|
93c144576f | ||
|
|
fa3b045a2f | ||
|
|
4583d09750 | ||
|
|
75ac8c823a | ||
|
|
68e36b4bac | ||
|
|
d24b45b404 | ||
|
|
d64eb7eec4 | ||
|
|
6cb65fddc1 | ||
|
|
0ca83c6736 | ||
|
|
06268880da | ||
|
|
b4f0ddcb78 | ||
|
|
55e3e074a5 | ||
|
|
66bbeb84a5 | ||
|
|
4578f8cd85 | ||
|
|
5469a86e6e | ||
|
|
2b6db1f903 | ||
|
|
7c97bc3a84 | ||
|
|
835fbf26e7 | ||
|
|
c4aaeff2a1 | ||
|
|
df30430956 | ||
|
|
57f11c362b | ||
|
|
4df83d36dd | ||
|
|
0a7a7c2827 | ||
|
|
1963faf9b8 |
BIN
.compliance-staging/.gitkeep
Normal file
BIN
.compliance-staging/.gitkeep
Normal file
Binary file not shown.
30
.gitignore
vendored
30
.gitignore
vendored
@@ -39,10 +39,6 @@ frontend.pid
|
||||
backend/uploads/temp/
|
||||
feature_request*.md
|
||||
|
||||
# Planning docs
|
||||
docs/aeo-compliance-ui-plan.md
|
||||
docs/aeo-compliance-wireframe.md
|
||||
|
||||
# AI tooling config
|
||||
.claude/
|
||||
ai_notes.md
|
||||
@@ -52,5 +48,27 @@ backend/fix_multivendor_constraint.js
|
||||
backend/server.js-backup
|
||||
backend/setup.js-backup
|
||||
|
||||
# Kiro implementation summary (internal only)
|
||||
docs/kiro-implementation-summary.md
|
||||
# Compliance staging — keep folder, ignore contents
|
||||
.compliance-staging/*
|
||||
!.compliance-staging/.gitkeep
|
||||
|
||||
# Kiro agents (local only)
|
||||
.kiro/
|
||||
|
||||
# Zip files
|
||||
*.zip
|
||||
|
||||
# Production DB copies
|
||||
cve_database_prod.db
|
||||
cve_database.db.prod
|
||||
cve_database.db.backup
|
||||
database.db
|
||||
|
||||
# Operations — local admin records, UAT logs, firewall requests, data exports
|
||||
docs/operations/
|
||||
|
||||
# Data exports — local spreadsheets
|
||||
docs/data-exports/
|
||||
|
||||
# Python cache
|
||||
__pycache__/
|
||||
|
||||
121
.gitlab-ci.yml
Normal file
121
.gitlab-ci.yml
Normal file
@@ -0,0 +1,121 @@
|
||||
# =============================================================================
|
||||
# GitLab CI/CD Pipeline — STEAM Security Dashboard
|
||||
# =============================================================================
|
||||
#
|
||||
# Pipeline stages:
|
||||
# 1. install — install dependencies for backend and frontend
|
||||
# 2. lint — run linters / static checks
|
||||
# 3. test — run backend (Jest) and frontend (react-scripts) tests
|
||||
# 4. build — produce the production frontend bundle
|
||||
# 5. deploy — restart services on the local machine (manual trigger)
|
||||
#
|
||||
# Executor: shell (runs directly on dashboard-dev using system Node.js)
|
||||
# Uses cache (not artifacts) for node_modules to avoid upload size limits.
|
||||
# =============================================================================
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Global cache — persists node_modules between pipeline runs on this runner
|
||||
# ---------------------------------------------------------------------------
|
||||
cache:
|
||||
key: ${CI_COMMIT_REF_SLUG}
|
||||
paths:
|
||||
- node_modules/
|
||||
- frontend/node_modules/
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Stages run in order; jobs within a stage run in parallel
|
||||
# ---------------------------------------------------------------------------
|
||||
stages:
|
||||
- install
|
||||
- lint
|
||||
- test
|
||||
- build
|
||||
- deploy
|
||||
|
||||
# =============================================================================
|
||||
# STAGE 1: Install dependencies
|
||||
# =============================================================================
|
||||
|
||||
install-backend:
|
||||
stage: install
|
||||
script:
|
||||
- npm install
|
||||
|
||||
install-frontend:
|
||||
stage: install
|
||||
script:
|
||||
- cd frontend
|
||||
- npm install
|
||||
|
||||
# =============================================================================
|
||||
# STAGE 2: Lint / static analysis
|
||||
# =============================================================================
|
||||
|
||||
lint-frontend:
|
||||
stage: lint
|
||||
script:
|
||||
- cd frontend
|
||||
- npm install
|
||||
- npx eslint src/ --max-warnings 0
|
||||
allow_failure: true # non-blocking until the team cleans up existing warnings
|
||||
|
||||
# =============================================================================
|
||||
# STAGE 3: Tests
|
||||
# =============================================================================
|
||||
|
||||
test-backend:
|
||||
stage: test
|
||||
script:
|
||||
- npm install
|
||||
- npx jest --ci --forceExit --detectOpenHandles backend/__tests__/
|
||||
timeout: 5 minutes
|
||||
|
||||
test-frontend:
|
||||
stage: test
|
||||
script:
|
||||
- cd frontend
|
||||
- npm install
|
||||
- CI=true npx react-scripts test --watchAll=false --ci --forceExit
|
||||
timeout: 5 minutes
|
||||
allow_failure: true # 2 test suites have pre-existing ESM/env issues — fix separately
|
||||
|
||||
# =============================================================================
|
||||
# STAGE 4: Build the production frontend bundle
|
||||
# =============================================================================
|
||||
|
||||
build-frontend:
|
||||
stage: build
|
||||
script:
|
||||
- cd frontend
|
||||
- npm install
|
||||
- CI=false REACT_APP_API_BASE=/api REACT_APP_API_HOST="" npm run build
|
||||
artifacts:
|
||||
paths:
|
||||
- frontend/build/
|
||||
expire_in: 7 days
|
||||
|
||||
# =============================================================================
|
||||
# STAGE 5: Deploy
|
||||
# =============================================================================
|
||||
# Since the runner IS the app server (dashboard-dev), deploy just restarts
|
||||
# the services locally. No SSH needed.
|
||||
#
|
||||
# Manual trigger only, and only from the main/master branch.
|
||||
# =============================================================================
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "master"
|
||||
when: manual
|
||||
environment:
|
||||
name: production
|
||||
script:
|
||||
- echo "Deploying on dashboard-dev..."
|
||||
- cd /home/cve-dashboard
|
||||
- git pull origin ${CI_COMMIT_BRANCH}
|
||||
- npm install
|
||||
- cd frontend && npm install && npm run build && cd ..
|
||||
- ./stop-servers.sh || true
|
||||
- ./start-servers.sh
|
||||
- echo "Deploy complete."
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "Check Component Conventions",
|
||||
"description": "On save of files in frontend/src/components/, verifies the component follows project conventions and flags deviations as inline comments.",
|
||||
"version": "1",
|
||||
"when": {
|
||||
"type": "fileEdited",
|
||||
"patterns": [
|
||||
"frontend/src/components/**/*.js"
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"type": "askAgent",
|
||||
"prompt": "Review the saved component file and verify it follows these project conventions:\n\n1. Functional component with hooks (no class components)\n2. Uses Lucide icons for iconography (not raw SVGs or other icon libraries)\n3. Uses inline styles or existing CSS classes from App.css (no CSS modules, no styled-components)\n4. Fetches data with fetch() using relative API paths and credentials: 'include' (no axios, no absolute URLs)\n5. Handles loading and error states when fetching data\n\nFor any deviations found, add inline comments in the code flagging the issue, e.g. // ⚠️ CONVENTION: Use lucide-react icons instead of raw SVGs\n\nOnly flag actual deviations. Do not modify working logic or refactor the component."
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "JSDoc Route Documentation",
|
||||
"description": "On save of files in backend/routes/, ensures every exported route handler has a JSDoc comment documenting the HTTP method, path, query parameters, request body shape, and response shape. Uses the existing documentation style in the file. Does not add comments to internal helper functions.",
|
||||
"version": "1",
|
||||
"when": {
|
||||
"type": "fileEdited",
|
||||
"patterns": [
|
||||
"backend/routes/*.js"
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"type": "askAgent",
|
||||
"prompt": "Review the saved route file and ensure every exported route handler (e.g., router.get, router.post, router.put, router.patch, router.delete) has a JSDoc comment directly above it documenting: the HTTP method, the route path, any query parameters, the request body shape (if applicable), and the response shape. Match the existing documentation style already used in the file. Do NOT add JSDoc comments to internal helper functions that are not route handlers. Only add missing documentation — do not modify or remove existing JSDoc comments that are already correct."
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "SQLite3 Safety Check",
|
||||
"description": "On save of files containing db.run, db.get, or db.all, verifies all sqlite3 calls use parameterized queries (? placeholders) instead of string concatenation, handle the error parameter first in every callback, and use hardcoded table/column names. Flags violations as inline comments prefixed with \"// FIXME:\".",
|
||||
"version": "1",
|
||||
"when": {
|
||||
"type": "fileEdited",
|
||||
"patterns": [
|
||||
"backend/**/*.js"
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"type": "askAgent",
|
||||
"prompt": "The saved file may contain sqlite3 calls (db.run, db.get, or db.all). Scan the file and verify all sqlite3 calls follow these rules:\n\n1. Parameterized queries only: All SQL queries must use ? placeholders for dynamic values. Never use string concatenation or template literals to inject values into SQL strings.\n2. Error-first callbacks: Every callback passed to db.run, db.get, or db.all must handle the error parameter first (e.g., `if (err) { ... }`).\n3. Hardcoded table/column names: All table and column names in SQL strings must be hardcoded string literals, never sourced from variables or parameters.\n\nIf the file does not contain any db.run, db.get, or db.all calls, skip the check silently.\n\nFor any violations found, add an inline comment on the offending line prefixed with \"// FIXME:\" describing the specific issue. Do not modify any other code."
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "Verify Migration Pattern",
|
||||
"description": "On save or create of migration files (migrate*.js), verifies the migration follows existing project patterns: uses CREATE TABLE IF NOT EXISTS, includes explicit column types, adds appropriate indexes, and wraps multiple statements in transactions. Compares against existing migrations for style consistency.",
|
||||
"version": "1",
|
||||
"when": {
|
||||
"type": "fileEdited",
|
||||
"patterns": [
|
||||
"**/migrate*.js"
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"type": "askAgent",
|
||||
"prompt": "A migration file was just saved. Review the edited file and verify it follows the existing migration pattern used in this project. Check the existing migrations in backend/migrations/ for reference, then verify the edited file:\n\n1. Uses CREATE TABLE IF NOT EXISTS (not just CREATE TABLE)\n2. Includes all columns with explicit SQLite types (TEXT, INTEGER, REAL, etc.)\n3. Adds appropriate indexes for foreign keys and frequently queried columns\n4. Wraps operations in a serialized transaction (db.serialize + db.run(\"BEGIN TRANSACTION\") / COMMIT) if there are multiple statements\n5. Follows the same callback-based db.run() style as existing migrations\n6. Includes proper error handling\n\nCompare the file against the existing migrations in backend/migrations/ for style consistency. Report any deviations or issues found."
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "Verify New Migration",
|
||||
"description": "On creation of new migration files in backend/migrations/, verifies the migration follows existing project patterns: uses CREATE TABLE IF NOT EXISTS, includes explicit column types, adds appropriate indexes, and wraps multiple statements in transactions.",
|
||||
"version": "1",
|
||||
"when": {
|
||||
"type": "fileCreated",
|
||||
"patterns": [
|
||||
"**/migrations/*.js"
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"type": "askAgent",
|
||||
"prompt": "A new migration file was just created. Review the file and verify it follows the existing migration pattern used in this project. Check the existing migrations in backend/migrations/ for reference, then verify the new file:\n\n1. Uses CREATE TABLE IF NOT EXISTS (not just CREATE TABLE)\n2. Includes all columns with explicit SQLite types (TEXT, INTEGER, REAL, etc.)\n3. Adds appropriate indexes for foreign keys and frequently queried columns\n4. Wraps operations in a serialized transaction (db.serialize + db.run(\"BEGIN TRANSACTION\") / COMMIT) if there are multiple statements\n5. Follows the same callback-based db.run() style as existing migrations\n6. Includes proper error handling\n\nCompare the file against the existing migrations in backend/migrations/ for style consistency. Report any deviations or issues found."
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{"specId": "9f5c16d4-43ea-4d7a-beb1-9329d79a5acc", "workflowType": "requirements-first", "specType": "feature"}
|
||||
@@ -1,331 +0,0 @@
|
||||
# Design Document: Batch Finding Disposition
|
||||
|
||||
## Overview
|
||||
|
||||
This feature adds multi-select capability to the Vulnerability Triage page's findings table, enabling engineers to select multiple findings and add them all to the Ivanti Queue in a single operation. The current flow requires clicking each finding individually, configuring a popover, and submitting one at a time — this design replaces that with a batch selection toolbar and a bulk-add API endpoint while preserving the existing single-select popover for one-off additions.
|
||||
|
||||
The design touches three layers:
|
||||
1. A new `POST /api/ivanti/todo-queue/batch` backend endpoint that accepts an array of findings in a single transactional insert
|
||||
2. Frontend multi-select state management (selection set, shift-click range select, select-all)
|
||||
3. A sticky Selection Toolbar component with workflow type toggles, vendor input, and batch submit
|
||||
|
||||
## Architecture
|
||||
|
||||
The feature extends the existing Ivanti Queue subsystem without introducing new services or tables. The `ivanti_todo_queue` table schema is unchanged — batch add simply inserts multiple rows in a single SQLite transaction.
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
subgraph Frontend ["Frontend (ReportingPage.js)"]
|
||||
CB[Row Checkboxes] --> SS[Selection State<br/>Set of finding IDs]
|
||||
SS --> ST[Selection Toolbar]
|
||||
ST -->|"Add to Queue"| BA[Batch API Call]
|
||||
CB -->|"No selection + click"| PO[AddToQueuePopover<br/>existing single-add]
|
||||
end
|
||||
|
||||
subgraph Backend ["Backend (ivantiTodoQueue.js)"]
|
||||
BA -->|"POST /batch"| BH[Batch Handler]
|
||||
BH -->|"BEGIN TRANSACTION"| DB[(ivanti_todo_queue)]
|
||||
BH -->|"logAudit()"| AL[(audit_logs)]
|
||||
PO -->|"POST /"| SH[Single Handler<br/>existing]
|
||||
SH --> DB
|
||||
end
|
||||
```
|
||||
|
||||
### Key Design Decisions
|
||||
|
||||
1. **No new database table or migration** — batch insert reuses the existing `ivanti_todo_queue` schema. Each finding becomes its own row, identical to what the single-add endpoint creates.
|
||||
|
||||
2. **SQLite transaction for atomicity** — all findings in a batch are inserted inside `db.serialize()` with `BEGIN TRANSACTION` / `COMMIT`. If any insert fails, the entire batch is rolled back. This satisfies the all-or-nothing requirement (Req 3.7, 3.8, 3.11).
|
||||
|
||||
3. **Selection state lives in the VulnerabilityTriagePage component** — a `Set<string>` of finding IDs managed via `useState`. This keeps the selection co-located with the existing `findings`, `sorted`, `filtered`, and `queueItems` state. No new context or global store needed.
|
||||
|
||||
4. **Dual-mode checkbox behavior** — when no findings are selected, clicking a checkbox opens the existing `AddToQueuePopover` (preserving the single-select flow per Req 5). Once one or more findings are selected, subsequent checkbox clicks toggle selection instead. This is the simplest UX that satisfies both Req 1 and Req 5.
|
||||
|
||||
5. **Selection Toolbar as inline sticky bar** — rendered between the table header controls and the `<table>` element, using `position: sticky` to stay visible during scroll. This avoids portal complexity and keeps the toolbar visually anchored to the table.
|
||||
|
||||
6. **200-item batch limit** — prevents oversized payloads and keeps SQLite transaction time reasonable. The findings table typically has 200-800 rows, so this covers most realistic batch sizes.
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### Backend
|
||||
|
||||
#### `POST /api/ivanti/todo-queue/batch`
|
||||
|
||||
Added to the existing `createIvantiTodoQueueRouter` factory in `backend/routes/ivantiTodoQueue.js`.
|
||||
|
||||
**Request body:**
|
||||
```json
|
||||
{
|
||||
"findings": [
|
||||
{
|
||||
"finding_id": "FID-12345",
|
||||
"finding_title": "OpenSSL vulnerability",
|
||||
"cves": ["CVE-2024-0001"],
|
||||
"ip_address": "10.0.1.50"
|
||||
}
|
||||
],
|
||||
"workflow_type": "FP",
|
||||
"vendor": "Juniper"
|
||||
}
|
||||
```
|
||||
|
||||
**Validation rules:**
|
||||
- `findings` — array, 1–200 items
|
||||
- Each item: `finding_id` required, non-empty string; `finding_title`, `cves`, `ip_address` optional
|
||||
- `workflow_type` — must be `FP`, `Archer`, or `CARD`
|
||||
- `vendor` — required non-empty string (≤200 chars) for FP/Archer; ignored for CARD
|
||||
- If any finding fails validation, reject entire batch with 400
|
||||
|
||||
**Auth:** `requireAuth(db)`, `requireGroup('Admin', 'Standard_User')`
|
||||
|
||||
**Response (201):**
|
||||
```json
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"id": 42,
|
||||
"user_id": 1,
|
||||
"finding_id": "FID-12345",
|
||||
"finding_title": "OpenSSL vulnerability",
|
||||
"cves_json": "[\"CVE-2024-0001\"]",
|
||||
"ip_address": "10.0.1.50",
|
||||
"vendor": "Juniper",
|
||||
"workflow_type": "FP",
|
||||
"status": "pending",
|
||||
"created_at": "2025-01-15 12:00:00",
|
||||
"updated_at": "2025-01-15 12:00:00",
|
||||
"cves": ["CVE-2024-0001"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**Error responses:**
|
||||
- `400` — validation failure (descriptive message)
|
||||
- `401` — not authenticated
|
||||
- `403` — insufficient permissions
|
||||
- `500` — database transaction failure (all inserts rolled back)
|
||||
|
||||
### Frontend
|
||||
|
||||
#### Selection State (in VulnerabilityTriagePage)
|
||||
|
||||
New state variables added to the main component:
|
||||
|
||||
```javascript
|
||||
const [selectedIds, setSelectedIds] = useState(new Set()); // Set<string> of finding IDs
|
||||
const [lastClickedId, setLastClickedId] = useState(null); // for shift-click range select
|
||||
const [batchSubmitting, setBatchSubmitting] = useState(false); // loading state
|
||||
const [batchError, setBatchError] = useState(null); // error message from failed batch
|
||||
const [batchWorkflowType, setBatchWorkflowType] = useState('FP');
|
||||
const [batchVendor, setBatchVendor] = useState('');
|
||||
```
|
||||
|
||||
#### Checkbox Click Logic
|
||||
|
||||
```
|
||||
onClick(finding, event):
|
||||
if finding is already queued → return (no-op)
|
||||
if selectedIds.size === 0 AND not shift-click:
|
||||
→ open AddToQueuePopover (existing single-select flow)
|
||||
else:
|
||||
if shift-click AND lastClickedId exists:
|
||||
→ range-select all visible findings between lastClickedId and finding.id
|
||||
else:
|
||||
→ toggle finding.id in selectedIds
|
||||
set lastClickedId = finding.id
|
||||
```
|
||||
|
||||
#### SelectionToolbar Component
|
||||
|
||||
Rendered inline above the table when `selectedIds.size > 0`. Contains:
|
||||
- Selected count badge
|
||||
- "Clear Selection" button
|
||||
- Workflow type toggle buttons (FP / Archer / CARD) with existing color scheme
|
||||
- Vendor text input (hidden when CARD selected)
|
||||
- "Add to Queue" submit button (disabled until valid)
|
||||
- Error message display area
|
||||
|
||||
#### Selection Persistence Across Filters
|
||||
|
||||
When `columnFilters`, `actionFilter`, or `excFilter` change, the selection set is pruned to only include IDs that remain in the `filtered` array. This is done via a `useEffect` that intersects `selectedIds` with the current filtered finding IDs.
|
||||
|
||||
#### Select All / Deselect All
|
||||
|
||||
The checkbox column header renders a "Select All" control when `selectedIds.size > 0` or as a standard header otherwise. Clicking it:
|
||||
- If not all visible non-queued findings are selected → selects all visible non-queued findings
|
||||
- If all are already selected → deselects all
|
||||
|
||||
## Data Models
|
||||
|
||||
### Database Schema (unchanged)
|
||||
|
||||
The `ivanti_todo_queue` table is reused as-is:
|
||||
|
||||
```sql
|
||||
CREATE TABLE ivanti_todo_queue (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
finding_id TEXT NOT NULL,
|
||||
finding_title TEXT,
|
||||
cves_json TEXT,
|
||||
ip_address TEXT,
|
||||
vendor TEXT NOT NULL,
|
||||
workflow_type TEXT NOT NULL CHECK(workflow_type IN ('FP', 'Archer', 'CARD')),
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'complete')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
```
|
||||
|
||||
Each batch-added finding creates one row, identical to single-add. The `vendor` and `workflow_type` are shared across all findings in a batch (set once in the toolbar).
|
||||
|
||||
### API Request Schema
|
||||
|
||||
```
|
||||
BatchAddRequest {
|
||||
findings: Array<{
|
||||
finding_id: string (required, non-empty, trimmed)
|
||||
finding_title: string | null (max 500 chars)
|
||||
cves: string[] | null
|
||||
ip_address: string | null (max 64 chars)
|
||||
}> (1–200 items)
|
||||
workflow_type: "FP" | "Archer" | "CARD"
|
||||
vendor: string (required for FP/Archer, ≤200 chars; empty/absent for CARD)
|
||||
}
|
||||
```
|
||||
|
||||
### Frontend State Shape
|
||||
|
||||
```
|
||||
Selection State:
|
||||
selectedIds: Set<string> — finding IDs currently selected
|
||||
lastClickedId: string | null — last checkbox clicked (for shift-range)
|
||||
batchSubmitting: boolean — true while POST /batch in flight
|
||||
batchError: string | null — error message from last failed batch
|
||||
batchWorkflowType: "FP" | "Archer" | "CARD"
|
||||
batchVendor: string
|
||||
```
|
||||
|
||||
|
||||
## Correctness Properties
|
||||
|
||||
*A property is a characteristic or behavior that should hold true across all valid executions of a system — essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
|
||||
|
||||
### Property 1: Selection pruning preserves only visible findings
|
||||
|
||||
*For any* set of selected finding IDs and any set of currently visible (filtered) finding IDs, pruning the selection after a filter change should produce exactly the intersection of the two sets — every ID in the result is both selected and visible, and no visible selected ID is lost.
|
||||
|
||||
**Validates: Requirements 1.4**
|
||||
|
||||
### Property 2: Select-all produces the complete visible non-queued set
|
||||
|
||||
*For any* list of visible findings and any set of queued finding IDs, the select-all operation should produce a set containing exactly the IDs of visible findings that are not in the queued set — no queued findings included, no non-queued visible findings omitted.
|
||||
|
||||
**Validates: Requirements 1.6**
|
||||
|
||||
### Property 3: Submit button enabled state matches validation rule
|
||||
|
||||
*For any* workflow type (FP, Archer, CARD) and any vendor string, the "Add to Queue" button should be enabled if and only if the workflow type is CARD, or the vendor string trimmed is non-empty. No other combination should enable the button.
|
||||
|
||||
**Validates: Requirements 2.7**
|
||||
|
||||
### Property 4: Batch size validation accepts only 1–200 items
|
||||
|
||||
*For any* integer N representing the number of findings in a batch request, the endpoint should accept the request (assuming all other fields are valid) if and only if 1 ≤ N ≤ 200. Arrays of size 0 or greater than 200 should be rejected with a 400 response.
|
||||
|
||||
**Validates: Requirements 3.2**
|
||||
|
||||
### Property 5: Vendor validation is conditional on workflow type
|
||||
|
||||
*For any* workflow type and any vendor string, the batch endpoint should require a non-empty vendor of 200 characters or fewer when workflow_type is FP or Archer, and should accept any vendor value (including empty or absent) when workflow_type is CARD.
|
||||
|
||||
**Validates: Requirements 3.5, 3.6**
|
||||
|
||||
### Property 6: One invalid finding rejects the entire batch
|
||||
|
||||
*For any* valid batch of findings, if exactly one finding is replaced with an invalid finding (empty finding_id, missing finding_id, or non-string finding_id) at any position in the array, the entire batch should be rejected with a 400 response and zero rows should be inserted.
|
||||
|
||||
**Validates: Requirements 3.3, 3.8**
|
||||
|
||||
### Property 7: Successful batch response matches request
|
||||
|
||||
*For any* valid batch request of N findings, the 201 response should contain exactly N items, each with a unique numeric `id`, and the set of `finding_id` values in the response should equal the set of `finding_id` values in the request.
|
||||
|
||||
**Validates: Requirements 3.9**
|
||||
|
||||
### Property 8: Shift-click range select covers exactly the between range
|
||||
|
||||
*For any* sorted list of visible findings, any last-clicked index, and any current-click index, the shift-click range select should produce a set containing exactly the non-queued findings between those two indices (inclusive), regardless of which index is larger.
|
||||
|
||||
**Validates: Requirements 6.1**
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Backend Errors
|
||||
|
||||
| Scenario | Response | Behavior |
|
||||
|----------|----------|----------|
|
||||
| Empty findings array or > 200 items | 400 | `{ error: "findings array must contain 1-200 items." }` |
|
||||
| Any finding missing/empty finding_id | 400 | `{ error: "Each finding must have a non-empty finding_id string." }` |
|
||||
| Invalid workflow_type | 400 | `{ error: "workflow_type must be FP, Archer, or CARD." }` |
|
||||
| Missing vendor for FP/Archer | 400 | `{ error: "vendor is required for FP and Archer workflows." }` |
|
||||
| Vendor exceeds 200 chars | 400 | `{ error: "vendor must be under 200 chars." }` |
|
||||
| Not authenticated | 401 | Standard auth middleware response |
|
||||
| Insufficient permissions (Read_Only) | 403 | Standard group middleware response |
|
||||
| SQLite transaction failure | 500 | Transaction rolled back, `{ error: "Internal server error." }` |
|
||||
|
||||
### Frontend Errors
|
||||
|
||||
| Scenario | Behavior |
|
||||
|----------|----------|
|
||||
| Batch POST returns 4xx/5xx | Display error message in Selection Toolbar, keep selection intact |
|
||||
| Network failure during batch POST | Display "Network error — please try again" in toolbar, keep selection |
|
||||
| Batch POST timeout | Same as network failure handling |
|
||||
|
||||
### Edge Cases
|
||||
|
||||
- **Duplicate finding_ids in batch**: Allowed — the same finding could appear on multiple hosts. The backend does not enforce uniqueness on finding_id within a batch.
|
||||
- **Finding already in queue**: The frontend prevents selecting already-queued findings (checkbox is disabled), so duplicates should not reach the API. No server-side duplicate check is added to keep the endpoint simple.
|
||||
- **Concurrent batch submissions**: The SQLite transaction serializes writes. If two users submit overlapping batches, both succeed independently (each user has their own queue scoped by user_id).
|
||||
- **Selection of 0 findings**: The "Add to Queue" button is only rendered when selectedIds.size > 0, so this state cannot be reached through the UI. The backend still validates for it.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests
|
||||
|
||||
Focus on specific examples and edge cases:
|
||||
|
||||
- **Backend validation**: Test each validation rule with concrete valid/invalid inputs (empty array, 201 items, missing finding_id, invalid workflow_type, vendor edge cases)
|
||||
- **Transaction rollback**: Mock a database error mid-insert, verify no rows are committed
|
||||
- **Frontend checkbox dual-mode**: Test that clicking with empty selection opens popover, clicking with existing selection toggles selection
|
||||
- **Toolbar visibility**: Test toolbar appears/disappears based on selection state
|
||||
- **Clear selection**: Test that clear button empties selection
|
||||
- **Escape key**: Test that Escape clears selection
|
||||
- **Select-all toggle**: Test select-all and deselect-all behavior
|
||||
- **Queue panel update**: Test that successful batch updates queueItems state
|
||||
|
||||
### Property-Based Tests
|
||||
|
||||
Using [fast-check](https://github.com/dubzzz/fast-check) for JavaScript property-based testing.
|
||||
|
||||
Each property test runs a minimum of 100 iterations with randomly generated inputs. Tests are tagged with their corresponding design property.
|
||||
|
||||
| Property | What's Generated | What's Verified |
|
||||
|----------|-----------------|-----------------|
|
||||
| Property 1: Selection pruning | Random sets of selected IDs and filtered IDs | Result = intersection of both sets |
|
||||
| Property 2: Select-all | Random finding lists and queued ID sets | Result = visible IDs minus queued IDs |
|
||||
| Property 3: Submit enabled | Random workflow types and vendor strings | Enabled iff CARD or non-empty vendor |
|
||||
| Property 4: Batch size | Random integers 0–300 | Accepted iff 1 ≤ N ≤ 200 |
|
||||
| Property 5: Vendor validation | Random workflow types and vendor strings (0–300 chars) | Conditional acceptance rule |
|
||||
| Property 6: Invalid finding rejection | Valid batches with one injected invalid item | Entire batch rejected, 0 rows inserted |
|
||||
| Property 7: Response shape | Valid batches of 1–50 findings | Response count matches, IDs match |
|
||||
| Property 8: Range select | Random sorted lists and two index positions | Correct range of non-queued findings |
|
||||
|
||||
### Integration Tests
|
||||
|
||||
- End-to-end batch submission: POST valid batch, verify rows in database, verify response shape
|
||||
- Auth enforcement: Verify 401 for unauthenticated, 403 for Read_Only users
|
||||
- Transaction atomicity: Verify rollback on database error
|
||||
- Frontend → Backend: Mock API, verify correct request payload from toolbar submit
|
||||
@@ -1,97 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
The Batch Finding Disposition feature adds multi-select capability to the Vulnerability Triage page's findings table, allowing engineers to select multiple findings at once and add them all to the Ivanti Queue with a shared workflow type and vendor in a single operation. Currently, each finding must be individually clicked, configured via a popover, and submitted — a repetitive process that slows down triage when working through many findings. This feature replaces that one-at-a-time flow with a batch selection toolbar and a bulk-add API endpoint.
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Findings_Table**: The sortable, filterable table of Ivanti host findings rendered in the VulnerabilityTriagePage component (`ReportingPage.js`), where each row represents one finding.
|
||||
- **Selection_Toolbar**: A floating toolbar that appears above the Findings_Table when one or more findings are selected via their row checkboxes, displaying the count of selected findings and batch action controls.
|
||||
- **Batch_Add_Panel**: The inline panel within the Selection_Toolbar that provides workflow type selection (FP, Archer, CARD), an optional vendor input, and a submit button for adding all selected findings to the queue in one operation.
|
||||
- **Todo_Queue_API**: The backend Express router at `/api/ivanti/todo-queue` that manages CRUD operations on the `ivanti_todo_queue` table.
|
||||
- **Queue_Panel**: The existing right-side slide-out panel (`QueuePanel` component) that displays the user's current queue items grouped by vendor.
|
||||
- **Workflow_Type**: One of three disposition categories: FP (false positive), Archer (risk acceptance), or CARD (remediation card). Each finding added to the queue is assigned exactly one Workflow_Type.
|
||||
- **Finding**: A single Ivanti host vulnerability record containing an ID, title, CVEs, IP address, severity, and other metadata.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: Multi-Select Findings via Row Checkboxes
|
||||
|
||||
**User Story:** As an engineer, I want to select multiple findings using checkboxes so that I can batch-process them instead of handling each one individually.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Findings_Table SHALL render a checkbox in the first column of each finding row that is not already in the queue.
|
||||
2. WHEN a user clicks a finding row's checkbox, THE Findings_Table SHALL toggle that Finding's selected state without opening the AddToQueuePopover.
|
||||
3. WHEN one or more findings are selected, THE Findings_Table SHALL visually distinguish selected rows from unselected rows using a highlighted background.
|
||||
4. THE Findings_Table SHALL maintain the selected findings set across sort and filter changes, removing only findings that are no longer visible after filtering.
|
||||
5. WHEN a finding is already in the queue, THE Findings_Table SHALL display that row's checkbox as checked and disabled, preventing re-selection.
|
||||
6. WHILE findings are selected, THE Findings_Table SHALL display a "Select All (visible)" control in the checkbox column header that selects all visible, non-queued findings.
|
||||
7. WHEN the "Select All" control is clicked while all visible non-queued findings are already selected, THE Findings_Table SHALL deselect all findings.
|
||||
|
||||
### Requirement 2: Selection Toolbar with Batch Actions
|
||||
|
||||
**User Story:** As an engineer, I want a toolbar that appears when I have findings selected so that I can see how many are selected and take batch actions on them.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN one or more findings are selected, THE Selection_Toolbar SHALL appear as a sticky bar above the Findings_Table header row.
|
||||
2. THE Selection_Toolbar SHALL display the count of currently selected findings.
|
||||
3. THE Selection_Toolbar SHALL provide a "Clear Selection" button that deselects all findings and hides the Selection_Toolbar.
|
||||
4. THE Selection_Toolbar SHALL provide workflow type toggle buttons for FP, Archer, and CARD, matching the existing color scheme (FP: amber, Archer: blue, CARD: green).
|
||||
5. WHEN the selected Workflow_Type is FP or Archer, THE Selection_Toolbar SHALL display a vendor text input field.
|
||||
6. WHEN the selected Workflow_Type is CARD, THE Selection_Toolbar SHALL hide the vendor input field and display a "No vendor required" indicator.
|
||||
7. THE Selection_Toolbar SHALL provide an "Add to Queue" submit button that is enabled only when a Workflow_Type is selected and vendor is provided (for FP/Archer) or Workflow_Type is CARD.
|
||||
8. THE Selection_Toolbar SHALL follow the existing dark theme design system (monospace fonts, dark gradient backgrounds, accent-colored borders).
|
||||
|
||||
### Requirement 3: Bulk Add to Queue API Endpoint
|
||||
|
||||
**User Story:** As an engineer, I want the backend to accept multiple findings in a single request so that batch additions are processed efficiently.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Todo_Queue_API SHALL expose a `POST /api/ivanti/todo-queue/batch` endpoint that accepts an array of finding objects with a shared workflow_type and vendor.
|
||||
2. THE Todo_Queue_API SHALL validate that the findings array contains between 1 and 200 items.
|
||||
3. THE Todo_Queue_API SHALL validate that each finding object contains a non-empty finding_id string.
|
||||
4. THE Todo_Queue_API SHALL validate that workflow_type is one of FP, Archer, or CARD.
|
||||
5. WHEN workflow_type is FP or Archer, THE Todo_Queue_API SHALL validate that vendor is a non-empty string of 200 characters or fewer.
|
||||
6. WHEN workflow_type is CARD, THE Todo_Queue_API SHALL accept an empty or absent vendor field.
|
||||
7. THE Todo_Queue_API SHALL insert all valid findings into the `ivanti_todo_queue` table within a single database transaction.
|
||||
8. IF any finding in the batch fails validation, THEN THE Todo_Queue_API SHALL reject the entire batch and return a 400 response with a descriptive error message.
|
||||
9. THE Todo_Queue_API SHALL return a 201 response containing the array of newly created queue items with their assigned IDs.
|
||||
10. THE Todo_Queue_API SHALL require authentication and the Admin or Standard_User group.
|
||||
11. IF a database error occurs during the transaction, THEN THE Todo_Queue_API SHALL roll back all inserts and return a 500 response.
|
||||
|
||||
### Requirement 4: Frontend Batch Submission Flow
|
||||
|
||||
**User Story:** As an engineer, I want clicking "Add to Queue" on the toolbar to submit all selected findings at once so that I save time during triage.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the user clicks "Add to Queue" on the Selection_Toolbar, THE Findings_Table SHALL send a single POST request to `POST /api/ivanti/todo-queue/batch` containing all selected findings with the chosen workflow_type and vendor.
|
||||
2. WHILE the batch request is in progress, THE Selection_Toolbar SHALL disable the "Add to Queue" button and display a loading indicator.
|
||||
3. WHEN the batch request succeeds, THE Findings_Table SHALL add all returned queue items to the local queue state, clear the selection, and hide the Selection_Toolbar.
|
||||
4. WHEN the batch request succeeds, THE Findings_Table SHALL update each newly queued finding's row checkbox to show the checked-and-disabled (already queued) state.
|
||||
5. IF the batch request fails, THEN THE Selection_Toolbar SHALL display the error message returned by the API and keep the current selection intact.
|
||||
6. WHEN the batch request succeeds and the Queue_Panel is open, THE Queue_Panel SHALL reflect the newly added items immediately without requiring a manual refresh.
|
||||
|
||||
### Requirement 5: Preserve Single-Select Popover Flow
|
||||
|
||||
**User Story:** As an engineer, I want to still be able to add a single finding to the queue quickly without going through the batch flow, so that simple one-off additions remain fast.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN no findings are currently selected and a user clicks a finding row's checkbox, THE Findings_Table SHALL open the existing AddToQueuePopover for that single finding.
|
||||
2. WHEN one or more findings are already selected and a user clicks another finding row's checkbox, THE Findings_Table SHALL add that finding to the selection set instead of opening the AddToQueuePopover.
|
||||
3. THE AddToQueuePopover SHALL continue to use the existing single-item `POST /api/ivanti/todo-queue` endpoint for individual additions.
|
||||
|
||||
### Requirement 6: Keyboard Accessibility for Multi-Select
|
||||
|
||||
**User Story:** As an engineer, I want to use keyboard shortcuts to speed up multi-select so that I can triage even faster.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a user holds Shift and clicks a finding row's checkbox, THE Findings_Table SHALL select all visible findings between the last clicked checkbox and the current checkbox (range select).
|
||||
2. THE Selection_Toolbar SHALL be navigable via keyboard Tab order, with all interactive elements (workflow buttons, vendor input, submit button) reachable by Tab key.
|
||||
3. WHEN the Escape key is pressed while the Selection_Toolbar is visible, THE Findings_Table SHALL clear the selection and hide the Selection_Toolbar.
|
||||
@@ -1,116 +0,0 @@
|
||||
# Implementation Plan: Batch Finding Disposition
|
||||
|
||||
## Overview
|
||||
|
||||
Add multi-select capability to the Vulnerability Triage findings table with a batch-add-to-queue API endpoint. The backend gets a new `POST /api/ivanti/todo-queue/batch` route in `ivantiTodoQueue.js`. The frontend gets selection state, checkbox dual-mode logic, a SelectionToolbar component, shift-click range select, select-all, and Escape-to-clear — all within `ReportingPage.js`.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [x] 1. Add `POST /api/ivanti/todo-queue/batch` endpoint
|
||||
- [x] 1.1 Add batch route handler to `backend/routes/ivantiTodoQueue.js`
|
||||
- Add `POST /batch` route inside `createIvantiTodoQueueRouter`, before the `POST /` route
|
||||
- Apply `requireAuth(db)` and `requireGroup('Admin', 'Standard_User')` middleware
|
||||
- Validate request body: `findings` array (1–200 items), each with non-empty `finding_id` string
|
||||
- Validate `workflow_type` is one of `FP`, `Archer`, `CARD`
|
||||
- Validate `vendor`: required non-empty string ≤200 chars for FP/Archer; ignored for CARD
|
||||
- If any validation fails, return 400 with descriptive error message and reject entire batch
|
||||
- _Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.8, 3.10_
|
||||
- [x] 1.2 Implement transactional batch insert with SQLite
|
||||
- Use `db.serialize()` with `BEGIN TRANSACTION` / `COMMIT` to insert all findings atomically
|
||||
- For each finding: insert row into `ivanti_todo_queue` with `user_id`, `finding_id`, `finding_title`, `cves_json`, `ip_address`, `vendor`, `workflow_type`
|
||||
- On success: fetch all inserted rows, parse `cves_json` back to arrays, return 201 with `{ items: [...] }`
|
||||
- On any DB error: `ROLLBACK` the transaction and return 500
|
||||
- _Requirements: 3.7, 3.8, 3.9, 3.11_
|
||||
- [x] 1.3 Add audit logging for batch additions
|
||||
- After successful commit, call `logAudit(db, { ... })` with action `'batch_add_to_queue'`, entityType `'ivanti_todo_queue'`, and details including the count and workflow_type
|
||||
- Import `logAudit` from `../helpers/auditLog`
|
||||
- _Requirements: 3.7_
|
||||
|
||||
- [x] 2. Checkpoint — Verify backend endpoint
|
||||
- Ensure the batch endpoint is syntactically correct and the route file has no errors. Ask the user if questions arise.
|
||||
|
||||
- [x] 3. Add multi-select state and checkbox dual-mode logic to `ReportingPage.js`
|
||||
- [x] 3.1 Add selection state variables to `VulnerabilityTriagePage`
|
||||
- Add `selectedIds` (`new Set()`), `lastClickedId` (null), `batchSubmitting` (false), `batchError` (null), `batchWorkflowType` ('FP'), `batchVendor` ('') as new `useState` hooks
|
||||
- _Requirements: 1.1, 2.1_
|
||||
- [x] 3.2 Implement checkbox dual-mode click handler
|
||||
- Replace the existing `<td>` onClick in the checkbox cell with new logic:
|
||||
- If finding is already queued → no-op (existing behavior)
|
||||
- If `selectedIds.size === 0` AND not shift-click → open `AddToQueuePopover` (preserves single-select flow)
|
||||
- If shift-click AND `lastClickedId` exists → range-select all visible non-queued findings between `lastClickedId` and current finding in the `sorted` array
|
||||
- Otherwise → toggle finding.id in `selectedIds`
|
||||
- Always update `lastClickedId` when toggling selection
|
||||
- _Requirements: 1.1, 1.2, 5.1, 5.2, 6.1_
|
||||
- [x] 3.3 Add visual highlighting for selected rows
|
||||
- When a finding's ID is in `selectedIds`, apply a highlighted background (e.g. `rgba(14,165,233,0.12)`) to the row
|
||||
- Override the existing alternating row background and hover for selected rows
|
||||
- _Requirements: 1.3_
|
||||
- [x] 3.4 Disable checkbox for already-queued findings
|
||||
- Keep existing behavior: queued findings show checked + disabled checkbox, preventing re-selection
|
||||
- Ensure queued findings are excluded from shift-click range select and select-all
|
||||
- _Requirements: 1.5_
|
||||
|
||||
- [x] 4. Implement Select All / Deselect All in column header
|
||||
- Modify the checkbox column `<th>` to render a clickable "Select All" checkbox when `selectedIds.size > 0` or when the user interacts with it
|
||||
- Click behavior: if not all visible non-queued findings are selected → select all visible non-queued; if all are selected → deselect all
|
||||
- _Requirements: 1.6, 1.7_
|
||||
|
||||
- [x] 5. Add selection pruning on filter changes
|
||||
- Add a `useEffect` that watches `filtered` (the filtered findings array) and prunes `selectedIds` to only include IDs still present in the filtered set
|
||||
- This ensures selection stays consistent when `columnFilters`, `actionFilter`, or `excFilter` change
|
||||
- _Requirements: 1.4_
|
||||
|
||||
- [x] 6. Implement SelectionToolbar component
|
||||
- [x] 6.1 Create the `SelectionToolbar` inline component in `ReportingPage.js`
|
||||
- Render between the panel header controls and the `<table>` element, only when `selectedIds.size > 0`
|
||||
- Use `position: sticky` with appropriate `top` value to stay visible during scroll
|
||||
- Follow the dark theme design system: monospace fonts, dark gradient background, accent-colored borders
|
||||
- _Requirements: 2.1, 2.8_
|
||||
- [x] 6.2 Add toolbar controls: count badge, Clear Selection, workflow toggles, vendor input, submit button
|
||||
- Display selected count badge (e.g. "12 selected")
|
||||
- "Clear Selection" button that empties `selectedIds` and hides toolbar
|
||||
- Workflow type toggle buttons (FP / Archer / CARD) using existing color scheme: FP = amber (`#F59E0B`), Archer = blue (`#0EA5E9`), CARD = green (`#10B981`)
|
||||
- Vendor text input (hidden when CARD is selected, show "No vendor required" indicator for CARD)
|
||||
- "Add to Queue" submit button — enabled only when workflow_type is CARD, or vendor is non-empty
|
||||
- _Requirements: 2.2, 2.3, 2.4, 2.5, 2.6, 2.7_
|
||||
|
||||
- [x] 7. Implement batch submission flow
|
||||
- [x] 7.1 Add `submitBatch` async function to `VulnerabilityTriagePage`
|
||||
- Build request payload from `selectedIds` (map each ID to its finding object from `sorted`/`filtered` for `finding_id`, `finding_title`, `cves`, `ip_address`), plus `batchWorkflowType` and `batchVendor`
|
||||
- POST to `${API_BASE}/ivanti/todo-queue/batch` with `credentials: 'include'`
|
||||
- Set `batchSubmitting = true` before request, `false` after
|
||||
- _Requirements: 4.1, 4.2_
|
||||
- [x] 7.2 Handle batch success response
|
||||
- On 201: merge returned items into `queueItems` state (sorted by vendor then id, matching existing pattern)
|
||||
- Clear `selectedIds`, reset `batchWorkflowType` to 'FP', reset `batchVendor` to '', clear `batchError`
|
||||
- The newly queued findings will automatically show as checked+disabled via the existing `isQueued()` helper
|
||||
- _Requirements: 4.3, 4.4, 4.6_
|
||||
- [x] 7.3 Handle batch error response
|
||||
- On 4xx/5xx: parse error message from response JSON, set `batchError` to display in toolbar
|
||||
- On network failure: set `batchError` to "Network error — please try again"
|
||||
- Keep selection intact on error so user can retry
|
||||
- _Requirements: 4.5_
|
||||
|
||||
- [x] 8. Add Escape key handler to clear selection
|
||||
- Add a `useEffect` with a `keydown` listener for Escape that clears `selectedIds` when the SelectionToolbar is visible (i.e. `selectedIds.size > 0`)
|
||||
- Ensure it doesn't conflict with the existing Escape handler on `AddToQueuePopover`
|
||||
- _Requirements: 6.3_
|
||||
|
||||
- [x] 9. Ensure keyboard Tab accessibility for SelectionToolbar
|
||||
- Verify all interactive elements in the toolbar (workflow buttons, vendor input, submit button, clear button) are focusable via Tab key
|
||||
- Use native `<button>` and `<input>` elements (which are inherently tabbable) rather than `<div>` with onClick
|
||||
- _Requirements: 6.2_
|
||||
|
||||
- [x] 10. Final checkpoint — Full integration verification
|
||||
- Ensure all files have no syntax errors or diagnostic issues
|
||||
- Verify the checkbox dual-mode logic: no selection → popover, existing selection → toggle
|
||||
- Verify the SelectionToolbar renders/hides correctly based on selection state
|
||||
- Verify batch submit wires through to the backend endpoint and updates queue state
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
## Notes
|
||||
|
||||
- No new database migration needed — batch insert reuses the existing `ivanti_todo_queue` schema
|
||||
- The batch endpoint must be registered before `POST /` in the router to avoid Express route conflicts
|
||||
- All testing is done on the dev server after push — no local test tasks included
|
||||
- Each task references specific acceptance criteria from the requirements document for traceability
|
||||
@@ -1 +0,0 @@
|
||||
{"specId": "b8855eb4-3949-426e-86ac-36fe069a6bb1", "workflowType": "requirements-first", "specType": "feature"}
|
||||
@@ -1,229 +0,0 @@
|
||||
# Design Document: CVE Tooltip Hover
|
||||
|
||||
## Overview
|
||||
|
||||
This feature adds a hover tooltip to CVE badges in the Reporting Page findings table. When a user pauses their cursor over a CVE identifier badge, the system fetches a brief description and severity from the backend and displays it in a styled floating tooltip. Responses are cached in-memory to avoid redundant API calls, and a 300ms hover delay prevents tooltip flicker during fast mouse movement.
|
||||
|
||||
The implementation spans two layers:
|
||||
1. A new lightweight backend endpoint (`/api/cves/:cveId/tooltip`) that queries the existing `cves` SQLite table and returns a trimmed response.
|
||||
2. A frontend `CveTooltip` component rendered via a React portal, with an in-memory cache (React ref), hover delay timer, and viewport-aware positioning.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant CVEBadge as CVE Badge (ReportingPage)
|
||||
participant Tooltip as CveTooltip Component
|
||||
participant Cache as Tooltip Cache (useRef)
|
||||
participant API as /api/cves/:cveId/tooltip
|
||||
participant DB as SQLite (cves table)
|
||||
|
||||
User->>CVEBadge: mouseenter
|
||||
CVEBadge->>Tooltip: start 300ms delay timer
|
||||
Note over Tooltip: If mouseout before 300ms, cancel
|
||||
|
||||
alt Cache hit
|
||||
Tooltip->>Cache: lookup(cveId)
|
||||
Cache-->>Tooltip: cached data
|
||||
Tooltip->>User: show tooltip (or skip if exists:false)
|
||||
else Cache miss
|
||||
Tooltip->>API: GET /api/cves/:cveId/tooltip
|
||||
API->>DB: SELECT cve_id, description, severity FROM cves WHERE cve_id = ?
|
||||
DB-->>API: row or null
|
||||
API-->>Tooltip: { exists, cve_id, description, severity }
|
||||
Tooltip->>Cache: store response
|
||||
Tooltip->>User: show tooltip (or skip if exists:false)
|
||||
end
|
||||
|
||||
User->>CVEBadge: mouseleave
|
||||
CVEBadge->>Tooltip: hide + clear timer
|
||||
```
|
||||
|
||||
### Key Design Decisions
|
||||
|
||||
1. **Inline endpoint in server.js** — The tooltip endpoint is a single GET route on the existing `/api/cves` path prefix. It follows the pattern of other simple CVE endpoints already defined inline in `server.js` (e.g., `/api/cves/check/:cveId`, `/api/cves/:cveId/vendors`). No separate route module needed.
|
||||
|
||||
2. **React portal for tooltip rendering** — The tooltip is rendered via `ReactDOM.createPortal` to `document.body`, avoiding overflow/clipping issues from the table's scroll container. The ReportingPage already imports `ReactDOM` for other portal usage.
|
||||
|
||||
3. **useRef for cache instead of useState** — The cache is a plain `Map` stored in a `useRef`. This avoids re-renders when cache entries are added and persists across renders without triggering updates. The cache is cleared when the findings data is re-synced.
|
||||
|
||||
4. **Single shared tooltip instance** — Only one tooltip is visible at a time. The parent component tracks which CVE badge is hovered and passes the active CVE ID + badge position to the tooltip component.
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### Backend
|
||||
|
||||
#### `GET /api/cves/:cveId/tooltip`
|
||||
|
||||
Added inline in `server.js` alongside existing CVE endpoints.
|
||||
|
||||
- **Auth**: `requireAuth(db)` — session cookie required
|
||||
- **Params**: `:cveId` — validated against `CVE_ID_PATTERN` (`/^CVE-\d{4}-\d{4,}$/`)
|
||||
- **Query**: `SELECT cve_id, description, severity FROM cves WHERE cve_id = ? LIMIT 1`
|
||||
- **Response (found)**:
|
||||
```json
|
||||
{
|
||||
"exists": true,
|
||||
"cve_id": "CVE-2024-12345",
|
||||
"description": "A vulnerability in...",
|
||||
"severity": "High"
|
||||
}
|
||||
```
|
||||
- **Response (not found)**:
|
||||
```json
|
||||
{ "exists": false }
|
||||
```
|
||||
- **Description truncation**: If `description.length > 300`, return `description.substring(0, 300) + '…'`
|
||||
|
||||
### Frontend
|
||||
|
||||
#### `CveTooltip` Component (new file: `frontend/src/components/CveTooltip.js`)
|
||||
|
||||
A portal-rendered tooltip that receives positioning data and CVE info.
|
||||
|
||||
**Props:**
|
||||
| Prop | Type | Description |
|
||||
|------|------|-------------|
|
||||
| `cveId` | `string \| null` | The CVE ID to display. `null` hides the tooltip. |
|
||||
| `anchorRect` | `DOMRect \| null` | Bounding rect of the hovered badge for positioning. |
|
||||
| `cache` | `React.MutableRefObject<Map>` | Shared cache ref from parent. |
|
||||
|
||||
**Internal state:**
|
||||
- `data` — fetched tooltip payload (`{ exists, cve_id, description, severity }` or `null`)
|
||||
- `loading` — boolean, true while fetch is in-flight
|
||||
|
||||
**Behavior:**
|
||||
1. When `cveId` changes to a non-null value, check `cache.current` for the CVE ID.
|
||||
2. If cached and `exists: false`, render nothing.
|
||||
3. If cached and `exists: true`, display immediately.
|
||||
4. If not cached, set `loading = true`, fetch from API, store result in cache, set `loading = false`.
|
||||
5. Position the tooltip above the badge by default. If the tooltip would overflow the top of the viewport, position it below instead.
|
||||
6. Render via `ReactDOM.createPortal` to `document.body`.
|
||||
|
||||
#### ReportingPage Integration
|
||||
|
||||
Modifications to the existing `renderCell` function for the `'cves'` case:
|
||||
|
||||
- Add `onMouseEnter` / `onMouseLeave` handlers to each CVE badge `<span>`.
|
||||
- `onMouseEnter`: Start a 300ms `setTimeout`. On fire, set active CVE ID + badge `getBoundingClientRect()` into state.
|
||||
- `onMouseLeave`: Clear the timeout. Set active CVE ID to `null`.
|
||||
- Render a single `<CveTooltip>` instance at the bottom of the component, passing the active CVE ID, anchor rect, and cache ref.
|
||||
- On data sync (when findings are refreshed), call `cache.current.clear()`.
|
||||
|
||||
## Data Models
|
||||
|
||||
### Existing: `cves` Table (SQLite)
|
||||
|
||||
The tooltip endpoint queries the existing table. No schema changes required.
|
||||
|
||||
```sql
|
||||
CREATE TABLE cves (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id TEXT NOT NULL,
|
||||
vendor TEXT NOT NULL,
|
||||
severity TEXT CHECK(severity IN ('Critical', 'High', 'Medium', 'Low')),
|
||||
description TEXT,
|
||||
published_date TEXT,
|
||||
status TEXT DEFAULT 'Open',
|
||||
created_by INTEGER,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(cve_id, vendor)
|
||||
);
|
||||
```
|
||||
|
||||
The query uses `LIMIT 1` since a CVE may have multiple vendor rows — the description and severity from any row suffice for the tooltip blurb.
|
||||
|
||||
### Frontend Cache Structure
|
||||
|
||||
```javascript
|
||||
// cache.current is a Map<string, object>
|
||||
// Key: CVE ID string (e.g. "CVE-2024-12345")
|
||||
// Value: API response object
|
||||
// { exists: false }
|
||||
// OR
|
||||
// { exists: true, cve_id: string, description: string, severity: string }
|
||||
```
|
||||
|
||||
|
||||
## Correctness Properties
|
||||
|
||||
*A property is a characteristic or behavior that should hold true across all valid executions of a system — essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
|
||||
|
||||
### Property 1: Tooltip endpoint returns correct data for existing CVEs
|
||||
|
||||
*For any* CVE record inserted into the `cves` table with a valid `cve_id`, `description`, and `severity`, a GET request to `/api/cves/:cveId/tooltip` SHALL return `{ exists: true }` with the matching `cve_id` and `severity`, and a `description` that is either the original (if ≤ 300 chars) or truncated to 300 chars + ellipsis.
|
||||
|
||||
**Validates: Requirements 1.1, 1.3, 1.5**
|
||||
|
||||
### Property 2: Description truncation preserves content and enforces length
|
||||
|
||||
*For any* string of arbitrary length, the truncation function SHALL return the original string unchanged if its length is ≤ 300, or return exactly the first 300 characters followed by "…" if its length exceeds 300. In both cases, the output starts with the same characters as the input.
|
||||
|
||||
**Validates: Requirements 1.5**
|
||||
|
||||
### Property 3: Tooltip positioning flips based on available viewport space
|
||||
|
||||
*For any* anchor rectangle position and viewport height, the tooltip SHALL be positioned above the anchor when `anchorRect.top` provides sufficient space for the tooltip height, and below the anchor otherwise. The tooltip SHALL never overflow the top or bottom of the viewport.
|
||||
|
||||
**Validates: Requirements 3.1, 3.2**
|
||||
|
||||
### Property 4: Cache round-trip — fetch then cache-hit avoids network call
|
||||
|
||||
*For any* CVE ID, after the tooltip system fetches data from the API and stores it in the cache, a subsequent tooltip request for the same CVE ID SHALL return the identical cached data object without making an additional network request.
|
||||
|
||||
**Validates: Requirements 4.1, 4.2**
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Layer | Behavior |
|
||||
|----------|-------|----------|
|
||||
| Invalid CVE ID format in URL param | Backend | Return `400 { error: 'Invalid CVE ID format.' }` |
|
||||
| Database query error | Backend | Log error, return `500 { error: 'Internal server error.' }` |
|
||||
| No session cookie / expired session | Backend | `requireAuth` middleware returns `401` |
|
||||
| Network error during fetch | Frontend | Catch error, hide tooltip (do not cache failures), log to console |
|
||||
| Fetch timeout / slow response | Frontend | Show loading state; if user moves away, cancel via AbortController |
|
||||
| Component unmounts during fetch | Frontend | AbortController signal aborts in-flight request, no state update |
|
||||
|
||||
**Key principle**: Transient errors (network failures, timeouts) are NOT cached. Only successful API responses (both `exists: true` and `exists: false`) are stored in the cache. This ensures a retry on next hover for failed requests.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests (Example-Based)
|
||||
|
||||
| Test | Validates |
|
||||
|------|-----------|
|
||||
| Endpoint returns `{ exists: false }` for unknown CVE ID | Req 1.2 |
|
||||
| Endpoint returns 401 without session cookie | Req 1.4 |
|
||||
| Endpoint returns 400 for malformed CVE ID (e.g. "not-a-cve") | Req 1.1 (error path) |
|
||||
| Tooltip appears after 300ms hover delay | Req 5.1 |
|
||||
| Tooltip cancelled if mouseout before 300ms | Req 5.2 |
|
||||
| Tooltip hidden on mouseleave | Req 2.2 |
|
||||
| Loading indicator shown while fetching | Req 2.5 |
|
||||
| No tooltip shown when API returns `exists: false` | Req 2.6 |
|
||||
| Severity badge uses correct color per level | Req 2.4 |
|
||||
| Tooltip has max-width of 320px | Req 3.3 |
|
||||
| Tooltip includes directional arrow element | Req 3.5 |
|
||||
| Cache cleared on data sync/refresh | Req 4.4 |
|
||||
| Cached `exists: false` suppresses tooltip and API call | Req 4.3 |
|
||||
|
||||
### Property-Based Tests
|
||||
|
||||
Property-based tests use **fast-check** (JavaScript PBT library, already compatible with the Jest/react-scripts test runner).
|
||||
|
||||
Each property test runs a minimum of **100 iterations**.
|
||||
|
||||
| Property | Tag | Focus |
|
||||
|----------|-----|-------|
|
||||
| Property 1 | `Feature: cve-tooltip-hover, Property 1: Tooltip endpoint returns correct data for existing CVEs` | Generate random CVE records (varying description lengths 0–1000, all 4 severity levels), insert into test DB, call endpoint, verify response shape and truncation |
|
||||
| Property 2 | `Feature: cve-tooltip-hover, Property 2: Description truncation preserves content and enforces length` | Generate random strings of length 0–2000, apply truncation function, verify length invariant and prefix preservation |
|
||||
| Property 3 | `Feature: cve-tooltip-hover, Property 3: Tooltip positioning flips based on available viewport space` | Generate random anchorRect.top (0–2000), tooltip height (50–200), viewport height (400–1200), verify position is within viewport bounds |
|
||||
| Property 4 | `Feature: cve-tooltip-hover, Property 4: Cache round-trip` | Generate random CVE IDs and response payloads, store in cache Map, verify subsequent lookups return identical objects and no fetch is triggered |
|
||||
|
||||
### Test Configuration
|
||||
|
||||
- Test runner: `react-scripts test` (Jest) — already configured in the project
|
||||
- PBT library: `fast-check` — install via `npm install --save-dev fast-check` in the `frontend/` directory
|
||||
- Backend endpoint tests: Use supertest or direct handler invocation with a test SQLite DB
|
||||
- Frontend component tests: React Testing Library with mocked fetch
|
||||
@@ -1,73 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
Add a hover tooltip to CVE badges in the Reporting Page (vuln triage view). When a user hovers over a CVE identifier badge in the findings table, the system checks whether that CVE exists in the local SQLite database. If it does, a small tooltip appears showing a brief description/blurb about that CVE. CVEs not present in the database show no tooltip.
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Reporting_Page**: The vulnerability triage view at `frontend/src/components/pages/ReportingPage.js` that displays Ivanti host findings in a sortable, filterable table.
|
||||
- **CVE_Badge**: The styled `<span>` element in the CVEs column of the findings table that displays a CVE identifier (e.g. CVE-2024-12345) with a purple pill/box appearance.
|
||||
- **CVE_Tooltip**: A small floating box that appears on mouse hover over a CVE_Badge, displaying a text blurb about the CVE.
|
||||
- **CVE_Database**: The `cves` table in the SQLite database (`backend/cve_database.db`) that stores CVE records including descriptions, severity, and vendor information.
|
||||
- **Tooltip_Cache**: An in-memory lookup (React state or ref) that stores previously fetched CVE descriptions to avoid redundant API calls during the same session.
|
||||
- **API_Server**: The Express backend at `backend/server.js` that serves CVE data via `/api` endpoints.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: CVE Tooltip Data Endpoint
|
||||
|
||||
**User Story:** As a frontend component, I want to fetch a brief description for a given CVE ID, so that the tooltip can display relevant information without loading unnecessary data.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a GET request is made to `/api/cves/:cveId/tooltip`, THE API_Server SHALL return a JSON object containing the `cve_id`, `description`, and `severity` fields for the matching CVE record.
|
||||
2. WHEN a GET request is made to `/api/cves/:cveId/tooltip` for a CVE ID that does not exist in the CVE_Database, THE API_Server SHALL return a JSON object with `{ exists: false }` and HTTP status 200.
|
||||
3. WHEN a GET request is made to `/api/cves/:cveId/tooltip` for a CVE ID that exists in the CVE_Database, THE API_Server SHALL return a JSON object with `{ exists: true, cve_id, description, severity }` and HTTP status 200.
|
||||
4. THE API_Server SHALL require a valid session cookie for the `/api/cves/:cveId/tooltip` endpoint.
|
||||
5. WHEN the `description` field exceeds 300 characters, THE API_Server SHALL truncate the description to 300 characters and append an ellipsis ("…").
|
||||
|
||||
### Requirement 2: Tooltip Display on CVE Badge Hover
|
||||
|
||||
**User Story:** As a security analyst triaging findings, I want to see a brief description of a CVE when I hover over its badge in the findings table, so that I can quickly understand the vulnerability without leaving the page.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the user hovers the mouse cursor over a CVE_Badge in the Reporting_Page findings table, THE Reporting_Page SHALL display a CVE_Tooltip near the hovered badge.
|
||||
2. WHEN the user moves the mouse cursor away from the CVE_Badge, THE Reporting_Page SHALL hide the CVE_Tooltip.
|
||||
3. THE CVE_Tooltip SHALL display the CVE description text returned by the API_Server.
|
||||
4. THE CVE_Tooltip SHALL display the severity level of the CVE using the existing severity color scheme (Critical: red, High: amber, Medium: sky blue, Low: emerald).
|
||||
5. WHILE the CVE data is being fetched from the API_Server, THE CVE_Tooltip SHALL display a loading indicator.
|
||||
6. WHEN the API_Server returns `exists: false` for a CVE ID, THE Reporting_Page SHALL not display a CVE_Tooltip for that badge.
|
||||
|
||||
### Requirement 3: Tooltip Positioning and Styling
|
||||
|
||||
**User Story:** As a security analyst, I want the CVE tooltip to be readable and not obstruct other table content, so that I can continue triaging while viewing CVE details.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE CVE_Tooltip SHALL appear above the hovered CVE_Badge by default.
|
||||
2. WHEN there is insufficient viewport space above the CVE_Badge, THE CVE_Tooltip SHALL appear below the badge instead.
|
||||
3. THE CVE_Tooltip SHALL have a maximum width of 320 pixels.
|
||||
4. THE CVE_Tooltip SHALL use the design system dark theme styling: dark background gradient, accent border, monospace font for the CVE ID, and standard font for the description text.
|
||||
5. THE CVE_Tooltip SHALL include a small directional arrow pointing toward the CVE_Badge.
|
||||
|
||||
### Requirement 4: Tooltip Response Caching
|
||||
|
||||
**User Story:** As a security analyst scrolling through many findings, I want CVE tooltip data to load instantly for CVEs I have already hovered over, so that repeated hovers do not cause redundant network requests.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the Reporting_Page fetches tooltip data for a CVE ID, THE Tooltip_Cache SHALL store the response for that CVE ID.
|
||||
2. WHEN the user hovers over a CVE_Badge for a CVE ID that exists in the Tooltip_Cache, THE Reporting_Page SHALL display the cached data without making an API call.
|
||||
3. WHEN the user hovers over a CVE_Badge for a CVE ID where the Tooltip_Cache stores `exists: false`, THE Reporting_Page SHALL not display a tooltip and SHALL not make an API call.
|
||||
4. WHEN the Reporting_Page performs a full data sync (refresh), THE Tooltip_Cache SHALL be cleared.
|
||||
|
||||
### Requirement 5: Hover Delay
|
||||
|
||||
**User Story:** As a security analyst, I want the tooltip to only appear after a brief pause on a CVE badge, so that tooltips do not flash distractingly when I move the mouse across the table quickly.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the user hovers over a CVE_Badge, THE Reporting_Page SHALL wait 300 milliseconds before initiating the tooltip display sequence.
|
||||
2. IF the user moves the mouse away from the CVE_Badge before 300 milliseconds have elapsed, THEN THE Reporting_Page SHALL cancel the tooltip display and not make an API call.
|
||||
@@ -1,107 +0,0 @@
|
||||
# Implementation Plan: CVE Tooltip Hover
|
||||
|
||||
## Overview
|
||||
|
||||
Implement a hover tooltip for CVE badges in the Reporting Page findings table. The feature spans a backend endpoint (`GET /api/cves/:cveId/tooltip`) and a frontend `CveTooltip` portal component with in-memory caching and 300ms hover delay. Tasks are ordered backend-first, then frontend component, then integration, with property tests alongside each layer.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [x] 1. Add backend tooltip endpoint
|
||||
- [x] 1.1 Add `GET /api/cves/:cveId/tooltip` route inline in `backend/server.js`
|
||||
- Place it alongside existing CVE endpoints (after `/api/cves/:cveId/vendors`)
|
||||
- Validate `:cveId` against existing `CVE_ID_PATTERN`; return 400 for invalid format
|
||||
- Query: `SELECT cve_id, description, severity FROM cves WHERE cve_id = ? LIMIT 1`
|
||||
- If no row: return `{ exists: false }` with status 200
|
||||
- If row found: truncate `description` to 300 chars + "…" if needed, return `{ exists: true, cve_id, description, severity }`
|
||||
- Protect with `requireAuth(db)` middleware
|
||||
- _Requirements: 1.1, 1.2, 1.3, 1.4, 1.5_
|
||||
|
||||
- [ ]* 1.2 Write property test for tooltip endpoint data correctness
|
||||
- **Property 1: Tooltip endpoint returns correct data for existing CVEs**
|
||||
- Install `fast-check` as dev dependency in `frontend/` (shared test runner)
|
||||
- Generate random CVE records with description lengths 0–1000 and all 4 severity levels
|
||||
- Verify response shape, truncation at 300 chars, and prefix preservation
|
||||
- **Validates: Requirements 1.1, 1.3, 1.5**
|
||||
|
||||
- [ ]* 1.3 Write property test for description truncation
|
||||
- **Property 2: Description truncation preserves content and enforces length**
|
||||
- Extract truncation logic into a testable pure function
|
||||
- Generate random strings of length 0–2000, verify length invariant and prefix match
|
||||
- **Validates: Requirements 1.5**
|
||||
|
||||
- [x] 2. Checkpoint — Verify backend endpoint
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [x] 3. Create CveTooltip frontend component
|
||||
- [x] 3.1 Create `frontend/src/components/CveTooltip.js`
|
||||
- Portal-rendered component using `ReactDOM.createPortal` to `document.body`
|
||||
- Props: `cveId` (string|null), `anchorRect` (DOMRect|null), `cache` (useRef Map)
|
||||
- Internal state: `data`, `loading`
|
||||
- On `cveId` change: check cache → if miss, fetch from `/api/cves/:cveId/tooltip` with AbortController
|
||||
- If cached `exists: false` or fetch returns `exists: false`, render nothing
|
||||
- Show loading spinner (Loader from lucide-react) while fetching
|
||||
- Display: CVE ID in monospace, severity badge with design system colors, description text
|
||||
- Max-width 320px, dark theme gradient background, accent border, directional arrow
|
||||
- Position above anchor by default; flip below if insufficient viewport space above
|
||||
- Do not cache transient errors (network failures)
|
||||
- _Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 3.1, 3.2, 3.3, 3.4, 3.5_
|
||||
|
||||
- [ ]* 3.2 Write property test for tooltip positioning logic
|
||||
- **Property 3: Tooltip positioning flips based on available viewport space**
|
||||
- Extract positioning calculation into a pure function
|
||||
- Generate random anchorRect.top (0–2000), tooltip height (50–200), viewport height (400–1200)
|
||||
- Verify tooltip never overflows top or bottom of viewport
|
||||
- **Validates: Requirements 3.1, 3.2**
|
||||
|
||||
- [ ]* 3.3 Write unit tests for CveTooltip component
|
||||
- Test loading state renders spinner
|
||||
- Test `exists: false` renders nothing
|
||||
- Test severity badge uses correct color per level
|
||||
- Test max-width constraint
|
||||
- Test directional arrow element is present
|
||||
- _Requirements: 2.4, 2.5, 2.6, 3.3, 3.5_
|
||||
|
||||
- [x] 4. Checkpoint — Verify CveTooltip component
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [x] 5. Integrate tooltip into ReportingPage
|
||||
- [x] 5.1 Add hover state and cache ref to ReportingPage
|
||||
- Add state: `tooltipCveId` (string|null), `tooltipAnchorRect` (DOMRect|null)
|
||||
- Add `useRef(new Map())` for tooltip cache
|
||||
- Add `useRef` for hover delay timer
|
||||
- Clear cache when findings data is re-synced (inside existing sync callback)
|
||||
- _Requirements: 4.1, 4.4, 5.1_
|
||||
|
||||
- [x] 5.2 Add mouseenter/mouseleave handlers to CVE badge spans
|
||||
- In the `renderCell` function for the `'cves'` column case, wrap each CVE badge `<span>` with `onMouseEnter` and `onMouseLeave`
|
||||
- `onMouseEnter`: start 300ms setTimeout; on fire, set `tooltipCveId` and `tooltipAnchorRect` from `getBoundingClientRect()`
|
||||
- `onMouseLeave`: clear timeout, set `tooltipCveId` to null
|
||||
- _Requirements: 2.1, 2.2, 5.1, 5.2_
|
||||
|
||||
- [x] 5.3 Render CveTooltip instance in ReportingPage
|
||||
- Add single `<CveTooltip>` at the bottom of the ReportingPage return, passing `tooltipCveId`, `tooltipAnchorRect`, and cache ref
|
||||
- _Requirements: 2.1, 4.2, 4.3_
|
||||
|
||||
- [ ]* 5.4 Write property test for cache round-trip behavior
|
||||
- **Property 4: Cache round-trip — fetch then cache-hit avoids network call**
|
||||
- Generate random CVE IDs and response payloads, store in Map, verify lookups return identical objects
|
||||
- **Validates: Requirements 4.1, 4.2**
|
||||
|
||||
- [ ]* 5.5 Write unit tests for hover delay and cache integration
|
||||
- Test tooltip appears after 300ms delay (use fake timers)
|
||||
- Test tooltip cancelled if mouseout before 300ms
|
||||
- Test cached `exists: false` suppresses tooltip and API call
|
||||
- Test cache cleared on data sync/refresh
|
||||
- _Requirements: 4.3, 4.4, 5.1, 5.2_
|
||||
|
||||
- [x] 6. Final checkpoint — Ensure all tests pass
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
## Notes
|
||||
|
||||
- Tasks marked with `*` are optional and can be skipped for faster MVP
|
||||
- Each task references specific requirements for traceability
|
||||
- Checkpoints ensure incremental validation
|
||||
- Property tests validate universal correctness properties from the design document
|
||||
- Unit tests validate specific examples and edge cases
|
||||
- The project uses plain JavaScript (no TypeScript), fast-check for PBT, and react-scripts test (Jest)
|
||||
@@ -1,293 +0,0 @@
|
||||
# Design Document: Finding Archive Tracking
|
||||
|
||||
## Overview
|
||||
|
||||
The Finding Archive Tracking system adds a detection layer to the existing Ivanti sync pipeline that identifies findings which disappear from sync results due to severity score drift. It tracks these findings through a four-state lifecycle (ACTIVE → ARCHIVED → RETURNED → CLOSED) with full transition history stored in two new SQLite tables. Three new API endpoints expose archive data, and an Archive Summary Bar UI component provides at-a-glance state counts on the Ivanti dashboard.
|
||||
|
||||
The system integrates directly into the existing `syncFindings()` function in `ivantiFindings.js`, comparing current sync results against the previous set to detect disappearances and reappearances. This approach requires no additional API calls to Ivanti and leverages the already-cached findings data.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
subgraph Ivanti Sync Pipeline
|
||||
A[syncFindings] --> B[Fetch all pages from Ivanti API]
|
||||
B --> C[Store findings in ivanti_findings_cache]
|
||||
C --> D[Archive Detection]
|
||||
end
|
||||
|
||||
subgraph Archive Detection
|
||||
D --> E{Compare previous vs current finding IDs}
|
||||
E -->|Missing from current| F[Create/Update Archive Record → ARCHIVED]
|
||||
E -->|Returned in current| G[Update Archive Record → RETURNED]
|
||||
E -->|Closed in Ivanti| H[Update Archive Record → CLOSED]
|
||||
F --> I[Insert Transition History]
|
||||
G --> I
|
||||
H --> I
|
||||
end
|
||||
|
||||
subgraph Archive API
|
||||
J[GET /api/ivanti/archive] --> K[(ivanti_finding_archives)]
|
||||
L[GET /api/ivanti/archive/:findingId/history] --> M[(ivanti_archive_transitions)]
|
||||
N[GET /api/ivanti/archive/stats] --> K
|
||||
end
|
||||
|
||||
subgraph Frontend
|
||||
O[Archive Summary Bar] -->|fetch stats| N
|
||||
O -->|click state| J
|
||||
P[Transition History Panel] -->|fetch history| L
|
||||
end
|
||||
```
|
||||
|
||||
### Integration Points
|
||||
|
||||
1. **Sync Pipeline Hook**: Archive detection runs after `syncFindings()` successfully stores new findings in the cache. It reads the previous findings from the cache before the update, then compares against the new set.
|
||||
2. **Route Registration**: The archive router is mounted at `/api/ivanti/archive` in `server.js`, following the same factory pattern as existing Ivanti routes.
|
||||
3. **Frontend Integration**: The Archive Summary Bar is rendered on the existing Ivanti findings page, above the findings table.
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### 1. Archive Detection Module (`detectArchiveChanges`)
|
||||
|
||||
Located within `backend/routes/ivantiFindings.js`, this async function runs after a successful sync.
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* Compare previous and current finding sets to detect archive state changes.
|
||||
* @param {sqlite3.Database} db - SQLite database instance
|
||||
* @param {Array} previousFindings - Findings from before the sync update
|
||||
* @param {Array} currentFindings - Findings from the latest sync
|
||||
*/
|
||||
async function detectArchiveChanges(db, previousFindings, currentFindings) {
|
||||
// 1. Build ID sets from previous and current
|
||||
// 2. Disappeared = in previous but not in current → ARCHIVED
|
||||
// 3. Returned = in current AND has existing ARCHIVED record → RETURNED
|
||||
// 4. For each state change, upsert archive record + insert transition
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Closed Finding Detection (`detectClosedFindings`)
|
||||
|
||||
Runs during the closed count sync to detect findings that transitioned to CLOSED in Ivanti.
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* Check archived findings against Ivanti closed findings to detect remediation.
|
||||
* @param {sqlite3.Database} db - SQLite database instance
|
||||
* @param {Array} closedFindingIds - IDs of findings confirmed closed in Ivanti
|
||||
*/
|
||||
async function detectClosedFindings(db, closedFindingIds) {
|
||||
// For each archived/returned finding, if it appears in closed set → CLOSED
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Archive API Router (`createIvantiArchiveRouter`)
|
||||
|
||||
Located at `backend/routes/ivantiArchive.js`, follows the existing factory pattern.
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* @param {sqlite3.Database} db - SQLite database instance
|
||||
* @param {Function} requireAuth - Auth middleware factory
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
function createIvantiArchiveRouter(db, requireAuth) {
|
||||
const router = express.Router();
|
||||
router.use(requireAuth(db));
|
||||
|
||||
// GET / - List archive records, optional ?state= filter
|
||||
// GET /stats - Summary counts by state
|
||||
// GET /:findingId/history - Transition history for a finding
|
||||
|
||||
return router;
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Archive Summary Bar Component (`ArchiveSummaryBar`)
|
||||
|
||||
Located at `frontend/src/components/pages/ArchiveSummaryBar.js`.
|
||||
|
||||
```javascript
|
||||
/**
|
||||
* Displays four stat cards for ACTIVE, ARCHIVED, RETURNED, CLOSED counts.
|
||||
* @param {Object} props
|
||||
* @param {Function} props.onStateClick - Callback when a state card is clicked
|
||||
* @param {string|null} props.activeFilter - Currently selected state filter
|
||||
*/
|
||||
function ArchiveSummaryBar({ onStateClick, activeFilter }) { ... }
|
||||
```
|
||||
|
||||
### API Endpoint Specifications
|
||||
|
||||
| Endpoint | Method | Auth | Query Params | Response |
|
||||
|----------|--------|------|-------------|----------|
|
||||
| `/api/ivanti/archive` | GET | Required | `state` (optional: ACTIVE, ARCHIVED, RETURNED, CLOSED) | `{ archives: [...], total: N }` |
|
||||
| `/api/ivanti/archive/stats` | GET | Required | None | `{ ARCHIVED: N, RETURNED: N, CLOSED: N, total: N }` |
|
||||
| `/api/ivanti/archive/:findingId/history` | GET | Required | None | `{ finding_id: "...", transitions: [...] }` |
|
||||
|
||||
## Data Models
|
||||
|
||||
### `ivanti_finding_archives` Table
|
||||
|
||||
| Column | Type | Constraints | Description |
|
||||
|--------|------|-------------|-------------|
|
||||
| `id` | INTEGER | PRIMARY KEY AUTOINCREMENT | Row ID |
|
||||
| `finding_id` | TEXT | NOT NULL UNIQUE | Ivanti finding identifier |
|
||||
| `finding_title` | TEXT | NOT NULL DEFAULT '' | Finding title at time of archival |
|
||||
| `host_name` | TEXT | NOT NULL DEFAULT '' | Host name at time of archival |
|
||||
| `ip_address` | TEXT | NOT NULL DEFAULT '' | IP address at time of archival |
|
||||
| `current_state` | TEXT | NOT NULL CHECK(IN ('ARCHIVED','RETURNED','CLOSED')) | Current lifecycle state |
|
||||
| `last_severity` | REAL | NOT NULL DEFAULT 0 | Last known severity score |
|
||||
| `first_archived_at` | DATETIME | NOT NULL DEFAULT CURRENT_TIMESTAMP | When first archived |
|
||||
| `last_transition_at` | DATETIME | NOT NULL DEFAULT CURRENT_TIMESTAMP | When last state change occurred |
|
||||
| `created_at` | DATETIME | DEFAULT CURRENT_TIMESTAMP | Row creation time |
|
||||
|
||||
**Indexes:**
|
||||
- `idx_archive_finding_id` on `finding_id`
|
||||
- `idx_archive_current_state` on `current_state`
|
||||
|
||||
### `ivanti_archive_transitions` Table
|
||||
|
||||
| Column | Type | Constraints | Description |
|
||||
|--------|------|-------------|-------------|
|
||||
| `id` | INTEGER | PRIMARY KEY AUTOINCREMENT | Row ID |
|
||||
| `archive_id` | INTEGER | NOT NULL, FK → ivanti_finding_archives(id) | Parent archive record |
|
||||
| `from_state` | TEXT | NOT NULL | Previous state (or 'NONE' for initial) |
|
||||
| `to_state` | TEXT | NOT NULL | New state |
|
||||
| `severity_at_transition` | REAL | NOT NULL DEFAULT 0 | Severity score at time of transition |
|
||||
| `reason` | TEXT | NOT NULL DEFAULT '' | Human-readable reason |
|
||||
| `transitioned_at` | DATETIME | NOT NULL DEFAULT CURRENT_TIMESTAMP | When transition occurred |
|
||||
|
||||
**Indexes:**
|
||||
- `idx_transition_archive_id` on `archive_id`
|
||||
|
||||
### State Transition Diagram
|
||||
|
||||
Archive records are only created when a finding first disappears from sync results. Findings that remain present in sync results do not get archive records — they are simply "active" in the findings cache. The three database states are ARCHIVED, RETURNED, and CLOSED.
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> ARCHIVED : Finding disappears from sync (score drift)
|
||||
ARCHIVED --> RETURNED : Reappeared in sync
|
||||
ARCHIVED --> CLOSED : Confirmed remediated in Ivanti
|
||||
RETURNED --> ARCHIVED : Disappeared again
|
||||
RETURNED --> CLOSED : Confirmed remediated in Ivanti
|
||||
```
|
||||
|
||||
### Valid State Transitions
|
||||
|
||||
| From State | To State | Reason |
|
||||
|-----------|----------|--------|
|
||||
| NONE → | ARCHIVED | `severity_score_drift` (first disappearance) |
|
||||
| ARCHIVED → | RETURNED | `reappeared_in_sync` |
|
||||
| ARCHIVED → | CLOSED | `remediated_in_ivanti` |
|
||||
| RETURNED → | ARCHIVED | `severity_score_drift` |
|
||||
| RETURNED → | CLOSED | `remediated_in_ivanti` |
|
||||
|
||||
|
||||
## Correctness Properties
|
||||
|
||||
*A property is a characteristic or behavior that should hold true across all valid executions of a system — essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
|
||||
|
||||
### Property 1: Disappeared findings are archived with complete metadata
|
||||
|
||||
*For any* set of previous findings and current findings, every finding present in the previous set but absent from the current set should have an Archive_Record with state ARCHIVED, and that record should contain the correct finding_id, finding_title, host_name, ip_address, and last_severity matching the original finding's data.
|
||||
|
||||
**Validates: Requirements 1.1, 1.2, 2.2**
|
||||
|
||||
### Property 2: Returned findings transition from ARCHIVED to RETURNED
|
||||
|
||||
*For any* finding that has an Archive_Record with state ARCHIVED, if that finding reappears in the current sync results, the Archive_Record state should be updated to RETURNED and the last_severity should reflect the finding's current severity score.
|
||||
|
||||
**Validates: Requirements 1.3**
|
||||
|
||||
### Property 3: Re-disappeared findings transition from RETURNED to ARCHIVED
|
||||
|
||||
*For any* finding that has an Archive_Record with state RETURNED, if that finding disappears from the current sync results, the Archive_Record state should be updated back to ARCHIVED.
|
||||
|
||||
**Validates: Requirements 1.4**
|
||||
|
||||
### Property 4: Every state transition produces a history record with all required fields
|
||||
|
||||
*For any* state transition on an Archive_Record, a Transition_History row should be inserted containing a valid archive_id, the correct from_state and to_state, a severity_at_transition value, a non-empty reason string, and a transitioned_at timestamp.
|
||||
|
||||
**Validates: Requirements 2.1**
|
||||
|
||||
### Property 5: Closed findings transition to CLOSED state
|
||||
|
||||
*For any* finding that has an Archive_Record with state ARCHIVED or RETURNED, if that finding appears in the Ivanti closed findings set, the Archive_Record state should be updated to CLOSED and the transition reason should be "remediated_in_ivanti".
|
||||
|
||||
**Validates: Requirements 2.3**
|
||||
|
||||
### Property 6: State filter returns only matching records
|
||||
|
||||
*For any* set of Archive_Records with various states, querying the archive list endpoint with a state filter should return only records whose current_state matches the filter, and the count should equal the number of records in that state.
|
||||
|
||||
**Validates: Requirements 4.1**
|
||||
|
||||
### Property 7: Transition history is ordered by timestamp descending
|
||||
|
||||
*For any* finding with multiple Transition_History entries, the history endpoint should return entries ordered by transitioned_at descending, such that each entry's timestamp is greater than or equal to the next entry's timestamp.
|
||||
|
||||
**Validates: Requirements 4.2**
|
||||
|
||||
### Property 8: Stats counts match actual record distribution
|
||||
|
||||
*For any* set of Archive_Records, the stats endpoint should return counts where the sum of all state counts equals the total number of Archive_Records, and each individual state count matches the actual number of records in that state.
|
||||
|
||||
**Validates: Requirements 4.3**
|
||||
|
||||
### Property 9: Migration idempotency
|
||||
|
||||
*For any* number of consecutive executions of the migration script, the resulting database schema should be identical and no errors should occur on subsequent runs.
|
||||
|
||||
**Validates: Requirements 6.2**
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Handling |
|
||||
|----------|----------|
|
||||
| Sync fails (API error, timeout) | Archive detection is skipped entirely for that cycle. No archive records are created or modified. The sync error is logged as usual. |
|
||||
| Database error during archive upsert | Log the error, continue processing remaining findings. Do not abort the entire archive detection pass. |
|
||||
| Database error during transition insert | Log the error. The archive record state may have been updated but the transition history may be incomplete. This is acceptable as the current state is the source of truth. |
|
||||
| Invalid state transition attempted | The detection logic only performs valid transitions per the state diagram. Invalid transitions (e.g., CLOSED → ARCHIVED) are not possible by design since closed findings are excluded from the sync pipeline. |
|
||||
| Missing finding metadata | Use empty string defaults for finding_title, host_name, ip_address if the finding object lacks these fields. Severity defaults to 0. |
|
||||
| Archive API query with invalid state parameter | Return a 400 status code with message "Invalid state parameter. Valid values: ACTIVE, ARCHIVED, RETURNED, CLOSED". Explicit errors surface frontend bugs faster than silent fallbacks. |
|
||||
| History query for non-existent finding | Return 200 with empty transitions array (not 404), per requirement 4.5. |
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests
|
||||
|
||||
Unit tests cover specific examples and edge cases:
|
||||
|
||||
- Migration script creates both tables and all indexes (example, Req 3.1–3.4)
|
||||
- Archive detection skips when sync errors occur (example, Req 1.5)
|
||||
- Unauthenticated requests return 401 (example, Req 4.4)
|
||||
- History endpoint returns empty array for unknown finding (edge case, Req 4.5)
|
||||
- Archive Summary Bar renders four stat cards (example, Req 5.1)
|
||||
- Archive Summary Bar fetches stats on mount (example, Req 5.2)
|
||||
- Clicking a state card triggers filter callback (example, Req 5.3)
|
||||
|
||||
### Property-Based Tests
|
||||
|
||||
Property-based tests use a PBT library (e.g., `fast-check`) to verify universal properties across generated inputs. Each test runs a minimum of 100 iterations.
|
||||
|
||||
| Property | Test Description | Tag |
|
||||
|----------|-----------------|-----|
|
||||
| Property 1 | Generate random previous/current finding sets, run detection, verify all disappeared findings have correct ARCHIVED records | **Feature: finding-archive-tracking, Property 1: Disappeared findings are archived with complete metadata** |
|
||||
| Property 2 | Generate archived findings, add some back to current set, verify RETURNED state | **Feature: finding-archive-tracking, Property 2: Returned findings transition from ARCHIVED to RETURNED** |
|
||||
| Property 3 | Generate returned findings, remove some from current set, verify ARCHIVED state | **Feature: finding-archive-tracking, Property 3: Re-disappeared findings transition from RETURNED to ARCHIVED** |
|
||||
| Property 4 | Generate random state transitions, verify each produces a complete history row | **Feature: finding-archive-tracking, Property 4: Every state transition produces a history record** |
|
||||
| Property 5 | Generate archived/returned findings, mark some as closed, verify CLOSED state and reason | **Feature: finding-archive-tracking, Property 5: Closed findings transition to CLOSED state** |
|
||||
| Property 6 | Generate archive records with random states, query with filter, verify only matching records returned | **Feature: finding-archive-tracking, Property 6: State filter returns only matching records** |
|
||||
| Property 7 | Generate multiple transitions for a finding, query history, verify descending order | **Feature: finding-archive-tracking, Property 7: Transition history is ordered by timestamp descending** |
|
||||
| Property 8 | Generate archive records with random states, query stats, verify counts match | **Feature: finding-archive-tracking, Property 8: Stats counts match actual record distribution** |
|
||||
| Property 9 | Run migration N times, verify no errors and schema is consistent | **Feature: finding-archive-tracking, Property 9: Migration idempotency** |
|
||||
|
||||
### Testing Tools
|
||||
|
||||
- **Test runner**: Jest (via react-scripts for frontend, direct for backend)
|
||||
- **Property-based testing**: `fast-check` library
|
||||
- **Database**: In-memory SQLite (`:memory:`) for isolated test runs
|
||||
- **HTTP testing**: `supertest` for API endpoint tests
|
||||
@@ -1,86 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
The Finding Archive Tracking system extends the Ivanti sync pipeline in the STEAM Security Dashboard to detect and track findings that disappear from sync results due to severity score drift (not remediation). Findings follow a four-state lifecycle (ACTIVE → ARCHIVED → RETURNED → CLOSED) with full transition history, enabling the security team to maintain visibility into findings that fall below the severity threshold and may reappear.
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Sync_Pipeline**: The existing Ivanti/RiskSense host finding sync process that fetches open findings matching BU and severity filters on a daily schedule.
|
||||
- **Finding**: A single host-level vulnerability record identified by a unique `finding_id` from Ivanti/RiskSense.
|
||||
- **Archive_Record**: A database row in the `ivanti_finding_archives` table tracking a finding's current lifecycle state and metadata.
|
||||
- **Transition_History**: A database row in the `ivanti_archive_transitions` table recording a single state change event with timestamps, severity scores, and reason.
|
||||
- **Archive_Detector**: The logic within the sync pipeline that compares previous sync results against current results to identify disappeared and returned findings.
|
||||
- **Archive_Summary_Bar**: A React UI component displaying counts for each lifecycle state (ACTIVE, ARCHIVED, RETURNED, CLOSED) with click-through navigation.
|
||||
- **Archive_API**: The set of three Express route endpoints serving archived finding data, transition history, and summary statistics.
|
||||
- **Lifecycle_State**: One of three database states an archive record can occupy: ARCHIVED (disappeared from sync results due to score drift), RETURNED (reappeared after being archived), CLOSED (remediated in Ivanti). Findings that remain present in sync results have no archive record.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: Archive Detection During Sync
|
||||
|
||||
**User Story:** As a security analyst, I want the system to automatically detect findings that disappear from sync results, so that I can track findings lost due to severity score drift rather than actual remediation.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the Sync_Pipeline completes a sync, THE Archive_Detector SHALL compare the current sync result finding IDs against the previous sync result finding IDs to identify findings that are no longer present.
|
||||
2. WHEN a finding is present in the previous sync but absent from the current sync, THE Archive_Detector SHALL create an Archive_Record with state ARCHIVED, recording the finding metadata, last known severity score, and a timestamp.
|
||||
3. WHEN a finding already has an Archive_Record with state ARCHIVED and the finding reappears in the current sync results, THE Archive_Detector SHALL update the Archive_Record state to RETURNED and record the new severity score.
|
||||
4. WHEN a finding has an Archive_Record with state RETURNED and the finding disappears again from sync results, THE Archive_Detector SHALL update the Archive_Record state to ARCHIVED and record the severity score at time of disappearance.
|
||||
5. IF the Sync_Pipeline encounters a sync error, THEN THE Archive_Detector SHALL skip archive detection for that sync cycle to avoid false positives from incomplete data.
|
||||
|
||||
### Requirement 2: Lifecycle State Transitions
|
||||
|
||||
**User Story:** As a security analyst, I want every state change to be recorded with context, so that I can audit the full history of a finding's lifecycle.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN an Archive_Record changes state, THE Sync_Pipeline SHALL insert a Transition_History row containing the previous state, new state, timestamp, severity score at time of transition, and a reason string.
|
||||
2. THE Archive_Record SHALL store the finding_id, finding_title, host_name, ip_address, current state, last known severity score, initial archive timestamp, and last transition timestamp.
|
||||
3. WHEN a finding is confirmed as remediated (closed) in Ivanti, THE Sync_Pipeline SHALL update the Archive_Record state to CLOSED and record a Transition_History entry with reason "remediated_in_ivanti".
|
||||
4. THE Transition_History SHALL store the archive_record_id, from_state, to_state, transition timestamp, severity_at_transition, and reason.
|
||||
|
||||
### Requirement 3: Database Schema
|
||||
|
||||
**User Story:** As a developer, I want the archive data stored in two normalized SQLite tables, so that the data model supports efficient queries and maintains referential integrity.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Sync_Pipeline SHALL create an `ivanti_finding_archives` table with columns for id, finding_id (unique), finding_title, host_name, ip_address, current_state, last_severity, first_archived_at, last_transition_at, and created_at.
|
||||
2. THE Sync_Pipeline SHALL create an `ivanti_archive_transitions` table with columns for id, archive_id (foreign key to ivanti_finding_archives), from_state, to_state, severity_at_transition, reason, and transitioned_at.
|
||||
3. THE Sync_Pipeline SHALL create indexes on ivanti_finding_archives(finding_id) and ivanti_finding_archives(current_state) for query performance.
|
||||
4. THE Sync_Pipeline SHALL create an index on ivanti_archive_transitions(archive_id) for efficient history lookups.
|
||||
|
||||
### Requirement 4: Archive API Endpoints
|
||||
|
||||
**User Story:** As a frontend developer, I want REST API endpoints to query archived findings, transition history, and summary statistics, so that I can build the archive tracking UI.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a GET request is made to `/api/ivanti/archive`, THE Archive_API SHALL return a list of all Archive_Records with optional filtering by current_state query parameter.
|
||||
2. WHEN a GET request is made to `/api/ivanti/archive/:findingId/history`, THE Archive_API SHALL return the Transition_History entries for the specified finding ordered by transitioned_at descending.
|
||||
3. WHEN a GET request is made to `/api/ivanti/archive/stats`, THE Archive_API SHALL return an object containing the count of Archive_Records in each Lifecycle_State (ACTIVE, ARCHIVED, RETURNED, CLOSED).
|
||||
4. WHEN an unauthenticated request is made to any Archive_API endpoint, THE Archive_API SHALL return a 401 status code.
|
||||
5. WHEN a GET request is made to `/api/ivanti/archive/:findingId/history` with a finding_id that has no Archive_Record, THE Archive_API SHALL return an empty transitions array with a 200 status code.
|
||||
|
||||
### Requirement 5: Archive Summary Bar UI
|
||||
|
||||
**User Story:** As a security analyst, I want a visual summary bar on the Ivanti dashboard showing counts for each archive state, so that I can quickly assess the archive landscape and navigate to details.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Archive_Summary_Bar SHALL display four stat cards showing the count of findings in each Lifecycle_State: ACTIVE, ARCHIVED, RETURNED, and CLOSED.
|
||||
2. WHEN the Archive_Summary_Bar loads, THE Archive_Summary_Bar SHALL fetch data from the `/api/ivanti/archive/stats` endpoint.
|
||||
3. WHEN a user clicks a state card in the Archive_Summary_Bar, THE Archive_Summary_Bar SHALL filter the displayed archive list to show only findings in that state.
|
||||
4. THE Archive_Summary_Bar SHALL use the existing design system colors: sky blue (#0EA5E9) for ACTIVE, amber (#F59E0B) for ARCHIVED, emerald (#10B981) for RETURNED, and red (#EF4444) for CLOSED.
|
||||
5. THE Archive_Summary_Bar SHALL use Lucide icons and monospace typography consistent with the existing dashboard design system.
|
||||
|
||||
### Requirement 6: Migration Script
|
||||
|
||||
**User Story:** As a developer, I want a standalone migration script to create the archive tables, so that the schema can be applied to existing deployments following the established migration pattern.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE migration script SHALL be located at `backend/migrations/add_finding_archive_tables.js` and follow the existing migration pattern of opening the database, running DDL statements in `db.serialize()`, and closing the connection.
|
||||
2. THE migration script SHALL use `CREATE TABLE IF NOT EXISTS` and `CREATE INDEX IF NOT EXISTS` to be idempotent.
|
||||
3. WHEN the migration script is executed, THE migration script SHALL log progress messages for each table and index created.
|
||||
@@ -1,134 +0,0 @@
|
||||
# Implementation Plan: Finding Archive Tracking
|
||||
|
||||
## Overview
|
||||
|
||||
Implement the Finding Archive Tracking system by creating the database migration, archive detection logic within the existing sync pipeline, three API endpoints via a new route module, and an Archive Summary Bar UI component. Each task builds incrementally — schema first, then detection logic, then API, then frontend.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [x] 1. Create database migration and archive tables
|
||||
- [x] 1.1 Create `backend/migrations/add_finding_archive_tables.js` migration script
|
||||
- Create `ivanti_finding_archives` table with columns: id, finding_id (UNIQUE), finding_title, host_name, ip_address, current_state (CHECK constraint for ACTIVE/ARCHIVED/RETURNED/CLOSED), last_severity, first_archived_at, last_transition_at, created_at
|
||||
- Create `ivanti_archive_transitions` table with columns: id, archive_id (FK), from_state, to_state, severity_at_transition, reason, transitioned_at
|
||||
- Create indexes: idx_archive_finding_id, idx_archive_current_state, idx_transition_archive_id
|
||||
- Use `CREATE TABLE IF NOT EXISTS` and `CREATE INDEX IF NOT EXISTS` for idempotency
|
||||
- Follow existing migration pattern: open db, `db.serialize()`, log progress, close db
|
||||
- _Requirements: 3.1, 3.2, 3.3, 3.4, 6.1, 6.2, 6.3_
|
||||
|
||||
- [ ]* 1.2 Write property test for migration idempotency
|
||||
- **Property 9: Migration idempotency**
|
||||
- Run migration logic multiple times against in-memory SQLite, verify no errors and schema is consistent
|
||||
- **Validates: Requirements 6.2**
|
||||
|
||||
- [x] 2. Implement archive detection logic in sync pipeline
|
||||
- [x] 2.1 Add `initArchiveTables(db)` function to `backend/routes/ivantiFindings.js`
|
||||
- Create both archive tables inline (same pattern as existing `initTables`) so they exist on startup
|
||||
- Call from `createIvantiFindingsRouter` during init alongside existing `initTables`
|
||||
- _Requirements: 3.1, 3.2, 3.3, 3.4_
|
||||
|
||||
- [x] 2.2 Implement `detectArchiveChanges(db, previousFindings, currentFindings)` function
|
||||
- Build ID sets from previous and current findings
|
||||
- For disappeared findings (in previous, not in current): upsert archive record with state ARCHIVED, insert transition history
|
||||
- For returned findings (in current, has ARCHIVED record): update to RETURNED, insert transition history
|
||||
- For re-disappeared findings (has RETURNED record, not in current): update to ARCHIVED, insert transition history
|
||||
- Use `db.run` with callbacks wrapped in promises (matching existing `dbRun` helper pattern)
|
||||
- _Requirements: 1.1, 1.2, 1.3, 1.4, 2.1, 2.2_
|
||||
|
||||
- [x] 2.3 Implement `detectClosedFindings(db, closedFindingIds)` function
|
||||
- Query archive records with state ARCHIVED or RETURNED
|
||||
- For any that appear in the closed findings set, update to CLOSED with reason "remediated_in_ivanti"
|
||||
- Insert transition history for each state change
|
||||
- _Requirements: 2.3_
|
||||
|
||||
- [x] 2.4 Integrate archive detection into `syncFindings()` flow
|
||||
- Before updating the cache, read the current findings from `ivanti_findings_cache` as `previousFindings`
|
||||
- After successful cache update, call `detectArchiveChanges(db, previousFindings, currentFindings)`
|
||||
- Skip archive detection if sync encountered an error (requirement 1.5)
|
||||
- Call `detectClosedFindings` during `syncClosedCount` with closed finding IDs
|
||||
- _Requirements: 1.1, 1.5, 2.3_
|
||||
|
||||
- [ ]* 2.5 Write property test for archive detection — disappeared findings
|
||||
- **Property 1: Disappeared findings are archived with complete metadata**
|
||||
- Generate random previous/current finding sets using fast-check, run detectArchiveChanges against in-memory SQLite, verify all disappeared findings have ARCHIVED records with correct metadata
|
||||
- **Validates: Requirements 1.1, 1.2, 2.2**
|
||||
|
||||
- [ ]* 2.6 Write property test for archive detection — returned findings
|
||||
- **Property 2: Returned findings transition from ARCHIVED to RETURNED**
|
||||
- Generate archived findings, add some back to current set, verify RETURNED state and updated severity
|
||||
- **Validates: Requirements 1.3**
|
||||
|
||||
- [ ]* 2.7 Write property test for archive detection — re-disappeared findings
|
||||
- **Property 3: Re-disappeared findings transition from RETURNED to ARCHIVED**
|
||||
- Generate returned findings, remove some from current set, verify ARCHIVED state
|
||||
- **Validates: Requirements 1.4**
|
||||
|
||||
- [ ]* 2.8 Write property test for transition history completeness
|
||||
- **Property 4: Every state transition produces a history record with all required fields**
|
||||
- Generate random state transitions, verify each produces a complete history row with archive_id, from_state, to_state, severity_at_transition, reason, transitioned_at
|
||||
- **Validates: Requirements 2.1**
|
||||
|
||||
- [ ]* 2.9 Write property test for closed finding detection
|
||||
- **Property 5: Closed findings transition to CLOSED state**
|
||||
- Generate archived/returned findings, mark some as closed, verify CLOSED state and reason "remediated_in_ivanti"
|
||||
- **Validates: Requirements 2.3**
|
||||
|
||||
- [x] 3. Checkpoint — Verify archive detection logic
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [x] 4. Implement Archive API endpoints
|
||||
- [x] 4.1 Create `backend/routes/ivantiArchive.js` route module
|
||||
- Export factory function `createIvantiArchiveRouter(db, requireAuth)` returning Express Router
|
||||
- Apply `requireAuth(db)` middleware to all routes
|
||||
- Implement GET `/` — list archive records with optional `?state=` filter, return `{ archives: [...], total: N }`. Return 400 with message "Invalid state parameter. Valid values: ACTIVE, ARCHIVED, RETURNED, CLOSED" if an unrecognized state value is provided.
|
||||
- Implement GET `/stats` — return `{ ACTIVE: N, ARCHIVED: N, RETURNED: N, CLOSED: N, total: N }`
|
||||
- Implement GET `/:findingId/history` — return `{ finding_id, transitions: [...] }` ordered by transitioned_at DESC, return empty array for unknown finding_id
|
||||
- _Requirements: 4.1, 4.2, 4.3, 4.4, 4.5_
|
||||
|
||||
- [x] 4.2 Register archive router in `backend/server.js`
|
||||
- Import `createIvantiArchiveRouter` from `./routes/ivantiArchive`
|
||||
- Mount at `/api/ivanti/archive` with `requireAuth` middleware
|
||||
- _Requirements: 4.1_
|
||||
|
||||
- [ ]* 4.3 Write property test for state filtering
|
||||
- **Property 6: State filter returns only matching records**
|
||||
- Generate archive records with random states, query with filter, verify only matching records returned
|
||||
- **Validates: Requirements 4.1**
|
||||
|
||||
- [ ]* 4.4 Write property test for history ordering
|
||||
- **Property 7: Transition history is ordered by timestamp descending**
|
||||
- Generate multiple transitions for a finding, query history, verify descending timestamp order
|
||||
- **Validates: Requirements 4.2**
|
||||
|
||||
- [ ]* 4.5 Write property test for stats accuracy
|
||||
- **Property 8: Stats counts match actual record distribution**
|
||||
- Generate archive records with random states, query stats, verify counts match actual distribution
|
||||
- **Validates: Requirements 4.3**
|
||||
|
||||
- [x] 5. Checkpoint — Verify API endpoints
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [x] 6. Implement Archive Summary Bar UI component
|
||||
- [x] 6.1 Create `frontend/src/components/pages/ArchiveSummaryBar.js`
|
||||
- Fetch stats from `/api/ivanti/archive/stats` on mount
|
||||
- Render four stat cards: ACTIVE (sky blue #0EA5E9), ARCHIVED (amber #F59E0B), RETURNED (emerald #10B981), CLOSED (red #EF4444)
|
||||
- Each card shows the count and state label with Lucide icons and monospace typography
|
||||
- Accept `onStateClick` callback prop and `activeFilter` prop for highlighting the selected state
|
||||
- Use inline style objects matching the existing design system (dark gradients, glows, hover effects)
|
||||
- _Requirements: 5.1, 5.2, 5.3, 5.4, 5.5_
|
||||
|
||||
- [x] 6.2 Integrate Archive Summary Bar into the Ivanti findings page
|
||||
- Import and render `ArchiveSummaryBar` in the Ivanti findings section of `App.js` (or the relevant page component)
|
||||
- Wire `onStateClick` to manage a state filter for the archive list display
|
||||
- _Requirements: 5.3_
|
||||
|
||||
- [x] 7. Final checkpoint — Verify full integration
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
## Notes
|
||||
|
||||
- Tasks marked with `*` are optional and can be skipped for faster MVP
|
||||
- Each task references specific requirements for traceability
|
||||
- Checkpoints ensure incremental validation
|
||||
- Property tests use `fast-check` library with minimum 100 iterations per test
|
||||
- All backend code uses callback-based SQLite API wrapped in promises (matching existing patterns)
|
||||
- All frontend code uses plain JavaScript (no TypeScript)
|
||||
@@ -1,143 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
Replace the existing simple role-based access control system (admin/editor/viewer) with a group-based access control model. The system supports exactly four user groups (Admin, Standard User, Leadership, Read Only) with distinct permission boundaries. This change affects the database schema, backend middleware, API endpoint authorization, frontend conditional rendering, and the admin panel user management interface.
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Dashboard**: The STEAM Security Dashboard application comprising a React frontend and Express backend
|
||||
- **Group**: One of four access control categories (Admin, Standard_User, Leadership, Read_Only) that determines a user's permissions
|
||||
- **Admin_Group**: The group with full CRUD access to all resources, user management, and admin panel access
|
||||
- **Standard_User_Group**: The working group with view-all, create, edit, and conditional delete permissions plus basic export
|
||||
- **Leadership_Group**: The read-only group with additional export capabilities for reports, compliance documents, and visualizations
|
||||
- **Read_Only_Group**: The view-only group with no create, edit, delete, or export capabilities
|
||||
- **Permission_Middleware**: Backend Express middleware that validates a user's group membership before allowing an API action
|
||||
- **Cascade_Impact**: The set of associated Archer tickets, JIRA tickets, and documents that would be deleted when a CVE is deleted
|
||||
- **Compliance_Link**: An association between a ticket (Archer or JIRA) and a compliance report that blocks Standard_User deletion
|
||||
- **Group_Migration**: The database migration that replaces the role field with a group field and maps existing users
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: Group Data Model
|
||||
|
||||
**User Story:** As a system administrator, I want the user model to reference one of four defined groups instead of the legacy role field, so that permissions are enforced through a well-defined group structure.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL store exactly four groups: Admin, Standard_User, Leadership, and Read_Only
|
||||
2. THE Dashboard SHALL assign each user to exactly one group via a group field on the user record
|
||||
3. WHEN a user record is created, THE Dashboard SHALL default the group to Read_Only
|
||||
4. THE Dashboard SHALL enforce a foreign key or CHECK constraint so that the group field only accepts valid group values
|
||||
|
||||
### Requirement 2: Group Migration
|
||||
|
||||
**User Story:** As a system administrator, I want existing users to be automatically mapped from the old role system to the new group system, so that no manual re-assignment is needed after the upgrade.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the migration runs, THE Group_Migration SHALL map users with role "admin" to Admin_Group
|
||||
2. WHEN the migration runs, THE Group_Migration SHALL map users with role "editor" to Standard_User_Group
|
||||
3. WHEN the migration runs, THE Group_Migration SHALL map users with role "viewer" to Read_Only_Group
|
||||
4. WHEN the migration runs, THE Group_Migration SHALL remove the CHECK constraint on the old role column and replace it with the new group field
|
||||
5. IF a user record has no role value or an unrecognized role value, THEN THE Group_Migration SHALL assign that user to Read_Only_Group
|
||||
|
||||
### Requirement 3: Backend Permission Enforcement
|
||||
|
||||
**User Story:** As a security-conscious developer, I want every API endpoint to check the requesting user's group before allowing the action, so that permissions are enforced server-side and cannot be bypassed through direct API calls.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Permission_Middleware SHALL replace the existing requireRole middleware with a requireGroup middleware that accepts one or more group names
|
||||
2. WHEN an unauthenticated request reaches a protected endpoint, THE Permission_Middleware SHALL return HTTP 401
|
||||
3. WHEN an authenticated user's group is not in the allowed groups for an endpoint, THE Permission_Middleware SHALL return HTTP 403
|
||||
4. THE Permission_Middleware SHALL attach the user's group to the request object for downstream route handlers to use
|
||||
5. WHEN a Standard_User_Group user attempts to delete a resource they did not create, THE Dashboard SHALL return HTTP 403
|
||||
6. WHEN a Standard_User_Group user attempts to delete a finding that is marked as resolved or closed, THE Dashboard SHALL return HTTP 403
|
||||
7. WHEN a Standard_User_Group user attempts to delete a ticket that is linked to a compliance report, THE Dashboard SHALL return HTTP 403
|
||||
8. WHEN a Standard_User_Group user attempts to delete a CVE they created, THE Dashboard SHALL check for Cascade_Impact and return the list of associated Archer tickets, JIRA tickets, and documents
|
||||
9. IF any ticket in the Cascade_Impact is linked to a compliance report, THEN THE Dashboard SHALL block the CVE deletion and return HTTP 403 with a message indicating Admin-only deletion is required
|
||||
10. WHEN an Admin_Group user performs any CRUD operation, THE Dashboard SHALL allow the operation without ownership or state restrictions
|
||||
|
||||
### Requirement 4: Admin Group Permissions
|
||||
|
||||
**User Story:** As an admin, I want full unrestricted access to all resources and management functions, so that I can manage the entire system without limitations.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL allow Admin_Group users to create, read, update, and delete all resources (CVEs, findings, tickets, comments, compliance reports)
|
||||
2. THE Dashboard SHALL allow Admin_Group users to access the admin panel
|
||||
3. THE Dashboard SHALL allow Admin_Group users to manage users and assign users to groups
|
||||
4. THE Dashboard SHALL allow Admin_Group users to export all data
|
||||
5. THE Dashboard SHALL allow Admin_Group users to delete any resource regardless of ownership, state, or compliance linkage
|
||||
|
||||
### Requirement 5: Standard User Group Permissions
|
||||
|
||||
**User Story:** As a standard user, I want to view all data and create/edit resources while having controlled delete access, so that I can do my daily work without accidentally removing critical linked data.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL allow Standard_User_Group users to view all data across the dashboard
|
||||
2. THE Dashboard SHALL allow Standard_User_Group users to create and edit CVEs, findings, tickets, and comments
|
||||
3. THE Dashboard SHALL allow Standard_User_Group users to delete their own findings, tickets, and comments subject to state and linkage restrictions
|
||||
4. WHEN a Standard_User_Group user attempts to delete a finding that is resolved or closed, THE Dashboard SHALL reject the deletion
|
||||
5. WHEN a Standard_User_Group user attempts to delete a ticket linked to a compliance report, THE Dashboard SHALL reject the deletion
|
||||
6. WHEN a Standard_User_Group user attempts to delete a CVE they created, THE Dashboard SHALL display a warning listing associated Archer tickets, JIRA tickets, and documents that will be cascade-deleted
|
||||
7. IF any associated ticket in the cascade is linked to a compliance report, THEN THE Dashboard SHALL block the CVE deletion entirely
|
||||
8. THE Dashboard SHALL allow Standard_User_Group users to perform basic exports (CSV and XLSX of CVEs and findings)
|
||||
|
||||
### Requirement 6: Leadership Group Permissions
|
||||
|
||||
**User Story:** As a leadership user, I want read-only access with export capabilities, so that I can review data and generate reports without risk of modifying records.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL allow Leadership_Group users to view all data across the dashboard
|
||||
2. THE Dashboard SHALL allow Leadership_Group users to export reports, compliance documents, and graph visualizations
|
||||
3. THE Dashboard SHALL prevent Leadership_Group users from creating, editing, or deleting any records
|
||||
4. THE Dashboard SHALL prevent Leadership_Group users from accessing the admin panel
|
||||
|
||||
### Requirement 7: Read Only Group Permissions
|
||||
|
||||
**User Story:** As a read-only user, I want view-only access to the dashboard, so that I can see data without any ability to modify or export it.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL allow Read_Only_Group users to view all data across the dashboard
|
||||
2. THE Dashboard SHALL prevent Read_Only_Group users from creating, editing, or deleting any records
|
||||
3. THE Dashboard SHALL prevent Read_Only_Group users from exporting any data
|
||||
4. THE Dashboard SHALL prevent Read_Only_Group users from accessing the admin panel
|
||||
|
||||
### Requirement 8: Admin Panel Group Management
|
||||
|
||||
**User Story:** As an admin, I want to view all users with their current group and reassign groups through the admin panel, so that I can manage access control centrally.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN an Admin_Group user opens the user management section, THE Dashboard SHALL display all users with their current group assignment
|
||||
2. WHEN an Admin_Group user changes a user's group, THE Dashboard SHALL update the group assignment and persist it to the database
|
||||
3. WHEN an Admin_Group user changes a user's group, THE Dashboard SHALL display a confirmation dialog before applying the change
|
||||
4. WHEN an Admin_Group user downgrades another Admin_Group user, THE Dashboard SHALL display an additional warning in the confirmation dialog
|
||||
5. THE Dashboard SHALL prevent an Admin_Group user from changing their own group to a non-Admin group
|
||||
|
||||
### Requirement 9: Audit Logging for Group Changes
|
||||
|
||||
**User Story:** As a system administrator, I want all group assignment changes to be logged with full context, so that I can audit who changed access for whom and when.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a user's group is changed, THE Dashboard SHALL log the change with the acting user's ID, the target user's ID, the previous group, the new group, and a timestamp
|
||||
2. THE Dashboard SHALL preserve existing audit trail behavior for all CRUD operations performed under the new group system
|
||||
3. WHEN a group change is logged, THE Dashboard SHALL record the IP address of the acting user
|
||||
|
||||
### Requirement 10: Frontend Conditional Rendering
|
||||
|
||||
**User Story:** As a user, I want the UI to show only the actions available to my group, so that I have a clear and uncluttered interface matching my permissions.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL conditionally render create, edit, and delete buttons based on the current user's group
|
||||
2. THE Dashboard SHALL conditionally render export options based on the current user's group
|
||||
3. THE Dashboard SHALL conditionally render the admin panel link based on the current user's group
|
||||
4. WHEN a Standard_User_Group user views a resource they did not create, THE Dashboard SHALL hide the delete button for that resource
|
||||
5. THE Dashboard SHALL replace the existing role-based helper functions (hasRole, canWrite, isAdmin) with group-based equivalents (isInGroup, canWrite, canDelete, canExport, isAdmin)
|
||||
@@ -1,279 +0,0 @@
|
||||
# Implementation Plan: Group-Based Access Control
|
||||
|
||||
## Overview
|
||||
|
||||
Replace the existing role-based access control (admin/editor/viewer) with a four-group model (Admin, Standard_User, Leadership, Read_Only). This touches the database schema, backend middleware, all route authorization, frontend permission helpers, and the admin panel UI. Tasks build incrementally: migration first, then middleware, then routes, then frontend.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [ ] 1. Create database migration for user groups
|
||||
- [x] 1.1 Create `backend/migrations/add_user_groups.js` migration script
|
||||
- Add `user_group` column (VARCHAR(20), NOT NULL, DEFAULT 'Read_Only') to users table
|
||||
- Map existing role values: admin to Admin, editor to Standard_User, viewer to Read_Only
|
||||
- Map NULL or unrecognized role values to Read_Only
|
||||
- Add CHECK constraint: user_group IN ('Admin', 'Standard_User', 'Leadership', 'Read_Only')
|
||||
- Add index `idx_users_user_group` on user_group column
|
||||
- Use idempotent checks so migration is safe to run multiple times
|
||||
- Follow existing migration pattern: open db, db.serialize(), log progress, close db
|
||||
- _Requirements: 1.1, 1.2, 1.3, 1.4, 2.1, 2.2, 2.3, 2.4, 2.5_
|
||||
|
||||
- [ ]* 1.2 Write property test for migration role mapping
|
||||
- **Property 8: Migration maps all role values correctly**
|
||||
- Generate users with random roles from {admin, editor, viewer, NULL, arbitrary}, run migration against in-memory SQLite, verify mapping
|
||||
- **Validates: Requirements 2.1, 2.2, 2.3, 2.5**
|
||||
|
||||
- [ ]* 1.3 Write property test for migration idempotency
|
||||
- **Property 9: Migration is idempotent**
|
||||
- Run migration N times (N in 1-5) against in-memory SQLite, verify schema and data identical each time
|
||||
- **Validates: Requirements 2.4**
|
||||
|
||||
- [ ] 1.4 Write unit tests for migration
|
||||
- Test column creation with correct CHECK constraint
|
||||
- Test role mapping: admin to Admin, editor to Standard_User, viewer to Read_Only
|
||||
- Test NULL and unrecognized role handling defaults to Read_Only
|
||||
- Test new user defaults to Read_Only group
|
||||
- _Requirements: 1.3, 1.4, 2.1, 2.2, 2.3, 2.5_
|
||||
|
||||
- [ ] 2. Update auth middleware to use groups
|
||||
- [x] 2.1 Update `requireAuth` in `backend/middleware/auth.js`
|
||||
- Modify session join query to SELECT user_group and attach as req.user.group
|
||||
- _Requirements: 3.4_
|
||||
|
||||
- [x] 2.2 Add `requireGroup` middleware function
|
||||
- Accept spread of allowed group names
|
||||
- Return 401 if req.user is missing
|
||||
- Return 403 with error details if user group not in allowed set
|
||||
- Call next() if group is allowed
|
||||
- _Requirements: 3.1, 3.2, 3.3_
|
||||
|
||||
- [x] 2.3 Remove `requireRole` and export `requireGroup`
|
||||
- Remove requireRole function and its export
|
||||
- Export requireGroup in its place
|
||||
- _Requirements: 3.1_
|
||||
|
||||
- [ ]* 2.4 Write property test for group constraint
|
||||
- **Property 1: Group constraint rejects invalid values**
|
||||
- Generate random strings not in valid group set, attempt DB insert, verify constraint error
|
||||
- **Validates: Requirements 1.1, 1.4**
|
||||
|
||||
- [ ]* 2.5 Write property test for requireGroup
|
||||
- **Property 3: requireGroup rejects unauthorized groups**
|
||||
- Generate random group and allowedGroups pairs where group is not in allowed set, verify 403
|
||||
- **Validates: Requirements 3.3**
|
||||
|
||||
- [ ] 2.6 Write unit tests for requireGroup middleware
|
||||
- Test 401 for unauthenticated requests
|
||||
- Test 403 for wrong group
|
||||
- Test group attached to req.user
|
||||
- Test next() called for allowed group
|
||||
- _Requirements: 3.2, 3.3, 3.4_
|
||||
|
||||
- [x] 3. Checkpoint: Verify migration and middleware
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [ ] 4. Update auth routes to return group
|
||||
- [x] 4.1 Update login endpoint in `backend/routes/auth.js`
|
||||
- Return group (from user_group) instead of role in user response object
|
||||
- Update audit log details to log group instead of role
|
||||
- _Requirements: 3.4, 9.2_
|
||||
|
||||
- [x] 4.2 Update me endpoint in `backend/routes/auth.js`
|
||||
- Return group instead of role in user response object
|
||||
- _Requirements: 3.4_
|
||||
|
||||
- [ ] 5. Update user management routes
|
||||
- [x] 5.1 Switch `backend/routes/users.js` to use requireGroup
|
||||
- Replace requireRole('admin') with requireGroup('Admin')
|
||||
- _Requirements: 4.2, 4.3_
|
||||
|
||||
- [x] 5.2 Update GET endpoints to return user_group
|
||||
- Return user_group instead of role in user records
|
||||
- _Requirements: 8.1_
|
||||
|
||||
- [x] 5.3 Update POST create user to accept group param
|
||||
- Validate group against valid values
|
||||
- Default to Read_Only if not provided
|
||||
- Return 400 for invalid group values
|
||||
- _Requirements: 1.3, 8.2_
|
||||
|
||||
- [x] 5.4 Update PATCH update user to accept group param
|
||||
- Validate group against valid values
|
||||
- Prevent admin self-demotion (return 400)
|
||||
- _Requirements: 8.2, 8.5_
|
||||
|
||||
- [x] 5.5 Add audit logging for group changes
|
||||
- Log acting user ID, target user ID, previous group, new group, IP address, timestamp
|
||||
- _Requirements: 9.1, 9.3_
|
||||
|
||||
- [ ]* 5.6 Write property test for user group validity
|
||||
- **Property 2: Every user has exactly one valid group**
|
||||
- Generate random user sets, query all users, verify each has exactly one valid group
|
||||
- **Validates: Requirements 1.2**
|
||||
|
||||
- [ ] 5.7 Write unit tests for user management group logic
|
||||
- Test group validation rejects invalid values
|
||||
- Test self-demotion prevention
|
||||
- Test audit logging includes all required fields
|
||||
- _Requirements: 8.2, 8.5, 9.1, 9.3_
|
||||
|
||||
- [ ] 6. Update backend route authorization across all routes
|
||||
- [x] 6.1 Update `backend/routes/auditLog.js`
|
||||
- Replace requireRole('admin') with requireGroup('Admin')
|
||||
- _Requirements: 4.2_
|
||||
|
||||
- [x] 6.2 Update `backend/routes/archerTickets.js`
|
||||
- Use requireGroup('Admin', 'Standard_User') for create, update, delete
|
||||
- _Requirements: 5.2_
|
||||
|
||||
- [x] 6.3 Update `backend/routes/knowledgeBase.js`
|
||||
- Use requireGroup('Admin', 'Standard_User') for upload and delete
|
||||
- _Requirements: 5.2_
|
||||
|
||||
- [x] 6.4 Update `backend/routes/ivantiFindings.js`
|
||||
- Use requireGroup('Admin', 'Standard_User') for override endpoint
|
||||
- _Requirements: 5.2_
|
||||
|
||||
- [x] 6.5 Update `backend/routes/compliance.js`
|
||||
- Use requireGroup('Admin', 'Standard_User') for preview and commit
|
||||
- _Requirements: 5.2_
|
||||
|
||||
- [x] 6.6 Update `backend/server.js` inline CVE routes
|
||||
- Use requireGroup('Admin', 'Standard_User') for POST, PUT, PATCH, DELETE
|
||||
- _Requirements: 5.2_
|
||||
|
||||
- [x] 6.7 Update `backend/server.js` route mounting
|
||||
- Pass requireGroup instead of requireRole to route factories
|
||||
- _Requirements: 3.1_
|
||||
|
||||
- [ ]* 6.8 Write property test for Leadership restrictions
|
||||
- **Property 5: Leadership cannot mutate any resource**
|
||||
- Generate random mutation requests as Leadership, verify 403
|
||||
- **Validates: Requirements 6.3**
|
||||
|
||||
- [ ]* 6.9 Write property test for Read_Only restrictions
|
||||
- **Property 6: Read_Only cannot mutate or export**
|
||||
- Generate random mutation and export requests as Read_Only, verify 403
|
||||
- **Validates: Requirements 7.2, 7.3**
|
||||
|
||||
- [x] 7. Checkpoint: Verify backend route authorization
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [ ] 8. Implement Standard User conditional delete logic
|
||||
- [x] 8.1 Add created_by column tracking
|
||||
- Add created_by to CVE, finding, and ticket creation endpoints storing req.user.id on insert
|
||||
- _Requirements: 3.5_
|
||||
|
||||
- [x] 8.2 Implement ownership check for CVE delete
|
||||
- Standard_User can only delete CVEs they created
|
||||
- Return 403 if not owner
|
||||
- _Requirements: 3.5_
|
||||
|
||||
- [x] 8.3 Implement cascade impact check for CVE delete
|
||||
- Query associated Archer tickets and documents
|
||||
- Check compliance linkage on cascaded tickets
|
||||
- Return cascade_impact response schema
|
||||
- Block deletion if any cascaded ticket is compliance-linked
|
||||
- _Requirements: 3.8, 3.9_
|
||||
|
||||
- [x] 8.4 Implement state check for finding delete
|
||||
- Standard_User cannot delete resolved or closed findings
|
||||
- Return 403 with appropriate error message
|
||||
- _Requirements: 3.6_
|
||||
|
||||
- [x] 8.5 Implement compliance linkage check for ticket delete
|
||||
- Standard_User cannot delete tickets linked to compliance reports
|
||||
- Return 403 with appropriate error message
|
||||
- _Requirements: 3.7_
|
||||
|
||||
- [x] 8.6 Ensure Admin bypasses all delete restrictions
|
||||
- Admin group skips ownership, state, and compliance checks
|
||||
- _Requirements: 3.10, 4.5_
|
||||
|
||||
- [ ]* 8.7 Write property test for Admin delete bypass
|
||||
- **Property 4: Admin bypasses all delete restrictions**
|
||||
- Generate resources with random ownership, state, compliance linkage, delete as Admin, verify success
|
||||
- **Validates: Requirements 3.10, 4.1, 4.5**
|
||||
|
||||
- [ ] 8.8 Write unit tests for conditional delete logic
|
||||
- Test ownership rejection for non-owner
|
||||
- Test state rejection for resolved/closed findings
|
||||
- Test compliance linkage rejection
|
||||
- Test cascade impact response format
|
||||
- Test Admin bypass of all restrictions
|
||||
- _Requirements: 3.5, 3.6, 3.7, 3.8, 3.9, 3.10_
|
||||
|
||||
- [x] 9. Checkpoint: Verify conditional delete logic
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [ ] 10. Update frontend AuthContext with group helpers
|
||||
- [x] 10.1 Update `frontend/src/contexts/AuthContext.js`
|
||||
- Read group from user object instead of role
|
||||
- Replace hasRole with isInGroup(...groups) helper
|
||||
- Update canWrite to check isInGroup('Admin', 'Standard_User')
|
||||
- Add canDelete(resource) helper: Admin always true, Standard_User only if owns resource, others false
|
||||
- Add canExport() helper: true for Admin, Standard_User, Leadership
|
||||
- Update isAdmin() to check isInGroup('Admin')
|
||||
- _Requirements: 10.1, 10.2, 10.3, 10.4, 10.5_
|
||||
|
||||
- [ ]* 10.2 Write property test for permission helpers
|
||||
- **Property 7: Group permission helpers are consistent with group matrix**
|
||||
- Generate all valid group values, call each helper, verify against permission matrix
|
||||
- **Validates: Requirements 10.5**
|
||||
|
||||
- [ ] 11. Update frontend UI for group-based rendering
|
||||
- [x] 11.1 Update `App.js` conditional rendering
|
||||
- Use canWrite, canDelete, canExport, isAdmin for button and link visibility
|
||||
- _Requirements: 10.1, 10.2, 10.3_
|
||||
|
||||
- [x] 11.2 Update `NavDrawer.js`
|
||||
- Show admin panel link only when isAdmin() is true
|
||||
- _Requirements: 10.3_
|
||||
|
||||
- [x] 11.3 Update `UserMenu.js`
|
||||
- Display user group instead of role
|
||||
- _Requirements: 10.1_
|
||||
|
||||
- [x] 11.4 Update all components using hasRole or canWrite
|
||||
- Replace with new group-based helpers throughout components
|
||||
- _Requirements: 10.5_
|
||||
|
||||
- [x] 11.5 Hide delete buttons for non-owned resources
|
||||
- Standard_User sees delete only on resources they created
|
||||
- _Requirements: 10.4_
|
||||
|
||||
- [ ] 12. Update User Management UI
|
||||
- [x] 12.1 Replace role dropdown with group dropdown in `UserManagement.js`
|
||||
- Options: Admin, Standard_User, Leadership, Read_Only
|
||||
- _Requirements: 8.1, 8.2_
|
||||
|
||||
- [x] 12.2 Update form data and API calls to use group field
|
||||
- Send group instead of role in create and update requests
|
||||
- _Requirements: 8.2_
|
||||
|
||||
- [x] 12.3 Add confirmation dialog for group changes
|
||||
- Show confirmation before applying any group change
|
||||
- _Requirements: 8.3_
|
||||
|
||||
- [x] 12.4 Add extra warning when downgrading Admin
|
||||
- Show additional warning in confirmation dialog
|
||||
- _Requirements: 8.4_
|
||||
|
||||
- [x] 12.5 Prevent admin self-demotion in UI
|
||||
- Disable group change dropdown for current user if Admin
|
||||
- _Requirements: 8.5_
|
||||
|
||||
- [x] 12.6 Update user table to show group badges
|
||||
- Display group badge with appropriate colors instead of role badge
|
||||
- _Requirements: 8.1_
|
||||
|
||||
- [x] 13. Final checkpoint: Verify full integration
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
## Notes
|
||||
|
||||
- Tasks marked with `*` are optional and can be skipped for faster MVP
|
||||
- Each task references specific requirements for traceability
|
||||
- Checkpoints ensure incremental validation
|
||||
- Property tests use `fast-check` library with minimum 100 iterations per test
|
||||
- All backend code uses callback-based SQLite API wrapped in promises (matching existing patterns)
|
||||
- All frontend code uses plain JavaScript (no TypeScript)
|
||||
@@ -1,321 +0,0 @@
|
||||
# Design Document: Ivanti FP Workflow Submission
|
||||
|
||||
## Overview
|
||||
|
||||
This feature extends the existing Ivanti Queue (QueuePanel) in the Reporting Page to allow users to submit False Positive (FP) workflows directly to the Ivanti/RiskSense API. The implementation adds a submission modal triggered from the queue panel, a backend API endpoint that proxies the workflow creation and attachment upload to Ivanti, and local tracking of submissions in SQLite.
|
||||
|
||||
The design follows existing codebase conventions: factory-pattern Express routes, inline React styles with the dark tactical theme, Multer for file uploads, and the `ivantiPost()` HTTP helper for Ivanti API calls.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant U as User (Browser)
|
||||
participant FE as React Frontend
|
||||
participant BE as Express Backend
|
||||
participant IV as Ivanti API
|
||||
participant DB as SQLite
|
||||
|
||||
U->>FE: Select FP queue items, click "Create FP Workflow"
|
||||
FE->>FE: Open FpWorkflowModal with selected items
|
||||
U->>FE: Fill form, attach files, click Submit
|
||||
FE->>BE: POST /api/ivanti/fp-workflow (multipart/form-data)
|
||||
BE->>BE: Validate input, check auth
|
||||
BE->>IV: POST /client/{clientId}/workflowBatch (create FP workflow)
|
||||
IV-->>BE: 200 + workflow batch response (id, generatedId)
|
||||
alt Attachments present
|
||||
loop For each attachment
|
||||
BE->>IV: POST /client/{clientId}/workflowBatch/{id}/attachment
|
||||
IV-->>BE: 200 OK
|
||||
end
|
||||
end
|
||||
BE->>DB: INSERT into ivanti_fp_submissions
|
||||
BE->>DB: INSERT audit log entry
|
||||
BE->>DB: UPDATE ivanti_todo_queue SET status='complete'
|
||||
BE-->>FE: 200 + { workflowBatchId, generatedId, status }
|
||||
FE->>FE: Show success, refresh queue panel
|
||||
```
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### Backend
|
||||
|
||||
#### New Route Module: `backend/routes/ivantiFpWorkflow.js`
|
||||
|
||||
Exports `createIvantiFpWorkflowRouter(db, requireAuth)` following the existing factory pattern.
|
||||
|
||||
**Endpoint: `POST /api/ivanti/fp-workflow`**
|
||||
|
||||
- Auth: `requireAuth(db)`, `requireGroup('Admin', 'Standard_User')`
|
||||
- Content-Type: `multipart/form-data` (handled by Multer)
|
||||
- Request fields:
|
||||
- `name` (string, required) — workflow name, max 255 chars
|
||||
- `reason` (string, required) — justification text
|
||||
- `description` (string, optional) — additional details, max 2000 chars
|
||||
- `expirationDate` (string, required) — ISO date string, must be future
|
||||
- `scopeOverride` (string, optional) — "Authorized" (default) or "None"
|
||||
- `findingIds` (string, required) — JSON-encoded array of finding ID strings
|
||||
- `queueItemIds` (string, required) — JSON-encoded array of local queue item IDs
|
||||
- `attachments` (files, optional) — up to 10 files, 10MB each
|
||||
|
||||
- Response (success):
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"workflowBatchId": 12345,
|
||||
"generatedId": "FP#12345",
|
||||
"attachmentResults": [
|
||||
{ "filename": "evidence.pdf", "success": true },
|
||||
{ "filename": "screenshot.png", "success": true }
|
||||
],
|
||||
"queueItemsUpdated": 3
|
||||
}
|
||||
```
|
||||
|
||||
- Response (error):
|
||||
```json
|
||||
{
|
||||
"success": false,
|
||||
"error": "Ivanti API returned status 401",
|
||||
"step": "create_workflow",
|
||||
"details": "..."
|
||||
}
|
||||
```
|
||||
|
||||
**Internal flow:**
|
||||
|
||||
1. Parse and validate all form fields
|
||||
2. Verify all `queueItemIds` belong to the requesting user and are FP-type with pending status
|
||||
3. Call Ivanti API to create the workflow batch
|
||||
4. If attachments exist, upload each to the created workflow batch
|
||||
5. Insert a submission record into `ivanti_fp_submissions`
|
||||
6. Log audit entry via `logAudit()`
|
||||
7. Mark queue items as complete
|
||||
8. Return combined result
|
||||
|
||||
#### Ivanti API Calls
|
||||
|
||||
Reuses the existing `ivantiPost()` helper pattern from `ivantiWorkflows.js`. Adds a new `ivantiMultipartPost()` helper for attachment uploads that sends `multipart/form-data` instead of JSON.
|
||||
|
||||
**Create Workflow Batch:**
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch
|
||||
```
|
||||
```json
|
||||
{
|
||||
"name": "FP - CVE-2024-1234 - Vendor X",
|
||||
"type": "FALSE_POSITIVE",
|
||||
"reason": "Scanner false positive confirmed by manual investigation",
|
||||
"description": "Additional context...",
|
||||
"expirationDate": "2025-12-31",
|
||||
"scopeOverrideAuthorization": "AUTHORIZED",
|
||||
"hostFindingIds": [123456, 789012],
|
||||
"subType": "FALSE_POSITIVE"
|
||||
}
|
||||
```
|
||||
|
||||
**Upload Attachment:**
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/{workflowBatchId}/attachment
|
||||
Content-Type: multipart/form-data
|
||||
```
|
||||
Form field: `file` — the binary file content.
|
||||
|
||||
#### Shared HTTP Helpers
|
||||
|
||||
The existing `ivantiPost()` function is duplicated across `ivantiWorkflows.js` and `ivantiFindings.js`. This design extracts it into a shared helper at `backend/helpers/ivantiApi.js` alongside the new multipart helper:
|
||||
|
||||
- `ivantiPost(urlPath, body, apiKey, skipTls)` — JSON POST (existing logic)
|
||||
- `ivantiMultipartPost(urlPath, fileBuffer, fileName, apiKey, skipTls)` — multipart file upload
|
||||
|
||||
### Frontend
|
||||
|
||||
#### New Component: `FpWorkflowModal`
|
||||
|
||||
Located in `frontend/src/components/pages/ReportingPage.js` (inline, following the existing pattern where QueuePanel and AddToQueuePopover are defined in the same file).
|
||||
|
||||
**Props:**
|
||||
- `open` (boolean) — controls visibility
|
||||
- `onClose` (function) — close handler
|
||||
- `selectedItems` (array) — FP queue items selected for submission
|
||||
- `onSuccess` (function) — callback after successful submission, triggers queue refresh
|
||||
|
||||
**State:**
|
||||
- `name`, `reason`, `description`, `expirationDate`, `scopeOverride` — form fields
|
||||
- `files` — array of File objects for upload
|
||||
- `submitting` — boolean, disables form during submission
|
||||
- `progress` — object tracking current step and attachment progress
|
||||
- `errors` — validation error map
|
||||
- `result` — submission result (success/failure details)
|
||||
|
||||
**UI Layout:**
|
||||
- Modal overlay with dark backdrop (matching existing modal patterns)
|
||||
- Header: "Create FP Workflow" with close button
|
||||
- Body sections:
|
||||
1. Selected findings summary (read-only list with finding_id, title, CVEs)
|
||||
2. Workflow configuration form (name, reason, description, expiration, scope override toggle)
|
||||
3. File upload area (drag-and-drop zone + file list)
|
||||
- Footer: Cancel and Submit buttons, progress indicator when submitting
|
||||
|
||||
#### QueuePanel Modifications
|
||||
|
||||
- Add a "Create FP Workflow" button in the footer, next to existing "Delete Selected" and "Clear Completed" buttons
|
||||
- Button enabled only when `selectedIds` contains at least one pending FP-type item
|
||||
- Clicking opens `FpWorkflowModal` with the filtered FP items
|
||||
- After successful submission, the `onSuccess` callback triggers queue refresh
|
||||
|
||||
## Data Models
|
||||
|
||||
### New Table: `ivanti_fp_submissions`
|
||||
|
||||
```sql
|
||||
CREATE TABLE IF NOT EXISTS ivanti_fp_submissions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
ivanti_workflow_batch_id INTEGER,
|
||||
ivanti_generated_id TEXT,
|
||||
workflow_name TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
description TEXT,
|
||||
expiration_date TEXT NOT NULL,
|
||||
scope_override TEXT NOT NULL DEFAULT 'Authorized',
|
||||
finding_ids_json TEXT NOT NULL,
|
||||
queue_item_ids_json TEXT NOT NULL,
|
||||
attachment_count INTEGER DEFAULT 0,
|
||||
attachment_results_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'success' CHECK(status IN ('success', 'partial', 'failed')),
|
||||
error_message TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fp_submissions_user ON ivanti_fp_submissions(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_fp_submissions_ivanti_id ON ivanti_fp_submissions(ivanti_generated_id);
|
||||
```
|
||||
|
||||
**Status values:**
|
||||
- `success` — workflow created and all attachments uploaded
|
||||
- `partial` — workflow created but one or more attachments failed
|
||||
- `failed` — workflow creation itself failed (record kept for audit)
|
||||
|
||||
### Migration Script: `backend/migrations/add_fp_submissions_table.js`
|
||||
|
||||
Standard migration script following the existing pattern (e.g., `add_ivanti_todo_queue_table.js`).
|
||||
|
||||
|
||||
## Correctness Properties
|
||||
|
||||
*A property is a characteristic or behavior that should hold true across all valid executions of a system — essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
|
||||
|
||||
### Property 1: FP Workflow Button Enabled State
|
||||
|
||||
*For any* set of queue items and any selection of item IDs, the "Create FP Workflow" button should be enabled if and only if the selection contains at least one queue item that has `workflow_type === 'FP'` and `status === 'pending'`.
|
||||
|
||||
**Validates: Requirements 1.1**
|
||||
|
||||
### Property 2: FP-Only Item Filtering
|
||||
|
||||
*For any* set of selected queue items containing a mix of workflow types (FP, Archer, CARD), the items passed to the FP workflow submission modal should contain only items where `workflow_type === 'FP'`, and the count of filtered items should be less than or equal to the count of selected items.
|
||||
|
||||
**Validates: Requirements 1.2**
|
||||
|
||||
### Property 3: Form Validation Correctness
|
||||
|
||||
*For any* form state (name, reason, description, expirationDate, scopeOverride), validation should pass if and only if: name is a non-empty string of at most 255 characters, reason is a non-empty string, description (if provided) is at most 2000 characters, and expirationDate is a valid date strictly after today. When validation fails, the returned error map should contain a key for each invalid field and no keys for valid fields.
|
||||
|
||||
**Validates: Requirements 2.4, 2.5**
|
||||
|
||||
### Property 4: File Extension Validation
|
||||
|
||||
*For any* filename string, the file acceptance function should return true if and only if the file's extension (case-insensitive) is one of: .pdf, .png, .jpg, .jpeg, .gif, .doc, .docx, .xlsx, .csv, .txt, .zip. Files with disallowed extensions should be rejected.
|
||||
|
||||
**Validates: Requirements 3.3**
|
||||
|
||||
### Property 5: API Payload Construction
|
||||
|
||||
*For any* valid form input (name, reason, description, expirationDate, scopeOverride, findingIds), the constructed Ivanti API request body should contain: `type` equal to "FALSE_POSITIVE", `name` equal to the input name, `reason` equal to the input reason, `expirationDate` equal to the input date, `scopeOverrideAuthorization` mapped from the input scopeOverride value, and `hostFindingIds` equal to the input finding IDs parsed as integers.
|
||||
|
||||
**Validates: Requirements 4.1**
|
||||
|
||||
### Property 6: Queue Items Marked Complete on Success
|
||||
|
||||
*For any* set of queue item IDs associated with a successful FP workflow submission, after the post-submission handler runs, all those queue items should have `status === 'complete'`.
|
||||
|
||||
**Validates: Requirements 5.1**
|
||||
|
||||
### Property 7: Post-Submission Persistence Completeness
|
||||
|
||||
*For any* successful FP workflow submission with a given workflow batch ID, name, user ID, and finding IDs, the resulting submission record should contain all of: ivanti_workflow_batch_id, workflow_name, user_id, finding_ids_json (parseable to the original finding IDs array), and a non-null created_at timestamp. Additionally, the audit log entry should have action "ivanti_fp_workflow_created", entity_type "ivanti_workflow", and details containing the workflow name and finding IDs.
|
||||
|
||||
**Validates: Requirements 6.1, 6.2**
|
||||
|
||||
### Property 8: Role-Based UI Visibility
|
||||
|
||||
*For any* user role, the "Create FP Workflow" button should be visible if and only if the user's role is "editor" or "admin". Users with the "viewer" role should not see the button.
|
||||
|
||||
**Validates: Requirements 7.2**
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Ivanti API Errors
|
||||
|
||||
| HTTP Status | Error Type | User-Facing Message | System Behavior |
|
||||
|-------------|-----------|---------------------|-----------------|
|
||||
| 401 | Auth failure | "Ivanti API key is invalid or missing. Contact your administrator." | Log error, preserve form state |
|
||||
| 419 | Insufficient privileges | "API key lacks workflow creation permissions." | Log error, preserve form state |
|
||||
| 429 | Rate limited | "Ivanti API rate limit reached. Please try again in a few minutes." | Log error, preserve form state |
|
||||
| 5xx | Server error | "Ivanti API is temporarily unavailable. Please try again later." | Log error, preserve form state |
|
||||
| Other | Unknown | "Workflow creation failed: {status} — {message}" | Log error with full response, preserve form state |
|
||||
|
||||
### Partial Failure (Attachment Upload)
|
||||
|
||||
When the workflow batch is created successfully but one or more attachment uploads fail:
|
||||
- The submission record is saved with `status = 'partial'`
|
||||
- The response includes the workflow batch ID and per-attachment success/failure details
|
||||
- The UI shows which attachments failed and allows retry
|
||||
- The queue items are still marked complete (the workflow itself was created)
|
||||
|
||||
### Local Database Errors
|
||||
|
||||
- If the submission record INSERT fails: log error, still return success to user (Ivanti workflow was created)
|
||||
- If queue item status UPDATE fails: return success with a warning that local queue state may be stale
|
||||
- If audit log INSERT fails: fire-and-forget (existing pattern from `logAudit()`)
|
||||
|
||||
### Input Validation Errors
|
||||
|
||||
- All validation errors return 400 with a structured error object mapping field names to error messages
|
||||
- Frontend validates before sending to prevent unnecessary API calls
|
||||
- Backend re-validates all inputs as a security measure
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Property-Based Testing
|
||||
|
||||
Use `fast-check` as the property-based testing library for JavaScript.
|
||||
|
||||
Each correctness property maps to a single property-based test with a minimum of 100 iterations. Tests are tagged with the format: **Feature: ivanti-fp-workflow-submission, Property {number}: {title}**.
|
||||
|
||||
Property tests focus on pure functions extracted from the implementation:
|
||||
- `isCreateFpButtonEnabled(items, selectedIds)` — Property 1
|
||||
- `filterFpItems(items)` — Property 2
|
||||
- `validateFpWorkflowForm(formData)` — Property 3
|
||||
- `isAllowedFileExtension(filename)` — Property 4
|
||||
- `buildIvantiPayload(formData, findingIds)` — Property 5
|
||||
- Queue item status update logic — Property 6
|
||||
- Submission record creation — Property 7
|
||||
- Role-based visibility check — Property 8
|
||||
|
||||
### Unit Testing
|
||||
|
||||
Unit tests complement property tests by covering:
|
||||
- Specific examples: known-good form submissions, known-bad inputs
|
||||
- Edge cases: empty finding lists, maximum file size boundary, expiration date exactly tomorrow
|
||||
- Error code mapping: verify each Ivanti HTTP status maps to the correct error message
|
||||
- Integration points: Multer file handling, multipart form construction
|
||||
- API response parsing: various Ivanti response formats
|
||||
|
||||
### Test File Locations
|
||||
|
||||
- `backend/__tests__/ivantiFpWorkflow.test.js` — backend route handler tests, validation, payload construction
|
||||
- `backend/__tests__/ivantiFpWorkflow.property.test.js` — property-based tests for backend logic
|
||||
- `frontend/src/__tests__/fpWorkflowModal.test.js` — frontend component and validation tests
|
||||
@@ -1,99 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
This feature adds the ability for users to select items from the Ivanti Queue (QueuePanel) and submit False Positive (FP) workflows directly to the Ivanti/RiskSense API. Users can configure the FP workflow with a name, reason, description, expiration date, and the "Authorized" scope override option. Supporting documentation and artifacts can be uploaded and attached to the workflow via the API. Successful submissions mark the corresponding queue items as complete and are tracked locally with full audit logging.
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Dashboard**: The STEAM Security Dashboard application
|
||||
- **Queue_Panel**: The slide-out panel in the Reporting Page that displays the user's Ivanti todo queue items grouped by vendor/CARD
|
||||
- **Queue_Item**: A single entry in the ivanti_todo_queue table representing a host finding staged for workflow processing, with fields including finding_id, finding_title, cves_json, ip_address, vendor, workflow_type, and status
|
||||
- **FP_Workflow**: A False Positive workflow batch created in the Ivanti/RiskSense platform to mark host findings as false positives, removing them from risk calculations
|
||||
- **Ivanti_API**: The Ivanti/RiskSense REST API at https://platform4.risksense.com/api/v1, authenticated via x-api-key header
|
||||
- **Workflow_Batch**: An Ivanti API resource representing a group of findings submitted together under a single workflow request
|
||||
- **Scope_Override_Authorization**: An Ivanti workflow property that controls whether additional findings can be added to or removed from the workflow after creation; values are "None" or "Authorized"
|
||||
- **Submission_Record**: A local database record tracking the details and outcome of an FP workflow submission made through the Dashboard
|
||||
- **Attachment**: A supporting document or artifact (PDF, screenshot, etc.) uploaded alongside an FP workflow submission as evidence or justification
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: Select FP Queue Items for Workflow Submission
|
||||
|
||||
**User Story:** As an editor or admin, I want to select one or more FP-type items from the Ivanti Queue, so that I can batch them into a single False Positive workflow submission.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the Queue_Panel is open and contains FP-type Queue_Items, THE Dashboard SHALL display a "Create FP Workflow" action button that is enabled only when at least one pending FP-type Queue_Item is selected
|
||||
2. WHEN a user selects Queue_Items of mixed workflow_type (FP and non-FP), THE Dashboard SHALL only include FP-type Queue_Items in the FP workflow submission and SHALL visually indicate which items are eligible
|
||||
3. IF no pending FP-type Queue_Items are selected, THEN THE Dashboard SHALL disable the "Create FP Workflow" action button and display a tooltip explaining the requirement
|
||||
4. WHEN the "Create FP Workflow" button is clicked, THE Dashboard SHALL open the FP Workflow Submission modal pre-populated with the selected finding IDs
|
||||
|
||||
### Requirement 2: Configure FP Workflow Details
|
||||
|
||||
**User Story:** As an editor or admin, I want to configure the FP workflow properties before submission, so that I can provide the required justification and metadata for the false positive request.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE FP_Workflow submission modal SHALL present input fields for: workflow name (required, max 255 characters), reason/justification (required), description (optional, max 2000 characters), and expiration date (required, must be a future date)
|
||||
2. THE FP_Workflow submission modal SHALL include a Scope_Override_Authorization toggle defaulting to "Authorized"
|
||||
3. THE FP_Workflow submission modal SHALL display a summary list of the selected Queue_Items including finding_id, finding_title, and associated CVEs
|
||||
4. WHEN a user attempts to submit with missing required fields, THE Dashboard SHALL display inline validation errors for each invalid field and prevent submission
|
||||
5. IF the expiration date is set to a date in the past or today, THEN THE Dashboard SHALL reject the value and display a validation message indicating the date must be in the future
|
||||
|
||||
### Requirement 3: Upload Supporting Documentation
|
||||
|
||||
**User Story:** As an editor or admin, I want to upload supporting documents and artifacts with my FP workflow submission, so that reviewers have the evidence needed to approve the false positive request.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE FP_Workflow submission modal SHALL include a file upload area that accepts multiple files with a maximum size of 10 MB per file
|
||||
2. WHEN files are added to the upload area, THE Dashboard SHALL display each file name, size, and a remove button
|
||||
3. THE Dashboard SHALL accept files with extensions: .pdf, .png, .jpg, .jpeg, .gif, .doc, .docx, .xlsx, .csv, .txt, .zip
|
||||
4. IF a user attempts to upload a file exceeding 10 MB, THEN THE Dashboard SHALL reject the file and display an error message stating the size limit
|
||||
5. IF a user attempts to upload a file with a disallowed extension, THEN THE Dashboard SHALL reject the file and display an error message listing the allowed file types
|
||||
|
||||
### Requirement 4: Submit FP Workflow to Ivanti API
|
||||
|
||||
**User Story:** As an editor or admin, I want to submit the configured FP workflow to the Ivanti API, so that the false positive request is created in the Ivanti/RiskSense platform with all associated findings and attachments.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN the user clicks Submit, THE Dashboard SHALL send a POST request to the Ivanti_API to create a Workflow_Batch of type "False Positive" with the configured name, reason, description, expiration date, Scope_Override_Authorization setting, and the list of host finding IDs
|
||||
2. WHEN the Workflow_Batch is created successfully and attachments are present, THE Dashboard SHALL upload each Attachment to the Ivanti_API associated with the created Workflow_Batch
|
||||
3. WHEN the submission is in progress, THE Dashboard SHALL display a progress indicator showing the current step (creating workflow, uploading attachment 1 of N, etc.) and disable the Submit button to prevent duplicate submissions
|
||||
4. WHEN the entire submission completes successfully, THE Dashboard SHALL display a success message including the Ivanti-generated workflow batch ID (e.g., "FP#12345")
|
||||
5. IF the Ivanti_API returns a 401 status, THEN THE Dashboard SHALL display an error message indicating the API key is invalid or missing
|
||||
6. IF the Ivanti_API returns a 429 status, THEN THE Dashboard SHALL display an error message indicating rate limiting and suggest retrying later
|
||||
7. IF the Ivanti_API returns any other error status during workflow creation, THEN THE Dashboard SHALL display the error details and preserve the user's form input so they can retry without re-entering data
|
||||
8. IF an attachment upload fails after the workflow is created, THEN THE Dashboard SHALL report which attachments failed, display the workflow batch ID for the successfully created workflow, and allow the user to retry the failed uploads
|
||||
|
||||
### Requirement 5: Post-Submission Queue Item Updates
|
||||
|
||||
**User Story:** As an editor or admin, I want queue items to be automatically marked complete after a successful FP workflow submission, so that my queue reflects the current processing state.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN an FP workflow submission completes successfully, THE Dashboard SHALL mark all associated Queue_Items as "complete" status
|
||||
2. WHEN Queue_Items are marked complete after submission, THE Dashboard SHALL refresh the Queue_Panel to reflect the updated statuses
|
||||
3. IF marking a Queue_Item as complete fails locally, THEN THE Dashboard SHALL display a warning that the workflow was submitted successfully but the local queue status could not be updated
|
||||
|
||||
### Requirement 6: Local Submission Tracking
|
||||
|
||||
**User Story:** As an editor or admin, I want FP workflow submissions to be tracked locally, so that I can review submission history and audit past actions.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN an FP workflow submission completes successfully, THE Dashboard SHALL create a Submission_Record in the local database containing: the Ivanti workflow batch ID, workflow name, submitting user ID, list of finding IDs, submission timestamp, and status
|
||||
2. WHEN an FP workflow submission completes successfully, THE Dashboard SHALL log an audit entry with action "ivanti_fp_workflow_created", entity type "ivanti_workflow", the workflow batch ID as entity ID, and details including the finding IDs and workflow name
|
||||
3. IF an FP workflow submission fails, THEN THE Dashboard SHALL log an audit entry with action "ivanti_fp_workflow_failed" including the error details
|
||||
|
||||
### Requirement 7: Authorization and Access Control
|
||||
|
||||
**User Story:** As a system administrator, I want FP workflow submission restricted to authorized users, so that only editors and admins can create workflows in the Ivanti platform.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Dashboard SHALL restrict the FP workflow submission API endpoint to users with the "Admin" or "Standard_User" group membership
|
||||
2. THE Dashboard SHALL restrict the FP workflow submission UI controls to users with editor or admin roles
|
||||
3. WHILE a user has the viewer role, THE Dashboard SHALL hide the "Create FP Workflow" button from the Queue_Panel
|
||||
@@ -1,109 +0,0 @@
|
||||
# Implementation Plan: Ivanti FP Workflow Submission
|
||||
|
||||
## Overview
|
||||
|
||||
Implement the ability to select FP-type items from the Ivanti Queue and submit False Positive workflows to the Ivanti/RiskSense API, with file attachment support, local submission tracking, and audit logging. The implementation follows existing codebase conventions: factory-pattern Express routes, Multer for file uploads, inline React component styles with the dark tactical theme, and the `ivantiPost()` HTTP helper for Ivanti API calls.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [x] 1. Database migration and shared helpers
|
||||
- [x] 1.1 Create migration script `backend/migrations/add_fp_submissions_table.js`
|
||||
- Create `ivanti_fp_submissions` table with columns: id, user_id, username, ivanti_workflow_batch_id, ivanti_generated_id, workflow_name, reason, description, expiration_date, scope_override, finding_ids_json, queue_item_ids_json, attachment_count, attachment_results_json, status (success/partial/failed), error_message, created_at
|
||||
- Add indexes on user_id and ivanti_generated_id
|
||||
- Follow existing migration pattern from `add_ivanti_todo_queue_table.js`
|
||||
- _Requirements: 6.1_
|
||||
|
||||
- [x] 1.2 Extract shared Ivanti API helpers into `backend/helpers/ivantiApi.js`
|
||||
- Move the `ivantiPost()` function from `ivantiWorkflows.js` into a shared module
|
||||
- Add `ivantiMultipartPost(urlPath, fileBuffer, fileName, apiKey, skipTls)` for attachment uploads using Node.js `https` module with multipart/form-data boundary construction
|
||||
- Export both functions; update `ivantiWorkflows.js` and `ivantiFindings.js` to import from the shared module
|
||||
- _Requirements: 4.1, 4.2_
|
||||
|
||||
- [x] 2. Backend route — validation and payload construction
|
||||
- [x] 2.1 Create `backend/routes/ivantiFpWorkflow.js` with validation and payload builder
|
||||
- Export `createIvantiFpWorkflowRouter(db, requireAuth)` factory function
|
||||
- Implement `POST /` route with `requireAuth(db)` and `requireGroup('Admin', 'Standard_User')` middleware
|
||||
- Configure Multer for up to 10 file uploads, 10MB each, with allowed extensions: .pdf, .png, .jpg, .jpeg, .gif, .doc, .docx, .xlsx, .csv, .txt, .zip
|
||||
- Implement `validateFpWorkflowForm(body)` — returns error map for invalid fields (name required max 255, reason required, description max 2000, expirationDate required and must be future date)
|
||||
- Implement `buildIvantiPayload(formData, findingIds)` — constructs the Ivanti API request body with type "FALSE_POSITIVE", scopeOverrideAuthorization mapping, and hostFindingIds as integers
|
||||
- Implement `isAllowedFileExtension(filename)` — checks against the allowed extensions list (case-insensitive)
|
||||
- Verify all queueItemIds belong to the requesting user, are FP-type, and have pending status
|
||||
- _Requirements: 2.4, 2.5, 3.3, 3.4, 3.5, 4.1, 7.1_
|
||||
|
||||
- [ ]* 2.2 Write property tests for validation and payload construction
|
||||
- **Property 3: Form Validation Correctness** — For any form state, validation passes iff all required fields present and expiration date is future; error map keys match invalid fields only
|
||||
- **Property 4: File Extension Validation** — For any filename, acceptance returns true iff extension is in the allowed set (case-insensitive)
|
||||
- **Property 5: API Payload Construction** — For any valid form input, the constructed payload contains correct type, name, reason, expirationDate, scopeOverrideAuthorization, and hostFindingIds as integers
|
||||
- Use `fast-check` library with minimum 100 iterations per property
|
||||
- **Validates: Requirements 2.4, 2.5, 3.3, 4.1**
|
||||
|
||||
- [x] 3. Backend route — Ivanti API submission and local persistence
|
||||
- [x] 3.1 Implement the submission flow in `ivantiFpWorkflow.js`
|
||||
- Call Ivanti API `POST /client/{clientId}/workflowBatch` to create the FP workflow batch
|
||||
- If attachments present, upload each via `ivantiMultipartPost()` to `/client/{clientId}/workflowBatch/{id}/attachment`
|
||||
- Handle Ivanti API error responses: 401 (invalid key), 419 (insufficient privileges), 429 (rate limited), other errors
|
||||
- On success: insert submission record into `ivanti_fp_submissions`, call `logAudit()` with action "ivanti_fp_workflow_created"
|
||||
- On failure: call `logAudit()` with action "ivanti_fp_workflow_failed"
|
||||
- Mark associated queue items as complete via `UPDATE ivanti_todo_queue SET status='complete'`
|
||||
- Handle partial failures (workflow created but attachment upload failed) — save with status "partial"
|
||||
- Return structured response with workflowBatchId, generatedId, attachmentResults, queueItemsUpdated
|
||||
- _Requirements: 4.1, 4.2, 4.5, 4.6, 4.7, 4.8, 5.1, 6.1, 6.2, 6.3_
|
||||
|
||||
- [ ]* 3.2 Write property tests for queue item completion and submission persistence
|
||||
- **Property 6: Queue Items Marked Complete on Success** — For any set of queue item IDs after successful submission, all items have status "complete"
|
||||
- **Property 7: Post-Submission Persistence Completeness** — For any successful submission, the record contains all required fields (ivanti_workflow_batch_id, workflow_name, user_id, finding_ids_json, created_at) and audit entry has correct action/entity_type/details
|
||||
- Use in-memory SQLite for test isolation
|
||||
- **Validates: Requirements 5.1, 6.1, 6.2**
|
||||
|
||||
- [x] 4. Wire backend route into server.js
|
||||
- [x] 4.1 Register the new route in `backend/server.js`
|
||||
- Add `const createIvantiFpWorkflowRouter = require('./routes/ivantiFpWorkflow');`
|
||||
- Mount at `app.use('/api/ivanti/fp-workflow', createIvantiFpWorkflowRouter(db, requireAuth));`
|
||||
- Place near the existing Ivanti route registrations
|
||||
- _Requirements: 7.1_
|
||||
|
||||
- [x] 5. Checkpoint — Backend complete
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
- [x] 6. Frontend — FP Workflow Modal component
|
||||
- [x] 6.1 Implement `FpWorkflowModal` in `frontend/src/components/pages/ReportingPage.js`
|
||||
- Add the modal component inline in ReportingPage.js following the existing pattern (QueuePanel, AddToQueuePopover are in the same file)
|
||||
- Props: open, onClose, selectedItems (FP queue items), onSuccess
|
||||
- Form fields: workflow name (text input, required), reason (textarea, required), description (textarea, optional), expiration date (date input, required), scope override toggle (Authorized/None, default Authorized)
|
||||
- Display selected findings summary: finding_id, finding_title, CVEs for each item
|
||||
- File upload area: drag-and-drop zone, file list with name/size/remove button, validate extensions and 10MB limit client-side
|
||||
- Submit button with progress indicator (creating workflow → uploading attachment N of M)
|
||||
- Error display: inline validation errors, API error messages with form state preservation
|
||||
- Success display: workflow batch ID (e.g., "FP#12345") with close/done action
|
||||
- Style with inline style objects matching the dark tactical theme from DESIGN_SYSTEM.md
|
||||
- Icons from lucide-react (Upload, FileText, X, Check, AlertTriangle, Loader)
|
||||
- _Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 3.1, 3.2, 3.3, 3.4, 3.5, 4.3, 4.4, 4.7, 4.8_
|
||||
|
||||
- [ ]* 6.2 Write property tests for frontend validation helpers
|
||||
- **Property 1: FP Workflow Button Enabled State** — For any set of queue items and selection, button enabled iff selection contains at least one pending FP item
|
||||
- **Property 2: FP-Only Item Filtering** — For any mixed-type selection, filtered result contains only FP items
|
||||
- **Property 8: Role-Based UI Visibility** — For any user role, button visible iff role is editor or admin
|
||||
- Extract `isCreateFpButtonEnabled`, `filterFpItems`, `shouldShowFpButton` as testable pure functions
|
||||
- Use `fast-check` with minimum 100 iterations
|
||||
- **Validates: Requirements 1.1, 1.2, 7.2**
|
||||
|
||||
- [x] 7. Frontend — QueuePanel integration
|
||||
- [x] 7.1 Add "Create FP Workflow" button and modal wiring in QueuePanel
|
||||
- Add "Create FP Workflow" button in QueuePanel footer, styled with amber/FP accent color
|
||||
- Button enabled only when selectedIds contains at least one pending FP-type item
|
||||
- Disabled state shows tooltip: "Select pending FP items to create a workflow"
|
||||
- Hide button entirely for viewer role users (check via useAuth context)
|
||||
- On click: filter selected items to FP-only, open FpWorkflowModal with filtered items
|
||||
- Wire onSuccess callback to trigger queue refresh (call existing fetch function from parent)
|
||||
- _Requirements: 1.1, 1.2, 1.3, 1.4, 5.2, 7.2, 7.3_
|
||||
|
||||
- [x] 8. Final checkpoint — Full integration
|
||||
- Ensure all tests pass, ask the user if questions arise.
|
||||
|
||||
## Notes
|
||||
|
||||
- Tasks marked with `*` are optional and can be skipped for faster MVP
|
||||
- Each task references specific requirements for traceability
|
||||
- Property tests use `fast-check` library — install via `npm install --save-dev fast-check` in both backend and frontend
|
||||
- The shared Ivanti API helper (task 1.2) updates existing imports in ivantiWorkflows.js and ivantiFindings.js — test those routes still work after the refactor
|
||||
- Multer is already a project dependency (used for document uploads in server.js)
|
||||
@@ -1 +0,0 @@
|
||||
{"specId": "b8855eb4-3949-426e-86ac-36fe069a6bb1", "workflowType": "requirements-first", "specType": "feature"}
|
||||
@@ -1,175 +0,0 @@
|
||||
# Design Document: Queue Hostname & IP Display
|
||||
|
||||
## Overview
|
||||
|
||||
This feature adds hostname tracking to the Ivanti todo queue. Currently the queue stores `ip_address` but not `hostname`. The change spans three layers:
|
||||
|
||||
1. **Database** — A migration adds a `hostname TEXT` column to `ivanti_todo_queue`.
|
||||
2. **Backend API** — The POST (single + batch) endpoints accept and store an optional `hostname` field. The GET endpoint already uses `SELECT *`, so hostname is returned automatically once the column exists.
|
||||
3. **Frontend** — The `addToQueue` and `submitBatch` functions pass `finding.hostName` as `hostname`. The QueuePanel renders hostname and IP address for both CARD and vendor-grouped (FP/Archer) sections.
|
||||
|
||||
The change is additive and backward-compatible. Existing rows get `NULL` for hostname. No existing behavior changes unless both hostname and ip_address are present.
|
||||
|
||||
## Architecture
|
||||
|
||||
The data flows through three layers in a straight pipeline:
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[Ivanti Finding<br/>hostName, ipAddress] -->|POST /todo-queue| B[Express Route<br/>ivantiTodoQueue.js]
|
||||
B -->|INSERT hostname, ip_address| C[SQLite<br/>ivanti_todo_queue]
|
||||
C -->|SELECT *| B
|
||||
B -->|GET response| D[QueuePanel<br/>ReportingPage.js]
|
||||
```
|
||||
|
||||
No new services, tables, or route modules are introduced. The migration script is a standalone Node.js file following the existing pattern in `backend/migrations/`.
|
||||
|
||||
## Components and Interfaces
|
||||
|
||||
### Migration Script: `backend/migrations/add_todo_queue_hostname.js`
|
||||
|
||||
Follows the exact pattern of `add_todo_queue_ip_address.js`:
|
||||
|
||||
- Opens `cve_database.db` via `sqlite3`
|
||||
- Runs `ALTER TABLE ivanti_todo_queue ADD COLUMN hostname TEXT`
|
||||
- Catches `duplicate column name` error to make it idempotent
|
||||
- Closes the database connection
|
||||
|
||||
### Backend Route: `backend/routes/ivantiTodoQueue.js`
|
||||
|
||||
Changes to two endpoints:
|
||||
|
||||
**POST `/` (single-item)**
|
||||
- Extract `hostname` from `req.body`
|
||||
- Sanitize: if present and a string, trim and slice to 255 chars; otherwise `null`
|
||||
- Add to the INSERT column list and parameter array
|
||||
|
||||
**POST `/batch`**
|
||||
- For each finding in the `findings` array, extract `hostname` from `f.hostname`
|
||||
- Same sanitization as single-item
|
||||
- Add to the per-row INSERT column list and parameter array
|
||||
|
||||
**GET `/`** — No code change needed. `SELECT *` already returns all columns.
|
||||
|
||||
**PUT `/:id`** — No change. Hostname is set at insert time and not editable.
|
||||
|
||||
### Frontend: `ReportingPage.js`
|
||||
|
||||
**`addToQueue` function**
|
||||
- Add `hostname: finding.hostName || null` to the POST body
|
||||
|
||||
**`submitBatch` function**
|
||||
- Add `hostname: f.hostName || null` to each finding object in `findingsPayload`
|
||||
|
||||
**QueuePanel rendering (per item)**
|
||||
|
||||
For CARD items, the content `<div>` currently shows:
|
||||
1. `finding_id`
|
||||
2. `ip_address` (if present)
|
||||
|
||||
New rendering for CARD items:
|
||||
1. `finding_id`
|
||||
2. `hostname` (if present)
|
||||
3. `ip_address` (if present)
|
||||
|
||||
For vendor-grouped items (FP/Archer), the content `<div>` currently shows:
|
||||
1. `finding_id`
|
||||
2. CVE list (if present)
|
||||
|
||||
New rendering for vendor-grouped items:
|
||||
1. `finding_id`
|
||||
2. CVE list (if present)
|
||||
3. `hostname` (if present)
|
||||
4. `ip_address` (if present)
|
||||
|
||||
Both hostname and IP use the same monospace styling at `0.68rem` / `0.62rem` with muted colors consistent with the existing design system.
|
||||
|
||||
## Data Models
|
||||
|
||||
### `ivanti_todo_queue` table (after migration)
|
||||
|
||||
| Column | Type | Nullable | Notes |
|
||||
|--------|------|----------|-------|
|
||||
| id | INTEGER | NO | PRIMARY KEY AUTOINCREMENT |
|
||||
| user_id | INTEGER | NO | FK → users(id) |
|
||||
| finding_id | TEXT | NO | |
|
||||
| finding_title | TEXT | YES | max 500 chars |
|
||||
| cves_json | TEXT | YES | JSON array string |
|
||||
| ip_address | TEXT | YES | max 64 chars |
|
||||
| **hostname** | **TEXT** | **YES** | **max 255 chars (new)** |
|
||||
| vendor | TEXT | NO | |
|
||||
| workflow_type | TEXT | NO | FP, Archer, or CARD |
|
||||
| status | TEXT | NO | pending or complete |
|
||||
| created_at | DATETIME | NO | DEFAULT CURRENT_TIMESTAMP |
|
||||
| updated_at | DATETIME | NO | DEFAULT CURRENT_TIMESTAMP |
|
||||
|
||||
### API Request/Response Changes
|
||||
|
||||
**POST `/api/ivanti/todo-queue` body** — adds optional field:
|
||||
```json
|
||||
{
|
||||
"finding_id": "...",
|
||||
"finding_title": "...",
|
||||
"cves": [],
|
||||
"ip_address": "...",
|
||||
"hostname": "server01.example.com",
|
||||
"vendor": "...",
|
||||
"workflow_type": "CARD"
|
||||
}
|
||||
```
|
||||
|
||||
**POST `/api/ivanti/todo-queue/batch` body** — adds optional field per finding:
|
||||
```json
|
||||
{
|
||||
"findings": [
|
||||
{ "finding_id": "...", "ip_address": "...", "hostname": "server01.example.com" }
|
||||
],
|
||||
"workflow_type": "FP",
|
||||
"vendor": "VendorName"
|
||||
}
|
||||
```
|
||||
|
||||
**GET response** — `hostname` field included automatically via `SELECT *`:
|
||||
```json
|
||||
{
|
||||
"id": 1,
|
||||
"finding_id": "...",
|
||||
"hostname": "server01.example.com",
|
||||
"ip_address": "10.0.0.1",
|
||||
"..."
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Correctness Properties
|
||||
|
||||
*A property is a characteristic or behavior that should hold true across all valid executions of a system — essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
|
||||
|
||||
### Property 1: Hostname storage round-trip
|
||||
|
||||
*For any* valid hostname string (up to 255 characters), storing it via the queue API (single or batch endpoint) and then retrieving it via GET should return the exact same trimmed string. When the hostname is omitted, null, or empty, the stored and returned value should be null.
|
||||
|
||||
**Validates: Requirements 2.1, 2.2, 2.3, 2.4**
|
||||
|
||||
### Property 2: Hostname display presence
|
||||
|
||||
*For any* queue item with a non-null hostname value, the rendered QueuePanel output should contain the hostname text, regardless of whether the item is a CARD item or a vendor-grouped (FP/Archer) item.
|
||||
|
||||
**Validates: Requirements 4.1, 5.1**
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Handling |
|
||||
|----------|----------|
|
||||
| Migration run when column already exists | Catch `duplicate column name` SQLite error, log skip message, exit cleanly |
|
||||
| `hostname` field is not a string | Treat as null — store NULL in database |
|
||||
| `hostname` exceeds 255 characters | Truncate to 255 characters via `.slice(0, 255)` |
|
||||
| `hostname` is undefined/null/empty string | Store NULL in database |
|
||||
| GET returns item with null hostname | Frontend conditionally renders — no hostname line shown |
|
||||
| GET returns item with null ip_address and null hostname | CARD: show only finding_id. Vendor: show finding_id + CVEs only |
|
||||
|
||||
No new error codes or HTTP status changes are introduced. The hostname field is optional and its absence is a normal case, not an error.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
Testing is out of scope for this feature. Manual verification will be performed after implementation.
|
||||
@@ -1,70 +0,0 @@
|
||||
# Requirements Document
|
||||
|
||||
## Introduction
|
||||
|
||||
The Ivanti Queue (todo queue) in the STEAM Security Dashboard currently stores and displays `ip_address` for CARD workflow items but omits hostname entirely. Vendor-grouped sections (FP/Archer) display only `finding_id` and CVEs, hiding the `ip_address` that is already stored. This feature adds a `hostname` column to the database, passes hostname through the backend API, and displays both hostname and IP address across all queue sections (CARD, FP, Archer).
|
||||
|
||||
## Glossary
|
||||
|
||||
- **Queue_Panel**: The slide-out side panel (`QueuePanel` component) that displays the user's staged Ivanti findings grouped by workflow type and vendor.
|
||||
- **Queue_API**: The Express route module (`ivantiTodoQueue.js`) that handles CRUD operations on the `ivanti_todo_queue` table.
|
||||
- **Queue_Table**: The SQLite table `ivanti_todo_queue` that persists per-user queue items.
|
||||
- **CARD_Section**: The top group in the Queue_Panel that displays items with `workflow_type = 'CARD'`.
|
||||
- **Vendor_Section**: Groups in the Queue_Panel for FP and Archer workflow items, organized by vendor name.
|
||||
- **Finding**: An Ivanti host finding record containing fields such as `id`, `title`, `hostName`, `ipAddress`, `cves`, and `severity`.
|
||||
- **Migration_Script**: A standalone Node.js script in `backend/migrations/` that alters the SQLite schema.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement 1: Add hostname column to the queue database table
|
||||
|
||||
**User Story:** As a developer, I want the queue table to have a `hostname` column, so that hostname data can be persisted alongside each queued finding.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. THE Migration_Script SHALL add a `hostname` TEXT column to the Queue_Table.
|
||||
2. WHEN the `hostname` column already exists, THE Migration_Script SHALL skip the alteration and log a message indicating the column already exists.
|
||||
3. THE Migration_Script SHALL preserve all existing rows and column data in the Queue_Table.
|
||||
|
||||
### Requirement 2: Accept and store hostname in queue API endpoints
|
||||
|
||||
**User Story:** As a developer, I want the queue API to accept a `hostname` field, so that hostname data is stored when findings are added to the queue.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a POST request is received at the single-item endpoint, THE Queue_API SHALL accept an optional `hostname` string field (max 255 characters) and store it in the Queue_Table.
|
||||
2. WHEN a POST request is received at the batch endpoint, THE Queue_API SHALL accept an optional `hostname` string field on each finding object (max 255 characters) and store it in the Queue_Table.
|
||||
3. WHEN the `hostname` field is omitted or empty, THE Queue_API SHALL store NULL for the `hostname` column.
|
||||
4. WHEN a GET request is received, THE Queue_API SHALL return the `hostname` field for each queue item in the response.
|
||||
|
||||
### Requirement 3: Pass hostname from the frontend to the queue API
|
||||
|
||||
**User Story:** As a developer, I want the frontend to send hostname data when adding findings to the queue, so that hostname is captured from the Ivanti findings data.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a single finding is added to the queue, THE ReportingPage SHALL include the finding's `hostName` value in the `hostname` field of the POST request body.
|
||||
2. WHEN findings are added via batch submission, THE ReportingPage SHALL include each finding's `hostName` value in the `hostname` field of the corresponding finding object in the POST request body.
|
||||
|
||||
### Requirement 4: Display hostname and IP address in the CARD section
|
||||
|
||||
**User Story:** As a security analyst, I want to see both hostname and IP address for CARD items in the queue, so that I can identify the affected host at a glance.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a CARD item has a `hostname` value, THE CARD_Section SHALL display the hostname below the finding ID.
|
||||
2. WHEN a CARD item has an `ip_address` value, THE CARD_Section SHALL display the IP address below the hostname.
|
||||
3. WHEN a CARD item has both `hostname` and `ip_address`, THE CARD_Section SHALL display hostname on one line and IP address on the next line.
|
||||
4. WHEN a CARD item has only `ip_address` and no `hostname`, THE CARD_Section SHALL display the IP address (preserving current behavior).
|
||||
5. WHEN a CARD item has only `hostname` and no `ip_address`, THE CARD_Section SHALL display the hostname.
|
||||
|
||||
### Requirement 5: Display hostname and IP address in vendor sections (FP/Archer)
|
||||
|
||||
**User Story:** As a security analyst, I want to see hostname and IP address for FP and Archer items in the queue, so that I can identify affected hosts without leaving the queue panel.
|
||||
|
||||
#### Acceptance Criteria
|
||||
|
||||
1. WHEN a vendor-grouped item has a `hostname` value, THE Vendor_Section SHALL display the hostname below the CVE list.
|
||||
2. WHEN a vendor-grouped item has an `ip_address` value, THE Vendor_Section SHALL display the IP address below the hostname (or below the CVE list if no hostname exists).
|
||||
3. WHEN a vendor-grouped item has both `hostname` and `ip_address`, THE Vendor_Section SHALL display hostname on one line and IP address on the next line, both below the CVE list.
|
||||
4. WHEN a vendor-grouped item has neither `hostname` nor `ip_address`, THE Vendor_Section SHALL display only the finding ID and CVE list (preserving current behavior).
|
||||
@@ -1,56 +0,0 @@
|
||||
# Implementation Plan: Queue Hostname & IP Display
|
||||
|
||||
## Overview
|
||||
|
||||
Add hostname tracking to the Ivanti todo queue across database, backend API, and frontend display layers. All changes are additive and backward-compatible.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [x] 1. Create database migration to add hostname column
|
||||
- Create `backend/migrations/add_todo_queue_hostname.js` following the exact pattern of `add_todo_queue_ip_address.js`
|
||||
- Use `ALTER TABLE ivanti_todo_queue ADD COLUMN hostname TEXT`
|
||||
- Handle `duplicate column name` error for idempotency
|
||||
- Log appropriate messages for success and skip scenarios
|
||||
- _Requirements: 1.1, 1.2, 1.3_
|
||||
|
||||
- [x] 2. Update backend API endpoints to accept and store hostname
|
||||
- [x] 2.1 Update POST `/` (single-item) endpoint in `backend/routes/ivantiTodoQueue.js`
|
||||
- Extract `hostname` from `req.body`
|
||||
- Sanitize: if present and a string, trim and slice to 255 chars; otherwise `null`
|
||||
- Add `hostname` to the INSERT column list and parameter array
|
||||
- _Requirements: 2.1, 2.3_
|
||||
|
||||
- [x] 2.2 Update POST `/batch` endpoint in `backend/routes/ivantiTodoQueue.js`
|
||||
- For each finding, extract `hostname` from `f.hostname`
|
||||
- Apply same sanitization as single-item (trim, slice to 255, or null)
|
||||
- Add `hostname` to the per-row INSERT column list and parameter array
|
||||
- _Requirements: 2.2, 2.3_
|
||||
|
||||
- [x] 3. Checkpoint
|
||||
- Ensure all backend changes are consistent, ask the user if questions arise.
|
||||
|
||||
- [x] 4. Update frontend to pass hostname and display it in the queue panel
|
||||
- [x] 4.1 Update `addToQueue` function in `ReportingPage.js`
|
||||
- Add `hostname: finding.hostName || null` to the POST request body
|
||||
- _Requirements: 3.1_
|
||||
|
||||
- [x] 4.2 Update `submitBatch` function in `ReportingPage.js`
|
||||
- Add `hostname: f.hostName || null` to each finding object in the payload
|
||||
- _Requirements: 3.2_
|
||||
|
||||
- [x] 4.3 Update CARD section rendering in QueuePanel (`ReportingPage.js`)
|
||||
- Display `hostname` below finding_id (when present)
|
||||
- Display `ip_address` below hostname (when present)
|
||||
- Handle all combinations: both present, only hostname, only ip_address, neither
|
||||
- Use monospace styling at `0.68rem` consistent with existing ip_address display
|
||||
- _Requirements: 4.1, 4.2, 4.3, 4.4, 4.5_
|
||||
|
||||
- [x] 4.4 Update vendor section (FP/Archer) rendering in QueuePanel (`ReportingPage.js`)
|
||||
- Display `hostname` below the CVE list (when present)
|
||||
- Display `ip_address` below hostname or below CVE list if no hostname
|
||||
- Handle all combinations: both present, only one, neither
|
||||
- Use monospace styling at `0.62rem` / `0.68rem` with muted colors matching existing design
|
||||
- _Requirements: 5.1, 5.2, 5.3, 5.4_
|
||||
|
||||
- [x] 5. Final checkpoint
|
||||
- Ensure all changes are wired together end-to-end, ask the user if questions arise.
|
||||
@@ -1,27 +0,0 @@
|
||||
# Product Overview
|
||||
|
||||
The STEAM Security Dashboard is a self-hosted vulnerability management tool for the NTS-AEO-STEAM and NTS-AEO-ACCESS-ENG business units. It centralizes CVE tracking, Ivanti host finding triage, AEO compliance posture monitoring, FP/Archer exception workflows, and internal documentation in a single interface.
|
||||
|
||||
## Core Capabilities
|
||||
|
||||
- Searchable CVE list with per-vendor tracking and document storage
|
||||
- NVD API integration for auto-populating CVE metadata
|
||||
- Ivanti/RiskSense integration for syncing open host findings with FP workflow tracking
|
||||
- Reporting page with charts, advanced filtering, inline editing, and CSV/XLSX export
|
||||
- Ivanti Queue for batch-processing FP, Archer, and CARD workflows
|
||||
- AEO Compliance page with weekly xlsx upload, diff preview, per-team metric health cards, and device-level violation tracking
|
||||
- Archer risk acceptance ticket tracking (EXC numbers) linked to CVE/vendor pairs
|
||||
- Knowledge base for internal documentation and policies
|
||||
- Role-based access control (viewer, editor, admin) with full audit trail
|
||||
|
||||
## User Roles
|
||||
|
||||
| Role | Permissions |
|
||||
|------|------------|
|
||||
| viewer | Read-only access to all data |
|
||||
| editor | All viewer permissions plus create/update operations |
|
||||
| admin | All editor permissions plus delete, user management, and audit log access |
|
||||
|
||||
## Teams Tracked
|
||||
|
||||
Only **STEAM** and **ACCESS-ENG** teams are tracked in the compliance module.
|
||||
@@ -1,83 +0,0 @@
|
||||
# Project Structure & Conventions
|
||||
|
||||
## Directory Layout
|
||||
|
||||
```
|
||||
cve-dashboard/
|
||||
├── backend/ # Express API server
|
||||
│ ├── server.js # Main entry point — app setup, middleware, CVE/document routes inline
|
||||
│ ├── setup.js # One-time DB init + default admin creation
|
||||
│ ├── cve_database.db # SQLite database (gitignored)
|
||||
│ ├── uploads/ # File storage (gitignored)
|
||||
│ ├── routes/ # Express route modules (factory pattern)
|
||||
│ │ ├── auth.js
|
||||
│ │ ├── users.js
|
||||
│ │ ├── auditLog.js
|
||||
│ │ ├── nvdLookup.js
|
||||
│ │ ├── knowledgeBase.js
|
||||
│ │ ├── archerTickets.js
|
||||
│ │ ├── ivantiWorkflows.js
|
||||
│ │ ├── ivantiFindings.js
|
||||
│ │ ├── ivantiTodoQueue.js
|
||||
│ │ └── compliance.js
|
||||
│ ├── middleware/
|
||||
│ │ └── auth.js # requireAuth(db), requireRole(...roles)
|
||||
│ ├── helpers/
|
||||
│ │ └── auditLog.js # logAudit() — fire-and-forget DB insert
|
||||
│ ├── migrations/ # Sequential migration scripts (run manually with node)
|
||||
│ └── scripts/ # Python utilities (compliance parsing, CSV import)
|
||||
│
|
||||
├── frontend/ # React 19 SPA (Create React App)
|
||||
│ └── src/
|
||||
│ ├── App.js # Main dashboard — CVE list, filters, modals, inline styles
|
||||
│ ├── App.css # Global styles and CSS variables
|
||||
│ ├── contexts/
|
||||
│ │ └── AuthContext.js # Auth state provider (login, logout, role helpers)
|
||||
│ └── components/
|
||||
│ ├── LoginForm.js
|
||||
│ ├── NavDrawer.js
|
||||
│ ├── UserMenu.js
|
||||
│ ├── CalendarWidget.js
|
||||
│ ├── UserManagement.js
|
||||
│ ├── AuditLog.js
|
||||
│ ├── NvdSyncModal.js
|
||||
│ ├── KnowledgeBaseModal.js
|
||||
│ ├── KnowledgeBaseViewer.js
|
||||
│ └── pages/ # Full-page views
|
||||
│ ├── ReportingPage.js
|
||||
│ ├── CompliancePage.js
|
||||
│ ├── ComplianceUploadModal.js
|
||||
│ ├── ComplianceDetailPanel.js
|
||||
│ ├── ComplianceChartsPanel.js
|
||||
│ ├── IvantiCountsChart.js
|
||||
│ ├── KnowledgeBasePage.js
|
||||
│ └── ExportsPage.js
|
||||
│
|
||||
├── docs/ # Internal documentation (markdown)
|
||||
├── start-servers.sh # Start both servers in background
|
||||
├── stop-servers.sh # Stop both servers
|
||||
└── DESIGN_SYSTEM.md # UI design system reference (colors, typography, components)
|
||||
```
|
||||
|
||||
## Backend Conventions
|
||||
|
||||
- Route modules export a factory function: `function createXxxRouter(db, ...middleware)` that returns an Express Router.
|
||||
- The `db` (sqlite3 Database instance) is passed via dependency injection from `server.js`.
|
||||
- Auth middleware: `requireAuth(db)` validates session cookie, attaches `req.user`. `requireRole('editor', 'admin')` checks role.
|
||||
- All state-changing actions call `logAudit(db, { userId, username, action, entityType, entityId, details, ipAddress })`.
|
||||
- Input validation is done inline in route handlers with early-return error responses.
|
||||
- SQLite queries use the callback-based `db.run()`, `db.get()`, `db.all()` API.
|
||||
- API routes are prefixed with `/api`. All endpoints except login/logout require a valid session cookie.
|
||||
- CVE and document routes are defined inline in `server.js`; feature routes are in separate modules under `routes/`.
|
||||
|
||||
## Frontend Conventions
|
||||
|
||||
- Single-page app with page-level navigation managed in `App.js` (no React Router).
|
||||
- Auth state managed via React Context (`AuthContext`). Use `useAuth()` hook for login/logout/role checks.
|
||||
- API calls use `fetch()` with `credentials: 'include'` for cookie-based auth.
|
||||
- API base URL from `process.env.REACT_APP_API_BASE`.
|
||||
- Styling uses a mix of inline style objects (defined as constants in component files) and `App.css` global styles.
|
||||
- Dark theme with a "tactical intelligence" aesthetic — see `DESIGN_SYSTEM.md` for color palette, typography, and component specs.
|
||||
- Icons from `lucide-react`. Charts from `recharts`.
|
||||
- Page components live in `components/pages/`. Shared components live in `components/`.
|
||||
- No TypeScript — the project uses plain JavaScript throughout.
|
||||
@@ -1,78 +0,0 @@
|
||||
# Tech Stack & Build System
|
||||
|
||||
## Stack
|
||||
|
||||
| Layer | Technology |
|
||||
|-------|-----------|
|
||||
| Backend | Node.js 18+, Express 5 |
|
||||
| Database | SQLite3 (file: `backend/cve_database.db`) |
|
||||
| Auth | bcryptjs, cookie-based sessions (httpOnly, 24h expiry) |
|
||||
| File uploads | Multer 2 (10MB limit) |
|
||||
| Frontend | React 19 (Create React App / react-scripts 5) |
|
||||
| UI Icons | lucide-react |
|
||||
| Charts | recharts |
|
||||
| Spreadsheet parsing | xlsx (frontend), pandas + openpyxl (backend Python scripts) |
|
||||
| Markdown rendering | react-markdown |
|
||||
| Diagrams | mermaid |
|
||||
|
||||
## Common Commands
|
||||
|
||||
### Backend
|
||||
```bash
|
||||
cd backend
|
||||
node setup.js # Initialize DB, tables, indexes, default admin user
|
||||
node server.js # Start backend on port 3001
|
||||
```
|
||||
|
||||
### Frontend
|
||||
```bash
|
||||
cd frontend
|
||||
npm install # Install dependencies
|
||||
npm start # Dev server on port 3000
|
||||
npm run build # Production build
|
||||
npm test # Run tests (react-scripts test)
|
||||
```
|
||||
|
||||
### Both servers (from project root)
|
||||
```bash
|
||||
./start-servers.sh # Start backend + frontend in background
|
||||
./stop-servers.sh # Stop all servers
|
||||
```
|
||||
|
||||
### Database Migrations (run from `backend/` in order)
|
||||
```bash
|
||||
node migrations/add_knowledge_base_table.js
|
||||
node migrations/add_archer_tickets_table.js
|
||||
node migrations/add_ivanti_sync_table.js
|
||||
node migrations/add_ivanti_findings_tables.js
|
||||
node migrations/add_ivanti_todo_queue_table.js
|
||||
node migrations/add_card_workflow_type.js
|
||||
node migrations/add_todo_queue_ip_address.js
|
||||
node migrations/add_compliance_tables.js
|
||||
```
|
||||
|
||||
### Python Scripts (from `backend/scripts/`)
|
||||
```bash
|
||||
# Compliance xlsx parsing (called automatically by upload flow)
|
||||
python3 parse_compliance_xlsx.py <file>
|
||||
|
||||
# Bulk notes import
|
||||
python3 import_notes_from_csv.py input.csv --dry-run
|
||||
python3 import_notes_from_csv.py input.csv
|
||||
```
|
||||
|
||||
Python dependencies: `pandas>=2.0.0`, `openpyxl>=3.0.0` (install via apt or venv).
|
||||
|
||||
## Environment Configuration
|
||||
|
||||
- `backend/.env` — PORT, CORS_ORIGINS, SESSION_SECRET, NVD_API_KEY, Ivanti API credentials
|
||||
- `frontend/.env` — REACT_APP_API_BASE, REACT_APP_API_HOST
|
||||
- Both `.env` files are gitignored; see `.env.example` files for templates.
|
||||
- React caches env vars at build/start time — restart the frontend process after changes.
|
||||
|
||||
## Default Ports
|
||||
|
||||
| Service | URL |
|
||||
|---------|-----|
|
||||
| Frontend | http://localhost:3000 |
|
||||
| Backend API | http://localhost:3001 |
|
||||
59
CHANGELOG.md
Normal file
59
CHANGELOG.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# Changelog
|
||||
|
||||
## v1.0.0 — 2026-05-01
|
||||
|
||||
First official release. Consolidates all features developed since initial commit into a stable, documented, deployment-ready package.
|
||||
|
||||
### Core Platform
|
||||
- CVE tracking with multi-vendor support, document storage, and NVD API auto-fill
|
||||
- Session-based authentication with four user groups (Admin, Standard_User, Leadership, Read_Only)
|
||||
- Full audit logging of all state-changing actions
|
||||
- Dark tactical intelligence UI theme with monospace typography
|
||||
|
||||
### Ivanti Integration
|
||||
- Live sync of open host findings from Ivanti/RiskSense API (auto-sync every 24h)
|
||||
- Reporting page with donut metric charts, advanced per-column filtering, inline editing
|
||||
- FP workflow submission directly to Ivanti API with file attachments
|
||||
- Ivanti Queue — personal staging list for batch FP, Archer, CARD, and Granite workflows
|
||||
- Queue item redirect between workflow types after completion
|
||||
- Row visibility controls with localStorage persistence
|
||||
|
||||
### Archive and Anomaly Tracking
|
||||
- Automatic detection of disappeared and returned findings across syncs
|
||||
- BU drift checker — classifies archived findings by reason (BU reassignment, severity drift, closed on platform, decommissioned)
|
||||
- Return classification — explains why findings came back (BU reassigned back, severity re-escalated, etc.)
|
||||
- Findings Trend chart with archive activity sparkline and shift reason tooltips
|
||||
- Anomaly banner for significant archive events
|
||||
|
||||
### Compliance (AEO Posture)
|
||||
- Weekly NTS_AEO xlsx upload with diff preview (new, resolved, recurring)
|
||||
- Schema drift detection with breaking/silent-miss/cosmetic classification
|
||||
- Admin config reconciliation for parser updates
|
||||
- Per-team metric health cards with grouped categories and variant pills
|
||||
- Device-level violation tracking with timestamped notes history
|
||||
- Multi-metric note grouping
|
||||
- Upload rollback support
|
||||
|
||||
### Integrations
|
||||
- Jira Data Center — create, sync, and track tickets linked to CVE/vendor pairs
|
||||
- Archer — risk acceptance exception tracking (EXC numbers)
|
||||
- Atlas InfoSec — action plan cache, bulk creation from row selection, metrics reporting
|
||||
- CARD API — Granite/CARD asset lookup for network device workflows
|
||||
- NVD API — auto-fill CVE metadata with bulk sync support
|
||||
|
||||
### Knowledge Base
|
||||
- Internal document library with inline PDF and Markdown rendering
|
||||
- Category-based browsing and search
|
||||
|
||||
### Admin
|
||||
- Full-page admin panel with user management, audit log, and system info tabs
|
||||
- Themed confirm modals replacing browser dialogs
|
||||
- User profile panel with self-service password change
|
||||
|
||||
### Infrastructure
|
||||
- Consolidated `setup.js` with complete database schema (27 tables, all indexes and triggers)
|
||||
- systemd service files for persistent deployment
|
||||
- GitLab CI/CD pipeline (install, lint, test, build, deploy)
|
||||
- GPG-signed commits for code provenance
|
||||
- Organized documentation structure (api, design, guides, security, testing, troubleshooting)
|
||||
- Migration scripts documented and retained for existing deployment upgrades
|
||||
@@ -3,6 +3,10 @@ PORT=3001
|
||||
API_HOST=localhost
|
||||
CORS_ORIGINS=http://localhost:3000
|
||||
|
||||
# Session secret — REQUIRED. Server will not start without this.
|
||||
# Generate with: openssl rand -base64 32
|
||||
SESSION_SECRET=
|
||||
|
||||
# NVD API Key (optional - increases rate limit from 5 to 50 requests per 30s)
|
||||
# Request one at https://nvd.nist.gov/developers/request-an-api-key
|
||||
NVD_API_KEY=
|
||||
@@ -15,3 +19,38 @@ IVANTI_FIRST_NAME=
|
||||
IVANTI_LAST_NAME=
|
||||
# Set to true if behind Charter's SSL inspection proxy (replicates Python verify=False)
|
||||
IVANTI_SKIP_TLS=false
|
||||
|
||||
# Atlas InfoSec API (atlas-infosec.caas.charterlab.com)
|
||||
# Service account credentials for Basic Auth — used to sync and manage action plans
|
||||
ATLAS_API_URL=
|
||||
ATLAS_API_USER=
|
||||
ATLAS_API_PASS=
|
||||
# Set to true if behind Charter's SSL inspection proxy (disables TLS cert verification)
|
||||
ATLAS_SKIP_TLS=false
|
||||
|
||||
# Jira Data Center REST API
|
||||
# VPN or Charter Network connection required for all Jira instances.
|
||||
# Service accounts use Basic Auth (JIRA_API_USER + JIRA_API_TOKEN).
|
||||
# PATs require ATLSUP approval and naming convention: Function - Team - ATLSUP-XXXXX
|
||||
# Rate limits: 1440 requests/day, burst of 60/minute.
|
||||
JIRA_BASE_URL=
|
||||
JIRA_AUTH_METHOD=basic
|
||||
# Basic Auth — service account credentials
|
||||
JIRA_API_USER=
|
||||
JIRA_API_TOKEN=
|
||||
# PAT Auth — set JIRA_AUTH_METHOD=pat to use
|
||||
JIRA_PAT=
|
||||
# Default project key and issue type for creating issues from the dashboard
|
||||
JIRA_PROJECT_KEY=
|
||||
JIRA_ISSUE_TYPE=Task
|
||||
# Set to true if behind Charter's SSL inspection proxy
|
||||
JIRA_SKIP_TLS=false
|
||||
|
||||
# CARD Asset Ownership API (card.charter.com / card.caas.stage.charterlab.com)
|
||||
# OAuth Bearer token auth — service account must be onboarded with the CARD team.
|
||||
# Tokens are acquired automatically via Basic Auth and cached for 1 hour.
|
||||
CARD_API_URL=
|
||||
CARD_API_USER=
|
||||
CARD_API_PASS=
|
||||
# Set to true if behind Charter's SSL inspection proxy
|
||||
CARD_SKIP_TLS=false
|
||||
|
||||
48
backend/__tests__/auth-password-change.property.test.js
Normal file
48
backend/__tests__/auth-password-change.property.test.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Property-Based Test: Password Change Round-Trip
|
||||
*
|
||||
* Feature: user-profile, Property 3: Password change round-trip
|
||||
*
|
||||
* For any valid current password and any new password of 8+ characters,
|
||||
* after a successful change, bcrypt.compare(newPassword, storedHash) returns true.
|
||||
*
|
||||
* Validates: Requirements 2.2, 2.7
|
||||
*/
|
||||
|
||||
const fc = require('fast-check');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
// bcrypt cost factor — production uses 10, but we use 4 (the minimum) here
|
||||
// to keep 100 iterations feasible within test timeouts. The round-trip property
|
||||
// holds regardless of cost factor.
|
||||
const BCRYPT_COST = 4;
|
||||
|
||||
describe('Feature: user-profile, Property 3: Password change round-trip', () => {
|
||||
it('after a password change, bcrypt.compare(newPassword, newHash) returns true', async () => {
|
||||
await fc.assert(
|
||||
fc.asyncProperty(
|
||||
// Current password: any non-empty string (length >= 1)
|
||||
fc.string({ minLength: 1, maxLength: 72 }),
|
||||
// New password: any string of length >= 8 (bcrypt max input is 72 bytes)
|
||||
fc.string({ minLength: 8, maxLength: 72 }),
|
||||
async (currentPassword, newPassword) => {
|
||||
// Step 1: Hash the current password (simulates existing stored hash)
|
||||
const currentHash = await bcrypt.hash(currentPassword, BCRYPT_COST);
|
||||
|
||||
// Step 2: Verify the current password against the stored hash
|
||||
// (simulates the bcrypt.compare check in the change-password route)
|
||||
const currentPasswordValid = await bcrypt.compare(currentPassword, currentHash);
|
||||
expect(currentPasswordValid).toBe(true);
|
||||
|
||||
// Step 3: Hash the new password (simulates bcrypt.hash(newPassword, 10) in the route)
|
||||
const newHash = await bcrypt.hash(newPassword, BCRYPT_COST);
|
||||
|
||||
// Step 4: Verify the new password matches the new hash (round-trip property)
|
||||
const newPasswordValid = await bcrypt.compare(newPassword, newHash);
|
||||
expect(newPasswordValid).toBe(true);
|
||||
}
|
||||
),
|
||||
{ numRuns: 100 }
|
||||
);
|
||||
}, 120000); // 2-minute timeout for 100 bcrypt iterations
|
||||
});
|
||||
84
backend/__tests__/auth-profile-completeness.property.test.js
Normal file
84
backend/__tests__/auth-profile-completeness.property.test.js
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Property-Based Test: Profile API Returns Complete User Data Matching Database
|
||||
*
|
||||
* Feature: user-profile, Property 2: Profile API returns complete user data matching database
|
||||
*
|
||||
* For any active user record, the profile route's mapping logic produces a
|
||||
* response object with all 6 required fields (id, username, email, group,
|
||||
* created_at, last_login) and each value matches the corresponding column
|
||||
* in the users table. The `group` field maps from the `user_group` column.
|
||||
*
|
||||
* Validates: Requirements 4.1
|
||||
*/
|
||||
|
||||
const fc = require('fast-check');
|
||||
|
||||
/**
|
||||
* Simulates the exact mapping logic from GET /api/auth/profile in routes/auth.js:
|
||||
*
|
||||
* res.json({
|
||||
* id: user.id,
|
||||
* username: user.username,
|
||||
* email: user.email,
|
||||
* group: user.user_group,
|
||||
* created_at: user.created_at,
|
||||
* last_login: user.last_login
|
||||
* });
|
||||
*/
|
||||
function mapUserRowToProfileResponse(user) {
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
group: user.user_group,
|
||||
created_at: user.created_at,
|
||||
last_login: user.last_login
|
||||
};
|
||||
}
|
||||
|
||||
describe('Feature: user-profile, Property 2: Profile API returns complete user data matching database', () => {
|
||||
it('profile response contains all 6 required fields matching the database row', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
// Generate arbitrary user rows matching the users table schema
|
||||
fc.record({
|
||||
id: fc.integer({ min: 1, max: 1000000 }),
|
||||
username: fc.string({ minLength: 1, maxLength: 50 }),
|
||||
email: fc.string({ minLength: 3, maxLength: 255 }),
|
||||
user_group: fc.constantFrom('Admin', 'Standard_User', 'Read_Only'),
|
||||
created_at: fc.integer({ min: 1577836800000, max: 1924991999000 })
|
||||
.map(ts => new Date(ts).toISOString().replace('T', ' ').slice(0, 19)),
|
||||
last_login: fc.oneof(
|
||||
fc.integer({ min: 1577836800000, max: 1924991999000 })
|
||||
.map(ts => new Date(ts).toISOString().replace('T', ' ').slice(0, 19)),
|
||||
fc.constant(null)
|
||||
),
|
||||
is_active: fc.constant(1)
|
||||
}),
|
||||
(userRow) => {
|
||||
const response = mapUserRowToProfileResponse(userRow);
|
||||
|
||||
// Assert all 6 required fields are present
|
||||
expect(response).toHaveProperty('id');
|
||||
expect(response).toHaveProperty('username');
|
||||
expect(response).toHaveProperty('email');
|
||||
expect(response).toHaveProperty('group');
|
||||
expect(response).toHaveProperty('created_at');
|
||||
expect(response).toHaveProperty('last_login');
|
||||
|
||||
// Assert each value matches the corresponding database column
|
||||
expect(response.id).toBe(userRow.id);
|
||||
expect(response.username).toBe(userRow.username);
|
||||
expect(response.email).toBe(userRow.email);
|
||||
expect(response.group).toBe(userRow.user_group); // group maps from user_group
|
||||
expect(response.created_at).toBe(userRow.created_at);
|
||||
expect(response.last_login).toBe(userRow.last_login);
|
||||
|
||||
// Assert exactly 6 keys — no extra fields leaked
|
||||
expect(Object.keys(response)).toHaveLength(6);
|
||||
}
|
||||
),
|
||||
{ numRuns: 100 }
|
||||
);
|
||||
});
|
||||
});
|
||||
39
backend/__tests__/auth-short-password.property.test.js
Normal file
39
backend/__tests__/auth-short-password.property.test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Property-Based Test: Short Passwords Are Rejected (Server-Side)
|
||||
*
|
||||
* Feature: user-profile, Property 6 (server-side): Short passwords are rejected
|
||||
*
|
||||
* For any string of length 0 to 7, the server-side validation logic
|
||||
* (newPassword.length < 8) correctly identifies them as too short,
|
||||
* meaning the password change would return 400 and the stored hash
|
||||
* would remain unchanged.
|
||||
*
|
||||
* Validates: Requirements 2.5, 5.4
|
||||
*/
|
||||
|
||||
const fc = require('fast-check');
|
||||
|
||||
describe('Feature: user-profile, Property 6 (server-side): Short passwords are rejected', () => {
|
||||
it('any string of length 0–7 is rejected by the server-side length validation', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
// Generate arbitrary strings of length 0 to 7
|
||||
fc.string({ minLength: 0, maxLength: 7 }),
|
||||
(shortPassword) => {
|
||||
// This is the exact validation check from POST /api/auth/change-password:
|
||||
// if (newPassword.length < 8) return res.status(400).json({ error: '...' })
|
||||
const wouldBeRejected = shortPassword.length < 8;
|
||||
|
||||
// Every generated string must be rejected by the validation
|
||||
expect(wouldBeRejected).toBe(true);
|
||||
|
||||
// The stored hash remains unchanged because the route returns
|
||||
// early before reaching the bcrypt.hash / UPDATE query.
|
||||
// This is a structural guarantee — the early return prevents
|
||||
// any mutation of the password_hash column.
|
||||
}
|
||||
),
|
||||
{ numRuns: 100 }
|
||||
);
|
||||
});
|
||||
});
|
||||
53
backend/__tests__/auth-wrong-password.property.test.js
Normal file
53
backend/__tests__/auth-wrong-password.property.test.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Property-Based Test: Incorrect Current Password Is Always Rejected
|
||||
*
|
||||
* Feature: user-profile, Property 4: Incorrect current password is always rejected
|
||||
*
|
||||
* For any password string that does not match the user's current password,
|
||||
* the endpoint returns 401 and the stored hash remains unchanged.
|
||||
*
|
||||
* Validates: Requirements 2.3
|
||||
*/
|
||||
|
||||
const fc = require('fast-check');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
// bcrypt cost factor — production uses 10, but we use 4 (the minimum) here
|
||||
// to keep 100 iterations feasible within test timeouts. The rejection property
|
||||
// holds regardless of cost factor.
|
||||
const BCRYPT_COST = 4;
|
||||
|
||||
describe('Feature: user-profile, Property 4: Incorrect current password is always rejected', () => {
|
||||
it('bcrypt.compare rejects any wrong password and the stored hash remains unchanged', async () => {
|
||||
await fc.assert(
|
||||
fc.asyncProperty(
|
||||
// Current password: any non-empty string (bcrypt max input is 72 bytes)
|
||||
fc.string({ minLength: 1, maxLength: 72 }),
|
||||
// Wrong password: any non-empty string (will be filtered to differ from current)
|
||||
fc.string({ minLength: 1, maxLength: 72 }),
|
||||
async (currentPassword, wrongPassword) => {
|
||||
// Ensure the wrong password is always different from the current password
|
||||
fc.pre(wrongPassword !== currentPassword);
|
||||
|
||||
// Step 1: Hash the current password (simulates existing stored hash)
|
||||
const currentHash = await bcrypt.hash(currentPassword, BCRYPT_COST);
|
||||
|
||||
// Capture the hash before the failed attempt
|
||||
const hashBefore = currentHash;
|
||||
|
||||
// Step 2: Attempt to verify the wrong password against the stored hash
|
||||
// (simulates the bcrypt.compare check in the change-password route)
|
||||
const isValid = await bcrypt.compare(wrongPassword, currentHash);
|
||||
|
||||
// The wrong password must always be rejected
|
||||
expect(isValid).toBe(false);
|
||||
|
||||
// Step 3: The stored hash remains unchanged after the failed attempt
|
||||
// (no mutation should occur on rejection)
|
||||
expect(currentHash).toBe(hashBefore);
|
||||
}
|
||||
),
|
||||
{ numRuns: 100 }
|
||||
);
|
||||
}, 120000); // 2-minute timeout for 100 bcrypt iterations
|
||||
});
|
||||
BIN
backend/cve_database.db.backupNVD
Normal file
BIN
backend/cve_database.db.backupNVD
Normal file
Binary file not shown.
104
backend/helpers/atlasApi.js
Normal file
104
backend/helpers/atlasApi.js
Normal file
@@ -0,0 +1,104 @@
|
||||
// Shared Atlas InfoSec API helpers
|
||||
// Centralizes HTTP calls so the atlas router uses a single implementation.
|
||||
// Follows the same promise-based pattern as ivantiApi.js.
|
||||
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Configuration — read from process.env at module load
|
||||
// ---------------------------------------------------------------------------
|
||||
const ATLAS_API_URL = process.env.ATLAS_API_URL || '';
|
||||
const ATLAS_API_USER = process.env.ATLAS_API_USER || '';
|
||||
const ATLAS_API_PASS = process.env.ATLAS_API_PASS || '';
|
||||
const ATLAS_SKIP_TLS = process.env.ATLAS_SKIP_TLS === 'true';
|
||||
|
||||
const requiredVars = ['ATLAS_API_URL', 'ATLAS_API_USER', 'ATLAS_API_PASS'];
|
||||
const missingVars = requiredVars.filter((v) => !process.env[v]);
|
||||
if (missingVars.length > 0) {
|
||||
console.warn(`[atlas-api] WARNING: Missing required environment variables: ${missingVars.join(', ')}. Atlas API calls will fail.`);
|
||||
}
|
||||
|
||||
const isConfigured = missingVars.length === 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Generic request — supports GET, PUT, PATCH, POST
|
||||
// ---------------------------------------------------------------------------
|
||||
function atlasRequest(method, urlPath, body, options) {
|
||||
const timeout = (options && options.timeout) || 15000;
|
||||
const authString = Buffer.from(ATLAS_API_USER + ':' + ATLAS_API_PASS).toString('base64');
|
||||
const fullUrl = new URL(ATLAS_API_URL + urlPath);
|
||||
const isHttps = fullUrl.protocol === 'https:';
|
||||
const transport = isHttps ? https : http;
|
||||
|
||||
const headers = {
|
||||
'accept': 'application/json',
|
||||
'authorization': 'Basic ' + authString
|
||||
};
|
||||
|
||||
let bodyStr = null;
|
||||
if (body !== null && body !== undefined) {
|
||||
bodyStr = JSON.stringify(body);
|
||||
headers['content-type'] = 'application/json';
|
||||
headers['content-length'] = Buffer.byteLength(bodyStr);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqOptions = {
|
||||
hostname: fullUrl.hostname,
|
||||
port: fullUrl.port || (isHttps ? 443 : 80),
|
||||
path: fullUrl.pathname + fullUrl.search,
|
||||
method: method,
|
||||
headers: headers,
|
||||
timeout: timeout
|
||||
};
|
||||
|
||||
if (isHttps) {
|
||||
reqOptions.rejectUnauthorized = !ATLAS_SKIP_TLS;
|
||||
}
|
||||
|
||||
const req = transport.request(reqOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => resolve({ status: res.statusCode, body: data }));
|
||||
});
|
||||
|
||||
req.on('timeout', () => req.destroy(new Error(method + ' ' + urlPath + ' timed out')));
|
||||
req.on('error', (err) => {
|
||||
reject(new Error(method + ' ' + urlPath + ' failed: ' + err.message));
|
||||
});
|
||||
|
||||
if (bodyStr) {
|
||||
req.write(bodyStr);
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Convenience wrappers
|
||||
// ---------------------------------------------------------------------------
|
||||
function atlasGet(urlPath, options) {
|
||||
return atlasRequest('GET', urlPath, null, options);
|
||||
}
|
||||
|
||||
function atlasPut(urlPath, body, options) {
|
||||
return atlasRequest('PUT', urlPath, body, options);
|
||||
}
|
||||
|
||||
function atlasPatch(urlPath, body, options) {
|
||||
return atlasRequest('PATCH', urlPath, body, options);
|
||||
}
|
||||
|
||||
function atlasPost(urlPath, body, options) {
|
||||
return atlasRequest('POST', urlPath, body, options);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isConfigured,
|
||||
atlasRequest,
|
||||
atlasGet,
|
||||
atlasPut,
|
||||
atlasPatch,
|
||||
atlasPost
|
||||
};
|
||||
305
backend/helpers/cardApi.js
Normal file
305
backend/helpers/cardApi.js
Normal file
@@ -0,0 +1,305 @@
|
||||
// Shared CARD API helpers
|
||||
// Centralizes HTTP calls for the CARD asset ownership API.
|
||||
// Follows the same promise-based pattern as atlasApi.js, with the addition
|
||||
// of OAuth Bearer token management (auto-acquire, cache, refresh, 401 retry).
|
||||
//
|
||||
// CARD API versioning:
|
||||
// - Read endpoints (GET): /api/v1/...
|
||||
// - Mutation endpoints (POST): /api/v2/...
|
||||
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Configuration — read from process.env at module load
|
||||
// ---------------------------------------------------------------------------
|
||||
const CARD_API_URL = process.env.CARD_API_URL || '';
|
||||
const CARD_API_USER = process.env.CARD_API_USER || '';
|
||||
const CARD_API_PASS = process.env.CARD_API_PASS || '';
|
||||
const CARD_SKIP_TLS = process.env.CARD_SKIP_TLS === 'true';
|
||||
|
||||
const requiredVars = ['CARD_API_URL', 'CARD_API_USER', 'CARD_API_PASS'];
|
||||
const missingVars = requiredVars.filter((v) => !process.env[v]);
|
||||
if (missingVars.length > 0) {
|
||||
console.warn(`[card-api] WARNING: Missing required environment variables: ${missingVars.join(', ')}. CARD API calls will fail.`);
|
||||
}
|
||||
|
||||
const isConfigured = missingVars.length === 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token Manager — OAuth Bearer token with 1-hour TTL
|
||||
// ---------------------------------------------------------------------------
|
||||
let cachedToken = null; // { token: string, expiresAt: number (epoch ms) }
|
||||
|
||||
function tokenIsValid() {
|
||||
if (!cachedToken) return false;
|
||||
// Refresh if within 60 seconds of expiry
|
||||
return cachedToken.expiresAt - Date.now() > 60_000;
|
||||
}
|
||||
|
||||
function invalidateToken() {
|
||||
cachedToken = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire a new Bearer token from CARD /api/v1/auth/get_token using Basic Auth.
|
||||
* Caches the token in memory with a 1-hour TTL.
|
||||
*/
|
||||
function acquireToken(timeout) {
|
||||
const authString = Buffer.from(CARD_API_USER + ':' + CARD_API_PASS).toString('base64');
|
||||
const fullUrl = new URL(CARD_API_URL + '/api/v1/auth/get_token');
|
||||
const isHttps = fullUrl.protocol === 'https:';
|
||||
const transport = isHttps ? https : http;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqOptions = {
|
||||
hostname: fullUrl.hostname,
|
||||
port: fullUrl.port || (isHttps ? 443 : 80),
|
||||
path: fullUrl.pathname + fullUrl.search,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'authorization': 'Basic ' + authString,
|
||||
'content-length': '0',
|
||||
},
|
||||
timeout: timeout || 15000,
|
||||
};
|
||||
|
||||
if (isHttps) {
|
||||
reqOptions.rejectUnauthorized = !CARD_SKIP_TLS;
|
||||
}
|
||||
|
||||
const req = transport.request(reqOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => {
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
return reject(new Error(
|
||||
`[card-api] Token acquisition failed with HTTP ${res.statusCode}: ${data.substring(0, 500)}`
|
||||
));
|
||||
}
|
||||
|
||||
// The CARD API returns the token as a JSON string or object.
|
||||
// Try to parse; fall back to raw body as the token string.
|
||||
let token;
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
token = typeof parsed === 'string' ? parsed
|
||||
: parsed.token || parsed.access_token || data.trim();
|
||||
} catch (_) {
|
||||
// Response may be a plain token string (unquoted)
|
||||
token = data.trim();
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
return reject(new Error('[card-api] Token parse failure: empty token in response body.'));
|
||||
}
|
||||
|
||||
cachedToken = {
|
||||
token,
|
||||
expiresAt: Date.now() + 60 * 60 * 1000, // 1-hour TTL
|
||||
};
|
||||
resolve(cachedToken.token);
|
||||
});
|
||||
});
|
||||
|
||||
req.on('timeout', () => req.destroy(new Error('GET /api/v1/auth/get_token timed out')));
|
||||
req.on('error', (err) => {
|
||||
reject(new Error(`[card-api] GET /api/v1/auth/get_token failed: ${err.message}`));
|
||||
});
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure we have a valid Bearer token, acquiring or refreshing as needed.
|
||||
*/
|
||||
async function ensureToken(timeout) {
|
||||
if (tokenIsValid()) return cachedToken.token;
|
||||
return acquireToken(timeout);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Generic request — supports GET and POST with Bearer auth + 401 retry
|
||||
// ---------------------------------------------------------------------------
|
||||
async function cardRequest(method, urlPath, body, options) {
|
||||
const timeout = (options && options.timeout) || 15000;
|
||||
const skipAuth = (options && options.skipAuth) || false;
|
||||
|
||||
async function doRequest(bearerToken) {
|
||||
const fullUrl = new URL(CARD_API_URL + urlPath);
|
||||
const isHttps = fullUrl.protocol === 'https:';
|
||||
const transport = isHttps ? https : http;
|
||||
|
||||
const headers = { 'accept': 'application/json' };
|
||||
|
||||
if (bearerToken) {
|
||||
headers['authorization'] = 'Bearer ' + bearerToken;
|
||||
}
|
||||
|
||||
let bodyStr = null;
|
||||
if (body !== null && body !== undefined) {
|
||||
bodyStr = JSON.stringify(body);
|
||||
headers['content-type'] = 'application/json';
|
||||
headers['content-length'] = Buffer.byteLength(bodyStr);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqOptions = {
|
||||
hostname: fullUrl.hostname,
|
||||
port: fullUrl.port || (isHttps ? 443 : 80),
|
||||
path: fullUrl.pathname + fullUrl.search,
|
||||
method,
|
||||
headers,
|
||||
timeout,
|
||||
};
|
||||
|
||||
if (isHttps) {
|
||||
reqOptions.rejectUnauthorized = !CARD_SKIP_TLS;
|
||||
}
|
||||
|
||||
const req = transport.request(reqOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => resolve({ status: res.statusCode, body: data }));
|
||||
});
|
||||
|
||||
req.on('timeout', () => req.destroy(new Error(`${method} ${urlPath} timed out`)));
|
||||
req.on('error', (err) => {
|
||||
reject(new Error(`[card-api] ${method} ${urlPath} failed: ${err.message}`));
|
||||
});
|
||||
|
||||
if (bodyStr) req.write(bodyStr);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// Skip auth for the token endpoint itself
|
||||
if (skipAuth) {
|
||||
return doRequest(null);
|
||||
}
|
||||
|
||||
// Normal flow: ensure token → request → retry once on 401
|
||||
let token = await ensureToken(timeout);
|
||||
let result = await doRequest(token);
|
||||
|
||||
if (result.status === 401) {
|
||||
// Invalidate and retry exactly once
|
||||
invalidateToken();
|
||||
token = await ensureToken(timeout);
|
||||
result = await doRequest(token);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Convenience wrappers
|
||||
// ---------------------------------------------------------------------------
|
||||
function cardGet(urlPath, options) {
|
||||
return cardRequest('GET', urlPath, null, options);
|
||||
}
|
||||
|
||||
function cardPost(urlPath, body, options) {
|
||||
return cardRequest('POST', urlPath, body, options);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// High-level helpers used by the UAT test and routes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Test connection by acquiring a token. Returns { ok, token } or { ok, error }.
|
||||
*/
|
||||
async function testConnection() {
|
||||
try {
|
||||
const token = await acquireToken();
|
||||
return { ok: true, token: token.substring(0, 12) + '...' };
|
||||
} catch (err) {
|
||||
return { ok: false, error: err.message };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/teams — list all CARD teams.
|
||||
*/
|
||||
async function getTeams() {
|
||||
const res = await cardGet('/api/v1/teams');
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/team/{teamName}/assets — list assets for a team.
|
||||
*/
|
||||
async function getTeamAssets(teamName, { disposition, page, pageSize } = {}) {
|
||||
const params = new URLSearchParams();
|
||||
if (disposition) params.set('disposition', disposition);
|
||||
if (page) params.set('page', String(page));
|
||||
params.set('page_size', String(pageSize || 50));
|
||||
|
||||
const qs = params.toString();
|
||||
const res = await cardGet(`/api/v1/team/${encodeURIComponent(teamName)}/assets${qs ? '?' + qs : ''}`);
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/owner/{assetId} — get owner record including update_token.
|
||||
*/
|
||||
async function getOwner(assetId) {
|
||||
const res = await cardGet(`/api/v1/owner/${encodeURIComponent(assetId)}`);
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v2/owner/{assetId}/confirm — confirm asset to a team.
|
||||
*/
|
||||
async function confirmAsset(assetId, teamName, updateToken, comment) {
|
||||
const params = new URLSearchParams({ update_token: updateToken });
|
||||
if (comment) params.set('comment', comment);
|
||||
const res = await cardPost(
|
||||
`/api/v2/owner/${encodeURIComponent(assetId)}/confirm?${params.toString()}`,
|
||||
{ name: teamName }
|
||||
);
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v2/owner/{assetId}/decline — decline asset from a team.
|
||||
*/
|
||||
async function declineAsset(assetId, teamName, updateToken, comment) {
|
||||
const params = new URLSearchParams({ update_token: updateToken });
|
||||
if (comment) params.set('comment', comment);
|
||||
const res = await cardPost(
|
||||
`/api/v2/owner/${encodeURIComponent(assetId)}/decline?${params.toString()}`,
|
||||
{ name: teamName }
|
||||
);
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v2/owner/{assetId}/{fromTeam}/redirect — redirect asset between teams.
|
||||
*/
|
||||
async function redirectAsset(assetId, fromTeam, toTeam, updateToken) {
|
||||
const params = new URLSearchParams({ update_token: updateToken });
|
||||
const res = await cardPost(
|
||||
`/api/v2/owner/${encodeURIComponent(assetId)}/${encodeURIComponent(fromTeam)}/redirect?${params.toString()}`,
|
||||
{ name: toTeam }
|
||||
);
|
||||
return { status: res.status, body: res.body, ok: res.status >= 200 && res.status < 300 };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isConfigured,
|
||||
missingVars,
|
||||
cardRequest,
|
||||
cardGet,
|
||||
cardPost,
|
||||
testConnection,
|
||||
getTeams,
|
||||
getTeamAssets,
|
||||
getOwner,
|
||||
confirmAsset,
|
||||
declineAsset,
|
||||
redirectAsset,
|
||||
invalidateToken,
|
||||
};
|
||||
332
backend/helpers/driftChecker.js
Normal file
332
backend/helpers/driftChecker.js
Normal file
@@ -0,0 +1,332 @@
|
||||
// Drift Checker — compares xlsx schema against parser config to detect structural drift
|
||||
// Returns categorised findings: breaking, silent_miss, cosmetic
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Load and validate the compliance parser configuration file.
|
||||
* @param {string} configPath — absolute or relative path to compliance_config.json
|
||||
* @returns {object} parsed config with metric_categories, core_cols, skip_sheets
|
||||
* @throws {Error} descriptive error if file missing, invalid JSON, or missing required keys
|
||||
*/
|
||||
function loadConfig(configPath) {
|
||||
let raw;
|
||||
try {
|
||||
raw = fs.readFileSync(configPath, 'utf8');
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
throw new Error(`Configuration file not found: ${configPath}`);
|
||||
}
|
||||
throw new Error(`Failed to read configuration file: ${err.message}`);
|
||||
}
|
||||
|
||||
let config;
|
||||
try {
|
||||
config = JSON.parse(raw);
|
||||
} catch (err) {
|
||||
throw new Error(`Configuration file contains invalid JSON: ${err.message}`);
|
||||
}
|
||||
|
||||
if (!config.metric_categories || typeof config.metric_categories !== 'object' || Array.isArray(config.metric_categories)) {
|
||||
throw new Error('Configuration file is missing required key "metric_categories" (must be an object)');
|
||||
}
|
||||
if (!Array.isArray(config.core_cols)) {
|
||||
throw new Error('Configuration file is missing required key "core_cols" (must be an array)');
|
||||
}
|
||||
if (!Array.isArray(config.skip_sheets)) {
|
||||
throw new Error('Configuration file is missing required key "skip_sheets" (must be an array)');
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare an xlsx schema against the parser config and produce a drift report.
|
||||
* @param {object} schema — output of extract_xlsx_schema.py: { sheets: [{ name, columns, metric_values? }] }
|
||||
* @param {object} config — parsed compliance_config.json: { metric_categories, core_cols, skip_sheets }
|
||||
* @returns {{ breaking: Array, silent_miss: Array, cosmetic: Array }}
|
||||
*/
|
||||
function compareSchemaToDrift(schema, config) {
|
||||
const breaking = [];
|
||||
const silent_miss = [];
|
||||
const cosmetic = [];
|
||||
|
||||
const metricCategoryKeys = new Set(Object.keys(config.metric_categories));
|
||||
const coreCols = new Set(config.core_cols);
|
||||
const skipSheets = new Set(config.skip_sheets);
|
||||
|
||||
// Build lookup of xlsx sheet names and find the Summary sheet
|
||||
const xlsxSheetNames = new Set();
|
||||
let summarySheet = null;
|
||||
|
||||
for (const sheet of schema.sheets) {
|
||||
xlsxSheetNames.add(sheet.name);
|
||||
if (sheet.name === 'Summary') {
|
||||
summarySheet = sheet;
|
||||
}
|
||||
}
|
||||
|
||||
// Identify detail sheets: present in xlsx AND not in skip_sheets
|
||||
const detailSheets = schema.sheets.filter(s => !skipSheets.has(s.name));
|
||||
|
||||
// Build set of metric values from the Summary sheet (used by multiple rules)
|
||||
const summaryMetrics = new Set(
|
||||
(summarySheet && Array.isArray(summarySheet.metric_values)) ? summarySheet.metric_values : []
|
||||
);
|
||||
|
||||
// --- Breaking rules ---
|
||||
|
||||
// Missing core column: a detail sheet is missing a column from core_cols.
|
||||
// Collect per-column stats first, then classify: if a column is missing from
|
||||
// ALL detail sheets it's breaking. If missing from only some (e.g. 5.8.1 uses
|
||||
// CMDB columns), it's cosmetic — the parser handles it via extra_json.
|
||||
const coreColMissingMap = {}; // col -> [sheet names missing it]
|
||||
for (const sheet of detailSheets) {
|
||||
const sheetCols = new Set(sheet.columns || []);
|
||||
for (const coreCol of config.core_cols) {
|
||||
if (!sheetCols.has(coreCol)) {
|
||||
if (!coreColMissingMap[coreCol]) coreColMissingMap[coreCol] = [];
|
||||
coreColMissingMap[coreCol].push(sheet.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const coreCol of Object.keys(coreColMissingMap)) {
|
||||
const missingSheets = coreColMissingMap[coreCol];
|
||||
if (detailSheets.length > 0 && missingSheets.length >= detailSheets.length) {
|
||||
// Missing from ALL detail sheets — genuinely breaking
|
||||
breaking.push({
|
||||
severity: 'breaking',
|
||||
message: `Core column "${coreCol}" is missing from all ${detailSheets.length} detail sheet(s)`,
|
||||
value: coreCol,
|
||||
sheet: null
|
||||
});
|
||||
} else {
|
||||
// Missing from some sheets — structural difference, not drift
|
||||
cosmetic.push({
|
||||
severity: 'cosmetic',
|
||||
message: `Core column "${coreCol}" is missing from ${missingSheets.length} of ${detailSheets.length} detail sheet(s): ${missingSheets.join(', ')}`,
|
||||
value: coreCol,
|
||||
sheet: null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Missing detail sheet: a sheet in metric_categories (not in skip_sheets) is absent from xlsx.
|
||||
// If the metric still appears in the Summary's metric_values, it's tracked but has zero
|
||||
// violations this week — downgrade to cosmetic instead of breaking.
|
||||
for (const metricKey of metricCategoryKeys) {
|
||||
if (!skipSheets.has(metricKey) && !xlsxSheetNames.has(metricKey)) {
|
||||
if (summaryMetrics.has(metricKey)) {
|
||||
cosmetic.push({
|
||||
severity: 'cosmetic',
|
||||
message: `Metric "${metricKey}" has no detail sheet this week — still tracked in Summary (zero violations)`,
|
||||
value: metricKey,
|
||||
sheet: null
|
||||
});
|
||||
} else {
|
||||
breaking.push({
|
||||
severity: 'breaking',
|
||||
message: `Expected detail sheet "${metricKey}" (metric category) is missing from the workbook`,
|
||||
value: metricKey,
|
||||
sheet: null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Silent-miss rules ---
|
||||
|
||||
// Unknown metric value: a metric value in Summary is not a key in metric_categories
|
||||
if (summarySheet && Array.isArray(summarySheet.metric_values)) {
|
||||
for (const metricVal of summarySheet.metric_values) {
|
||||
if (!metricCategoryKeys.has(metricVal)) {
|
||||
silent_miss.push({
|
||||
severity: 'silent_miss',
|
||||
message: `Unknown metric "${metricVal}" in Summary — not in metric_categories`,
|
||||
value: metricVal,
|
||||
sheet: 'Summary'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown sheet: an xlsx sheet not in skip_sheets and not in metric_categories
|
||||
for (const sheet of schema.sheets) {
|
||||
if (!skipSheets.has(sheet.name) && !metricCategoryKeys.has(sheet.name)) {
|
||||
silent_miss.push({
|
||||
severity: 'silent_miss',
|
||||
message: `Unknown sheet "${sheet.name}" — not in skip_sheets or metric_categories`,
|
||||
value: sheet.name,
|
||||
sheet: sheet.name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// --- Cosmetic rules ---
|
||||
|
||||
// New column in detail sheet: a detail sheet has columns not in core_cols
|
||||
for (const sheet of detailSheets) {
|
||||
for (const col of (sheet.columns || [])) {
|
||||
if (!coreCols.has(col)) {
|
||||
cosmetic.push({
|
||||
severity: 'cosmetic',
|
||||
message: `New column "${col}" in sheet "${sheet.name}" — will be captured in extra_json`,
|
||||
value: col,
|
||||
sheet: sheet.name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stale metric category: a key in metric_categories not in Summary metric values
|
||||
for (const metricKey of metricCategoryKeys) {
|
||||
if (!summaryMetrics.has(metricKey)) {
|
||||
cosmetic.push({
|
||||
severity: 'cosmetic',
|
||||
message: `Stale metric category "${metricKey}" — not found in Summary sheet metric values`,
|
||||
value: metricKey,
|
||||
sheet: null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { breaking, silent_miss, cosmetic };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconcile the parser config to resolve breaking drift findings.
|
||||
*
|
||||
* Breaking — "missing detail sheet":
|
||||
* A metric_categories key has no matching xlsx sheet. But if the metric
|
||||
* still appears in the Summary sheet's metric_values, it's a legitimate
|
||||
* tracked metric that simply doesn't have violations this week — keep it.
|
||||
* Only remove metrics absent from BOTH the xlsx sheets AND the Summary.
|
||||
*
|
||||
* Breaking — "missing core column":
|
||||
* A core_cols entry is absent from one or more detail sheets. Only remove
|
||||
* if the column is missing from ALL detail sheets (some sheets like 5.8.1
|
||||
* have a completely different column structure and shouldn't cause removal).
|
||||
*
|
||||
* Silent-miss — "unknown metric":
|
||||
* A metric value in the Summary is not in metric_categories. Add it as 'Other'.
|
||||
*
|
||||
* Silent-miss — "unknown sheet":
|
||||
* Left as a warning. Auto-adding unknown sheets creates a reconcile loop.
|
||||
*
|
||||
* @param {string} configPath — path to compliance_config.json
|
||||
* @param {object} driftReport — the drift report from compareSchemaToDrift()
|
||||
* @param {object} [schema] — optional xlsx schema (with sheets[].name and Summary metric_values)
|
||||
* @returns {{ changes: Array<{ action: string, key: string, value: string }>, config: object }}
|
||||
*/
|
||||
function reconcileConfig(configPath, driftReport, schema) {
|
||||
const config = loadConfig(configPath);
|
||||
const changes = [];
|
||||
|
||||
// Build a set of metric values from the Summary sheet (if schema provided)
|
||||
const summaryMetrics = new Set();
|
||||
if (schema && Array.isArray(schema.sheets)) {
|
||||
const summarySheet = schema.sheets.find(function(s) { return s.name === 'Summary'; });
|
||||
if (summarySheet && Array.isArray(summarySheet.metric_values)) {
|
||||
summarySheet.metric_values.forEach(function(v) { summaryMetrics.add(v); });
|
||||
}
|
||||
}
|
||||
|
||||
// Build a set of xlsx sheet names (if schema provided)
|
||||
const xlsxSheetNames = new Set();
|
||||
if (schema && Array.isArray(schema.sheets)) {
|
||||
schema.sheets.forEach(function(s) { xlsxSheetNames.add(s.name); });
|
||||
}
|
||||
|
||||
// Count how many detail sheets exist in the xlsx (excluding skip_sheets)
|
||||
const skipSheets = new Set(config.skip_sheets);
|
||||
const detailSheetCount = schema
|
||||
? schema.sheets.filter(function(s) { return !skipSheets.has(s.name); }).length
|
||||
: 0;
|
||||
|
||||
// --- Resolve breaking findings ---
|
||||
|
||||
for (const finding of (driftReport.breaking || [])) {
|
||||
// Missing detail sheet: remove from metric_categories ONLY if the metric
|
||||
// is also absent from the Summary's metric_values. If it's in the Summary,
|
||||
// it's still a tracked metric — the sheet just has zero violations this week.
|
||||
if (finding.message.includes('is missing from the workbook') && finding.value in config.metric_categories) {
|
||||
if (summaryMetrics.has(finding.value)) {
|
||||
// Metric is in the Summary — keep it, just note it's sheet-less this week
|
||||
changes.push({
|
||||
action: 'kept',
|
||||
key: 'metric_categories',
|
||||
value: finding.value,
|
||||
detail: `Kept metric "${finding.value}" — no detail sheet this week but still tracked in Summary`
|
||||
});
|
||||
} else {
|
||||
const oldCategory = config.metric_categories[finding.value];
|
||||
delete config.metric_categories[finding.value];
|
||||
changes.push({
|
||||
action: 'removed',
|
||||
key: 'metric_categories',
|
||||
value: finding.value,
|
||||
detail: `Removed stale metric category "${finding.value}" (was "${oldCategory}") — absent from both workbook sheets and Summary`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Missing core column: only remove if the column is missing from ALL detail sheets.
|
||||
// Some sheets (e.g. 5.8.1 with CMDB columns) have a completely different structure
|
||||
// and shouldn't cause removal of columns that exist in most other sheets.
|
||||
if (finding.message.includes('is missing core column') && config.core_cols.includes(finding.value)) {
|
||||
if (!changes.some(function(c) { return c.key === 'core_cols' && c.value === finding.value; })) {
|
||||
const missingFromCount = (driftReport.breaking || []).filter(
|
||||
function(f) { return f.message.includes('is missing core column') && f.value === finding.value; }
|
||||
).length;
|
||||
|
||||
if (detailSheetCount > 0 && missingFromCount >= detailSheetCount) {
|
||||
// Missing from ALL detail sheets — safe to remove
|
||||
config.core_cols = config.core_cols.filter(function(c) { return c !== finding.value; });
|
||||
changes.push({
|
||||
action: 'removed',
|
||||
key: 'core_cols',
|
||||
value: finding.value,
|
||||
detail: `Removed core column "${finding.value}" — missing from all ${detailSheetCount} detail sheet(s)`
|
||||
});
|
||||
} else {
|
||||
// Missing from some sheets but present in others — keep it
|
||||
changes.push({
|
||||
action: 'kept',
|
||||
key: 'core_cols',
|
||||
value: finding.value,
|
||||
detail: `Kept core column "${finding.value}" — missing from ${missingFromCount} of ${detailSheetCount} detail sheet(s)`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Resolve silent-miss findings ---
|
||||
|
||||
for (const finding of (driftReport.silent_miss || [])) {
|
||||
// Unknown metric in Summary: add to metric_categories as 'Other'
|
||||
if (finding.message.includes('not in metric_categories') && !(finding.value in config.metric_categories)) {
|
||||
config.metric_categories[finding.value] = 'Other';
|
||||
changes.push({
|
||||
action: 'added',
|
||||
key: 'metric_categories',
|
||||
value: finding.value,
|
||||
detail: `Added new metric "${finding.value}" to metric_categories as "Other"`
|
||||
});
|
||||
}
|
||||
|
||||
// Unknown sheet: left as a warning — auto-adding creates a reconcile loop.
|
||||
}
|
||||
|
||||
// Only write if there were actual config mutations (not just 'kept' entries)
|
||||
const hasMutations = changes.some(function(c) { return c.action !== 'kept'; });
|
||||
if (hasMutations) {
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', 'utf8');
|
||||
}
|
||||
|
||||
return { changes, config };
|
||||
}
|
||||
|
||||
module.exports = { compareSchemaToDrift, loadConfig, reconcileConfig };
|
||||
@@ -109,11 +109,11 @@ function ivantiFormPost(urlPath, fields, files, apiKey, skipTls) {
|
||||
}
|
||||
|
||||
// File fields
|
||||
for (const { name, buffer, filename } of files) {
|
||||
for (const { name, buffer, filename, contentType } of files) {
|
||||
parts.push(Buffer.from(
|
||||
`--${boundary}\r\n` +
|
||||
`Content-Disposition: form-data; name="${name}"; filename="${filename}"\r\n` +
|
||||
`Content-Type: application/octet-stream\r\n\r\n`
|
||||
`Content-Type: ${contentType || 'application/octet-stream'}\r\n\r\n`
|
||||
));
|
||||
parts.push(buffer);
|
||||
parts.push(Buffer.from('\r\n'));
|
||||
|
||||
453
backend/helpers/jiraApi.js
Normal file
453
backend/helpers/jiraApi.js
Normal file
@@ -0,0 +1,453 @@
|
||||
// Shared Jira Data Center REST API helpers
|
||||
// Centralizes HTTP calls for Jira issue operations.
|
||||
// Follows the same promise-based pattern as atlasApi.js and ivantiApi.js.
|
||||
//
|
||||
// =========================================================================
|
||||
// Charter Jira REST API Compliance
|
||||
// =========================================================================
|
||||
// Authentication:
|
||||
// - Service accounts use Basic Auth (required for shared integrations).
|
||||
// - PATs require ATLSUP approval and naming convention:
|
||||
// Function - Team - Approved ATLSUP ticket
|
||||
// - SSO must NOT be used for REST API integrations.
|
||||
//
|
||||
// Rate limiting (Charter-posted):
|
||||
// - 1 440 requests/day max
|
||||
// - Burst cap of 60 requests/minute (accumulates 1 req/idle minute)
|
||||
// - 429 response when limits are hit server-side
|
||||
//
|
||||
// Automation delays (Charter requirement):
|
||||
// - 1 second delay between GET requests
|
||||
// - 2 second delay between PUT, POST, or DELETE requests
|
||||
//
|
||||
// Forbidden patterns:
|
||||
// - /rest/api/2/field — must specify fields explicitly in every call
|
||||
// - /rest/api/2/issue/bulk — bulk updates are not allowed
|
||||
// - Single-issue GET loops — use bulk JQL search instead
|
||||
//
|
||||
// Required patterns:
|
||||
// - All GET requests MUST include a ?fields= parameter
|
||||
// - JQL MUST include at least one of: project+updated, assignee+updated,
|
||||
// status+updated
|
||||
// - JQL should use &updated>=-Xh to only fetch changed issues
|
||||
// - maxResults=1000 for search queries
|
||||
// - Issues must be updated one at a time (no bulk PUT)
|
||||
// =========================================================================
|
||||
|
||||
const https = require('https');
|
||||
const http = require('http');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Configuration — read from process.env at module load
|
||||
// ---------------------------------------------------------------------------
|
||||
const JIRA_BASE_URL = process.env.JIRA_BASE_URL || '';
|
||||
const JIRA_AUTH_METHOD = (process.env.JIRA_AUTH_METHOD || 'basic').toLowerCase();
|
||||
const JIRA_API_USER = process.env.JIRA_API_USER || '';
|
||||
const JIRA_API_TOKEN = process.env.JIRA_API_TOKEN || '';
|
||||
const JIRA_PAT = process.env.JIRA_PAT || '';
|
||||
const JIRA_SKIP_TLS = process.env.JIRA_SKIP_TLS === 'true';
|
||||
const JIRA_PROJECT_KEY = process.env.JIRA_PROJECT_KEY || '';
|
||||
const JIRA_ISSUE_TYPE = process.env.JIRA_ISSUE_TYPE || 'Task';
|
||||
|
||||
const requiredVars = JIRA_AUTH_METHOD === 'pat'
|
||||
? ['JIRA_BASE_URL', 'JIRA_PAT']
|
||||
: ['JIRA_BASE_URL', 'JIRA_API_USER', 'JIRA_API_TOKEN'];
|
||||
|
||||
const missingVars = requiredVars.filter((v) => !process.env[v]);
|
||||
if (missingVars.length > 0) {
|
||||
console.warn(`[jira-api] WARNING: Missing required environment variables: ${missingVars.join(', ')}. Jira API calls will fail.`);
|
||||
}
|
||||
|
||||
const isConfigured = missingVars.length === 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Default fields — every GET must specify fields explicitly.
|
||||
// /rest/api/2/field is forbidden; we define the field list here.
|
||||
// ---------------------------------------------------------------------------
|
||||
const DEFAULT_FIELDS = [
|
||||
'summary', 'status', 'assignee', 'created', 'updated',
|
||||
'priority', 'issuetype', 'project', 'resolution'
|
||||
];
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Rate limiter — enforces Charter's posted limits
|
||||
// 1 440 events/day, burst of 60 events/minute
|
||||
// ---------------------------------------------------------------------------
|
||||
const DAILY_LIMIT = 1440;
|
||||
const BURST_LIMIT = 60;
|
||||
const MINUTE_MS = 60 * 1000;
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
let dailyLog = [];
|
||||
let minuteLog = [];
|
||||
|
||||
function pruneLog(log, windowMs) {
|
||||
const cutoff = Date.now() - windowMs;
|
||||
while (log.length > 0 && log[0] < cutoff) {
|
||||
log.shift();
|
||||
}
|
||||
}
|
||||
|
||||
function checkRateLimit() {
|
||||
pruneLog(dailyLog, DAY_MS);
|
||||
pruneLog(minuteLog, MINUTE_MS);
|
||||
|
||||
if (dailyLog.length >= DAILY_LIMIT) {
|
||||
return { allowed: false, reason: `Daily Jira API limit reached (${DAILY_LIMIT}/day). Resets at midnight.` };
|
||||
}
|
||||
if (minuteLog.length >= BURST_LIMIT) {
|
||||
return { allowed: false, reason: `Burst Jira API limit reached (${BURST_LIMIT}/min). Wait and retry.` };
|
||||
}
|
||||
return { allowed: true };
|
||||
}
|
||||
|
||||
function recordRequest() {
|
||||
const now = Date.now();
|
||||
dailyLog.push(now);
|
||||
minuteLog.push(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current rate limit usage for diagnostics.
|
||||
*/
|
||||
function getRateLimitStatus() {
|
||||
pruneLog(dailyLog, DAY_MS);
|
||||
pruneLog(minuteLog, MINUTE_MS);
|
||||
return {
|
||||
daily: { used: dailyLog.length, limit: DAILY_LIMIT, remaining: DAILY_LIMIT - dailyLog.length },
|
||||
burst: { used: minuteLog.length, limit: BURST_LIMIT, remaining: BURST_LIMIT - minuteLog.length }
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Inter-request delay — Charter automation requirements
|
||||
// 1s between GETs, 2s between PUT/POST/DELETE
|
||||
// ---------------------------------------------------------------------------
|
||||
const GET_DELAY_MS = 1000;
|
||||
const WRITE_DELAY_MS = 2000;
|
||||
|
||||
let lastRequestTime = 0;
|
||||
let lastRequestMethod = '';
|
||||
|
||||
/**
|
||||
* Wait the required delay before issuing the next request.
|
||||
* GET → 1s, PUT/POST/DELETE → 2s since the previous request.
|
||||
*/
|
||||
function waitForDelay(method) {
|
||||
const now = Date.now();
|
||||
const requiredDelay = (lastRequestMethod === 'GET') ? GET_DELAY_MS
|
||||
: (lastRequestMethod !== '') ? WRITE_DELAY_MS : 0;
|
||||
const elapsed = now - lastRequestTime;
|
||||
const remaining = requiredDelay - elapsed;
|
||||
|
||||
if (remaining > 0) {
|
||||
return new Promise(resolve => setTimeout(resolve, remaining));
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Blocked endpoint guard
|
||||
// ---------------------------------------------------------------------------
|
||||
const BLOCKED_PATHS = [
|
||||
'/rest/api/2/field', // Must specify fields in call, not query field list
|
||||
'/rest/api/2/issue/bulk', // Bulk updates are not allowed
|
||||
];
|
||||
|
||||
function isBlockedPath(urlPath) {
|
||||
return BLOCKED_PATHS.some(blocked => urlPath.startsWith(blocked));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Generic request — supports GET, POST, PUT, DELETE
|
||||
// Enforces rate limits, inter-request delays, and blocked-path guards.
|
||||
// ---------------------------------------------------------------------------
|
||||
async function jiraRequest(method, urlPath, body, options) {
|
||||
// Block forbidden endpoints
|
||||
if (isBlockedPath(urlPath)) {
|
||||
return Promise.reject(new Error(`Blocked: ${urlPath} is not allowed per Charter Jira API policy.`));
|
||||
}
|
||||
|
||||
const limit = checkRateLimit();
|
||||
if (!limit.allowed) {
|
||||
return Promise.reject(new Error(limit.reason));
|
||||
}
|
||||
|
||||
// Enforce inter-request delay
|
||||
await waitForDelay(method);
|
||||
|
||||
const timeout = (options && options.timeout) || 15000;
|
||||
const fullUrl = new URL(JIRA_BASE_URL + urlPath);
|
||||
const isHttps = fullUrl.protocol === 'https:';
|
||||
const transport = isHttps ? https : http;
|
||||
|
||||
const headers = {
|
||||
'accept': 'application/json'
|
||||
};
|
||||
|
||||
// Auth header
|
||||
if (JIRA_AUTH_METHOD === 'pat') {
|
||||
headers['authorization'] = 'Bearer ' + JIRA_PAT;
|
||||
} else {
|
||||
const authString = Buffer.from(JIRA_API_USER + ':' + JIRA_API_TOKEN).toString('base64');
|
||||
headers['authorization'] = 'Basic ' + authString;
|
||||
}
|
||||
|
||||
let bodyStr = null;
|
||||
if (body !== null && body !== undefined) {
|
||||
bodyStr = JSON.stringify(body);
|
||||
headers['content-type'] = 'application/json';
|
||||
headers['content-length'] = Buffer.byteLength(bodyStr);
|
||||
}
|
||||
|
||||
recordRequest();
|
||||
lastRequestTime = Date.now();
|
||||
lastRequestMethod = method;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const reqOptions = {
|
||||
hostname: fullUrl.hostname,
|
||||
port: fullUrl.port || (isHttps ? 443 : 80),
|
||||
path: fullUrl.pathname + fullUrl.search,
|
||||
method: method,
|
||||
headers: headers,
|
||||
timeout: timeout
|
||||
};
|
||||
|
||||
if (isHttps) {
|
||||
reqOptions.rejectUnauthorized = !JIRA_SKIP_TLS;
|
||||
}
|
||||
|
||||
const req = transport.request(reqOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => {
|
||||
if (res.statusCode === 429) {
|
||||
resolve({ status: 429, body: data, rateLimited: true });
|
||||
} else {
|
||||
resolve({ status: res.statusCode, body: data });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('timeout', () => req.destroy(new Error(method + ' ' + urlPath + ' timed out')));
|
||||
req.on('error', (err) => {
|
||||
reject(new Error(method + ' ' + urlPath + ' failed: ' + err.message));
|
||||
});
|
||||
|
||||
if (bodyStr) {
|
||||
req.write(bodyStr);
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Convenience wrappers
|
||||
// ---------------------------------------------------------------------------
|
||||
function jiraGet(urlPath, options) {
|
||||
return jiraRequest('GET', urlPath, null, options);
|
||||
}
|
||||
|
||||
function jiraPost(urlPath, body, options) {
|
||||
return jiraRequest('POST', urlPath, body, options);
|
||||
}
|
||||
|
||||
function jiraPut(urlPath, body, options) {
|
||||
return jiraRequest('PUT', urlPath, body, options);
|
||||
}
|
||||
|
||||
function jiraDelete(urlPath, options) {
|
||||
return jiraRequest('DELETE', urlPath, null, options);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// High-level Jira operations — all comply with Charter requirements
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a single issue by key using a GET with explicit ?fields= parameter.
|
||||
* Charter requires all GETs to specify fields — /rest/api/2/field is forbidden.
|
||||
*
|
||||
* NOTE: For syncing multiple tickets, prefer searchIssuesByKeys() which uses
|
||||
* a single bulk JQL search instead of one GET per issue.
|
||||
*
|
||||
* @param {string} issueKey - e.g. "VULN-123"
|
||||
* @param {string[]} [fields] - Jira field names to return
|
||||
*/
|
||||
async function getIssue(issueKey, fields) {
|
||||
const jql = `key = "${issueKey}" AND project = ${JIRA_PROJECT_KEY}`;
|
||||
const result = await searchIssues(jql, { fields: fields || DEFAULT_FIELDS, maxResults: 1, startAt: 0 });
|
||||
if (result.ok && result.data.issues && result.data.issues.length > 0) {
|
||||
return { ok: true, data: result.data.issues[0] };
|
||||
}
|
||||
if (result.ok && (!result.data.issues || result.data.issues.length === 0)) {
|
||||
return { ok: false, status: 404, body: 'Issue not found' };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk-fetch issues by their keys using a single JQL search.
|
||||
* This is the Charter-compliant way to sync multiple tickets — avoids
|
||||
* querying one issue at a time.
|
||||
*
|
||||
* @param {string[]} issueKeys - Array of Jira issue keys
|
||||
* @param {object} [opts] - { fields, maxResults }
|
||||
*/
|
||||
async function searchIssuesByKeys(issueKeys, opts) {
|
||||
if (!issueKeys || issueKeys.length === 0) {
|
||||
return { ok: true, data: { total: 0, issues: [] } };
|
||||
}
|
||||
|
||||
// Build JQL: key in (KEY-1, KEY-2, ...) — Charter requires project+updated
|
||||
// or similar, but key-based search is inherently scoped. We add updated
|
||||
// clause for compliance.
|
||||
const keyList = issueKeys.map(k => `"${k}"`).join(', ');
|
||||
const jql = `key in (${keyList}) AND updated >= -24h AND project = ${JIRA_PROJECT_KEY}`;
|
||||
const fields = (opts && opts.fields) || DEFAULT_FIELDS;
|
||||
const maxResults = Math.min((opts && opts.maxResults) || 1000, 1000);
|
||||
|
||||
return searchIssues(jql, { fields, maxResults, startAt: 0 });
|
||||
}
|
||||
|
||||
/**
|
||||
* Search issues via JQL (POST to /rest/api/2/search).
|
||||
* Charter requirements enforced:
|
||||
* - fields array is always specified (never omitted)
|
||||
* - maxResults capped at 1000
|
||||
*
|
||||
* The caller is responsible for including an &updated clause in the JQL
|
||||
* for recurring/scheduled queries.
|
||||
*
|
||||
* @param {string} jql - JQL query string
|
||||
* @param {object} [opts] - { startAt, maxResults, fields }
|
||||
*/
|
||||
async function searchIssues(jql, opts) {
|
||||
const startAt = (opts && opts.startAt) || 0;
|
||||
const maxResults = Math.min((opts && opts.maxResults) || 1000, 1000);
|
||||
const fields = (opts && opts.fields) || DEFAULT_FIELDS;
|
||||
|
||||
const fieldList = encodeURIComponent(fields.join(','));
|
||||
const encodedJql = encodeURIComponent(jql);
|
||||
const queryString = `?jql=${encodedJql}&fields=${fieldList}&maxResults=${maxResults}&startAt=${startAt}`;
|
||||
const res = await jiraGet('/rest/api/2/search' + queryString);
|
||||
if (res.status === 200) {
|
||||
return { ok: true, data: JSON.parse(res.body) };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Jira issue (POST, subject to 2s delay).
|
||||
* @param {object} fields - Jira issue fields object
|
||||
*/
|
||||
async function createIssue(fields) {
|
||||
const res = await jiraPost('/rest/api/2/issue', { fields });
|
||||
if (res.status === 201) {
|
||||
return { ok: true, data: JSON.parse(res.body) };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a single Jira issue (PUT, subject to 2s delay).
|
||||
* Charter forbids bulk updates — issues must be updated one at a time.
|
||||
* @param {string} issueKey
|
||||
* @param {object} fields - Fields to update
|
||||
*/
|
||||
async function updateIssue(issueKey, fields) {
|
||||
const res = await jiraPut(
|
||||
`/rest/api/2/issue/${encodeURIComponent(issueKey)}`,
|
||||
{ fields }
|
||||
);
|
||||
// Jira returns 204 on successful update
|
||||
if (res.status === 204) {
|
||||
return { ok: true };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a comment to an existing issue (POST, subject to 2s delay).
|
||||
*/
|
||||
async function addComment(issueKey, commentBody) {
|
||||
const res = await jiraPost(
|
||||
`/rest/api/2/issue/${encodeURIComponent(issueKey)}/comment`,
|
||||
{ body: commentBody }
|
||||
);
|
||||
if (res.status === 201) {
|
||||
return { ok: true, data: JSON.parse(res.body) };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Transition an issue to a new status (POST, subject to 2s delay).
|
||||
* @param {string} issueKey
|
||||
* @param {string} transitionId
|
||||
*/
|
||||
async function transitionIssue(issueKey, transitionId) {
|
||||
const res = await jiraPost(
|
||||
`/rest/api/2/issue/${encodeURIComponent(issueKey)}/transitions`,
|
||||
{ transition: { id: transitionId } }
|
||||
);
|
||||
if (res.status === 204) {
|
||||
return { ok: true };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available transitions for an issue.
|
||||
* Uses GET with explicit fields parameter (transitions endpoint returns
|
||||
* transitions by default, but we include the query param for compliance).
|
||||
*/
|
||||
async function getTransitions(issueKey) {
|
||||
const res = await jiraGet(
|
||||
`/rest/api/2/issue/${encodeURIComponent(issueKey)}/transitions`
|
||||
);
|
||||
if (res.status === 200) {
|
||||
return { ok: true, data: JSON.parse(res.body) };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body, rateLimited: res.rateLimited };
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connectivity — calls /rest/api/2/myself to verify credentials.
|
||||
* This is a lightweight GET that returns the authenticated user.
|
||||
*/
|
||||
async function testConnection() {
|
||||
try {
|
||||
const res = await jiraGet('/rest/api/2/myself');
|
||||
if (res.status === 200) {
|
||||
const user = JSON.parse(res.body);
|
||||
return { ok: true, user: { name: user.name, displayName: user.displayName, emailAddress: user.emailAddress } };
|
||||
}
|
||||
return { ok: false, status: res.status, body: res.body };
|
||||
} catch (err) {
|
||||
return { ok: false, error: err.message };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isConfigured,
|
||||
jiraRequest,
|
||||
jiraGet,
|
||||
jiraPost,
|
||||
jiraPut,
|
||||
jiraDelete,
|
||||
getIssue,
|
||||
searchIssuesByKeys,
|
||||
searchIssues,
|
||||
createIssue,
|
||||
updateIssue,
|
||||
addComment,
|
||||
transitionIssue,
|
||||
getTransitions,
|
||||
testConnection,
|
||||
getRateLimitStatus,
|
||||
DEFAULT_FIELDS,
|
||||
JIRA_PROJECT_KEY,
|
||||
JIRA_ISSUE_TYPE
|
||||
};
|
||||
@@ -1,96 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Migration script: Add audit_logs table
|
||||
// Run: node migrate-audit-log.js
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const fs = require('fs');
|
||||
|
||||
const DB_FILE = './cve_database.db';
|
||||
const BACKUP_FILE = `./cve_database_backup_${Date.now()}.db`;
|
||||
|
||||
function run(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function(err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function migrate() {
|
||||
console.log('╔════════════════════════════════════════════════════════╗');
|
||||
console.log('║ CVE Database Migration: Add Audit Logs ║');
|
||||
console.log('╚════════════════════════════════════════════════════════╝\n');
|
||||
|
||||
if (!fs.existsSync(DB_FILE)) {
|
||||
console.log('❌ Database not found. Run setup.js for fresh install.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Backup database
|
||||
console.log('📦 Creating backup...');
|
||||
fs.copyFileSync(DB_FILE, BACKUP_FILE);
|
||||
console.log(` ✓ Backup saved to: ${BACKUP_FILE}\n`);
|
||||
|
||||
const db = new sqlite3.Database(DB_FILE);
|
||||
|
||||
try {
|
||||
// Check if table already exists
|
||||
const exists = await get(db,
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='audit_logs'"
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
console.log('⏭️ audit_logs table already exists, nothing to do.');
|
||||
} else {
|
||||
console.log('1️⃣ Creating audit_logs table...');
|
||||
await run(db, `
|
||||
CREATE TABLE audit_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
username VARCHAR(50) NOT NULL,
|
||||
action VARCHAR(50) NOT NULL,
|
||||
entity_type VARCHAR(50) NOT NULL,
|
||||
entity_id VARCHAR(100),
|
||||
details TEXT,
|
||||
ip_address VARCHAR(45),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
console.log(' ✓ Table created');
|
||||
|
||||
console.log('2️⃣ Creating indexes...');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_audit_user_id ON audit_logs(user_id)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_audit_action ON audit_logs(action)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_audit_entity_type ON audit_logs(entity_type)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_audit_created_at ON audit_logs(created_at)');
|
||||
console.log(' ✓ Indexes created');
|
||||
}
|
||||
|
||||
console.log('\n╔════════════════════════════════════════════════════════╗');
|
||||
console.log('║ MIGRATION COMPLETE! ║');
|
||||
console.log('╚════════════════════════════════════════════════════════╝');
|
||||
console.log('\n📋 Summary:');
|
||||
console.log(' ✓ audit_logs table ready');
|
||||
console.log(`\n💾 Backup saved: ${BACKUP_FILE}`);
|
||||
console.log('\n🚀 Restart your server to apply changes.\n');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Migration failed:', error.message);
|
||||
console.log(`\n🔄 To restore from backup: cp ${BACKUP_FILE} ${DB_FILE}`);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
migrate();
|
||||
@@ -1,289 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Migration script: v1.0.0 -> v1.1.0
|
||||
// Adds: users, sessions tables, multi-vendor support, vendor column in documents
|
||||
// Run: node migrate-to-1.1.js
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const bcrypt = require('bcryptjs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const DB_FILE = './cve_database.db';
|
||||
const BACKUP_FILE = `./cve_database_backup_${Date.now()}.db`;
|
||||
|
||||
async function migrate() {
|
||||
console.log('╔════════════════════════════════════════════════════════╗');
|
||||
console.log('║ CVE Database Migration: v1.0.0 → v1.1.0 ║');
|
||||
console.log('╚════════════════════════════════════════════════════════╝\n');
|
||||
|
||||
// Check if database exists
|
||||
if (!fs.existsSync(DB_FILE)) {
|
||||
console.log('❌ Database not found. Run setup.js for fresh install.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Backup database
|
||||
console.log('📦 Creating backup...');
|
||||
fs.copyFileSync(DB_FILE, BACKUP_FILE);
|
||||
console.log(` ✓ Backup saved to: ${BACKUP_FILE}\n`);
|
||||
|
||||
const db = new sqlite3.Database(DB_FILE);
|
||||
|
||||
try {
|
||||
// Run migrations in sequence
|
||||
await addUsersTable(db);
|
||||
await addSessionsTable(db);
|
||||
await addVendorToDocuments(db);
|
||||
await updateCvesConstraint(db);
|
||||
await createDefaultAdmin(db);
|
||||
await updateView(db);
|
||||
|
||||
console.log('\n╔════════════════════════════════════════════════════════╗');
|
||||
console.log('║ MIGRATION COMPLETE! ║');
|
||||
console.log('╚════════════════════════════════════════════════════════╝');
|
||||
console.log('\n📋 Summary:');
|
||||
console.log(' ✓ Users table added');
|
||||
console.log(' ✓ Sessions table added');
|
||||
console.log(' ✓ Vendor column added to documents');
|
||||
console.log(' ✓ Multi-vendor constraint applied to cves');
|
||||
console.log(' ✓ Default admin user created (admin/admin123)');
|
||||
console.log(`\n💾 Backup saved: ${BACKUP_FILE}`);
|
||||
console.log('\n🚀 Restart your server to apply changes.\n');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Migration failed:', error.message);
|
||||
console.log(`\n🔄 To restore from backup: cp ${BACKUP_FILE} ${DB_FILE}`);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
function run(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function(err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function all(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function addUsersTable(db) {
|
||||
console.log('1️⃣ Adding users table...');
|
||||
|
||||
const exists = await get(db,
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='users'"
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
console.log(' ⏭️ Users table already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
await run(db, `
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL DEFAULT 'viewer',
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login TIMESTAMP,
|
||||
CHECK (role IN ('admin', 'editor', 'viewer'))
|
||||
)
|
||||
`);
|
||||
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_users_username ON users(username)');
|
||||
console.log(' ✓ Users table created');
|
||||
}
|
||||
|
||||
async function addSessionsTable(db) {
|
||||
console.log('2️⃣ Adding sessions table...');
|
||||
|
||||
const exists = await get(db,
|
||||
"SELECT name FROM sqlite_master WHERE type='table' AND name='sessions'"
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
console.log(' ⏭️ Sessions table already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
await run(db, `
|
||||
CREATE TABLE sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id VARCHAR(255) UNIQUE NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
`);
|
||||
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_sessions_session_id ON sessions(session_id)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at)');
|
||||
console.log(' ✓ Sessions table created');
|
||||
}
|
||||
|
||||
async function addVendorToDocuments(db) {
|
||||
console.log('3️⃣ Adding vendor column to documents...');
|
||||
|
||||
// Check if vendor column exists
|
||||
const columns = await all(db, "PRAGMA table_info(documents)");
|
||||
const hasVendor = columns.some(col => col.name === 'vendor');
|
||||
|
||||
if (hasVendor) {
|
||||
console.log(' ⏭️ Vendor column already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
// Add vendor column
|
||||
await run(db, "ALTER TABLE documents ADD COLUMN vendor VARCHAR(100)");
|
||||
|
||||
// Populate vendor from the cves table based on cve_id
|
||||
await run(db, `
|
||||
UPDATE documents
|
||||
SET vendor = (
|
||||
SELECT c.vendor
|
||||
FROM cves c
|
||||
WHERE c.cve_id = documents.cve_id
|
||||
LIMIT 1
|
||||
)
|
||||
WHERE vendor IS NULL
|
||||
`);
|
||||
|
||||
// Set default for any remaining nulls
|
||||
await run(db, "UPDATE documents SET vendor = 'Unknown' WHERE vendor IS NULL");
|
||||
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_doc_vendor ON documents(vendor)');
|
||||
console.log(' ✓ Vendor column added and populated');
|
||||
}
|
||||
|
||||
async function updateCvesConstraint(db) {
|
||||
console.log('4️⃣ Updating CVEs table for multi-vendor support...');
|
||||
|
||||
// Check current schema
|
||||
const tableInfo = await get(db,
|
||||
"SELECT sql FROM sqlite_master WHERE type='table' AND name='cves'"
|
||||
);
|
||||
|
||||
if (tableInfo.sql.includes('UNIQUE(cve_id, vendor)')) {
|
||||
console.log(' ⏭️ Multi-vendor constraint already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
// SQLite doesn't support ALTER CONSTRAINT, so we need to rebuild the table
|
||||
console.log(' 📋 Rebuilding table with new constraint...');
|
||||
|
||||
// Create new table with correct schema
|
||||
await run(db, `
|
||||
CREATE TABLE cves_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
severity VARCHAR(20) NOT NULL,
|
||||
description TEXT,
|
||||
published_date DATE,
|
||||
status VARCHAR(50) DEFAULT 'Open',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(cve_id, vendor)
|
||||
)
|
||||
`);
|
||||
|
||||
// Copy data
|
||||
await run(db, `
|
||||
INSERT INTO cves_new (id, cve_id, vendor, severity, description, published_date, status, created_at, updated_at)
|
||||
SELECT id, cve_id, vendor, severity, description, published_date, status, created_at, updated_at
|
||||
FROM cves
|
||||
`);
|
||||
|
||||
// Drop old table
|
||||
await run(db, 'DROP TABLE cves');
|
||||
|
||||
// Rename new table
|
||||
await run(db, 'ALTER TABLE cves_new RENAME TO cves');
|
||||
|
||||
// Recreate indexes
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_cve_id ON cves(cve_id)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_vendor ON cves(vendor)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_severity ON cves(severity)');
|
||||
await run(db, 'CREATE INDEX IF NOT EXISTS idx_status ON cves(status)');
|
||||
|
||||
console.log(' ✓ Multi-vendor constraint applied');
|
||||
}
|
||||
|
||||
async function createDefaultAdmin(db) {
|
||||
console.log('5️⃣ Creating default admin user...');
|
||||
|
||||
const exists = await get(db, "SELECT id FROM users WHERE username = 'admin'");
|
||||
|
||||
if (exists) {
|
||||
console.log(' ⏭️ Admin user already exists, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash('admin123', 10);
|
||||
|
||||
await run(db, `
|
||||
INSERT INTO users (username, email, password_hash, role, is_active)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
`, ['admin', 'admin@localhost', passwordHash, 'admin', 1]);
|
||||
|
||||
console.log(' ✓ Admin user created (admin/admin123)');
|
||||
}
|
||||
|
||||
async function updateView(db) {
|
||||
console.log('6️⃣ Updating document status view...');
|
||||
|
||||
// Drop old view if exists
|
||||
await run(db, 'DROP VIEW IF EXISTS cve_document_status');
|
||||
|
||||
// Create updated view with multi-vendor support
|
||||
await run(db, `
|
||||
CREATE VIEW cve_document_status AS
|
||||
SELECT
|
||||
c.id as record_id,
|
||||
c.cve_id,
|
||||
c.vendor,
|
||||
c.severity,
|
||||
c.status,
|
||||
COUNT(DISTINCT d.id) as total_documents,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) as advisory_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'email' THEN d.id END) as email_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'screenshot' THEN d.id END) as screenshot_count,
|
||||
CASE
|
||||
WHEN COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) > 0
|
||||
THEN 'Complete'
|
||||
ELSE 'Missing Required Docs'
|
||||
END as compliance_status
|
||||
FROM cves c
|
||||
LEFT JOIN documents d ON c.cve_id = d.cve_id AND c.vendor = d.vendor
|
||||
GROUP BY c.id, c.cve_id, c.vendor, c.severity, c.status
|
||||
`);
|
||||
|
||||
console.log(' ✓ View updated');
|
||||
}
|
||||
|
||||
// Run migration
|
||||
migrate();
|
||||
@@ -1,39 +0,0 @@
|
||||
// Migration: Add jira_tickets table
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting JIRA tickets migration...');
|
||||
|
||||
db.serialize(() => {
|
||||
// Create jira_tickets table
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS jira_tickets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id TEXT NOT NULL,
|
||||
vendor TEXT NOT NULL,
|
||||
ticket_key TEXT NOT NULL,
|
||||
url TEXT,
|
||||
summary TEXT,
|
||||
status TEXT DEFAULT 'Open' CHECK(status IN ('Open', 'In Progress', 'Closed')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (cve_id, vendor) REFERENCES cves(cve_id, vendor) ON DELETE CASCADE
|
||||
)
|
||||
`, (err) => {
|
||||
if (err) console.error('Error creating table:', err);
|
||||
else console.log('✓ jira_tickets table created');
|
||||
});
|
||||
|
||||
// Create indexes
|
||||
db.run('CREATE INDEX IF NOT EXISTS idx_jira_tickets_cve ON jira_tickets(cve_id, vendor)');
|
||||
db.run('CREATE INDEX IF NOT EXISTS idx_jira_tickets_status ON jira_tickets(status)');
|
||||
|
||||
console.log('✓ Indexes created');
|
||||
});
|
||||
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
@@ -1,128 +0,0 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const db = new sqlite3.Database('./cve_database.db');
|
||||
|
||||
console.log('🔄 Starting database migration for multi-vendor support...\n');
|
||||
|
||||
db.serialize(() => {
|
||||
// Backup existing data
|
||||
console.log('📦 Creating backup tables...');
|
||||
db.run(`CREATE TABLE IF NOT EXISTS cves_backup AS SELECT * FROM cves`, (err) => {
|
||||
if (err) console.error('Backup error:', err);
|
||||
else console.log('✓ CVEs backed up');
|
||||
});
|
||||
|
||||
db.run(`CREATE TABLE IF NOT EXISTS documents_backup AS SELECT * FROM documents`, (err) => {
|
||||
if (err) console.error('Backup error:', err);
|
||||
else console.log('✓ Documents backed up');
|
||||
});
|
||||
|
||||
// Drop old table
|
||||
console.log('\n🗑️ Dropping old cves table...');
|
||||
db.run(`DROP TABLE IF EXISTS cves`, (err) => {
|
||||
if (err) {
|
||||
console.error('Drop error:', err);
|
||||
return;
|
||||
}
|
||||
console.log('✓ Old table dropped');
|
||||
|
||||
// Create new table with UNIQUE(cve_id, vendor) instead of UNIQUE(cve_id)
|
||||
console.log('\n🏗️ Creating new cves table with multi-vendor support...');
|
||||
db.run(`
|
||||
CREATE TABLE cves (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
severity VARCHAR(20) NOT NULL,
|
||||
description TEXT,
|
||||
published_date DATE,
|
||||
status VARCHAR(50) DEFAULT 'Open',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(cve_id, vendor)
|
||||
)
|
||||
`, (err) => {
|
||||
if (err) {
|
||||
console.error('Create error:', err);
|
||||
return;
|
||||
}
|
||||
console.log('✓ New table created with UNIQUE(cve_id, vendor)');
|
||||
|
||||
// Restore data
|
||||
console.log('\n📥 Restoring data...');
|
||||
db.run(`INSERT INTO cves SELECT * FROM cves_backup`, (err) => {
|
||||
if (err) {
|
||||
console.error('Restore error:', err);
|
||||
return;
|
||||
}
|
||||
console.log('✓ Data restored');
|
||||
|
||||
// Recreate indexes
|
||||
console.log('\n🔍 Creating indexes...');
|
||||
db.run(`CREATE INDEX idx_cve_id ON cves(cve_id)`, () => {
|
||||
console.log('✓ Index: idx_cve_id');
|
||||
});
|
||||
db.run(`CREATE INDEX idx_vendor ON cves(vendor)`, () => {
|
||||
console.log('✓ Index: idx_vendor');
|
||||
});
|
||||
db.run(`CREATE INDEX idx_severity ON cves(severity)`, () => {
|
||||
console.log('✓ Index: idx_severity');
|
||||
});
|
||||
db.run(`CREATE INDEX idx_status ON cves(status)`, () => {
|
||||
console.log('✓ Index: idx_status');
|
||||
});
|
||||
|
||||
// Update view
|
||||
console.log('\n👁️ Updating cve_document_status view...');
|
||||
db.run(`DROP VIEW IF EXISTS cve_document_status`, (err) => {
|
||||
if (err) console.error('Drop view error:', err);
|
||||
|
||||
db.run(`
|
||||
CREATE VIEW cve_document_status AS
|
||||
SELECT
|
||||
c.id as record_id,
|
||||
c.cve_id,
|
||||
c.vendor,
|
||||
c.severity,
|
||||
c.status,
|
||||
COUNT(DISTINCT d.id) as total_documents,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) as advisory_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'email' THEN d.id END) as email_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'screenshot' THEN d.id END) as screenshot_count,
|
||||
CASE
|
||||
WHEN COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) > 0
|
||||
THEN 'Complete'
|
||||
ELSE 'Missing Required Docs'
|
||||
END as compliance_status
|
||||
FROM cves c
|
||||
LEFT JOIN documents d ON c.cve_id = d.cve_id AND c.vendor = d.vendor
|
||||
GROUP BY c.id, c.cve_id, c.vendor, c.severity, c.status
|
||||
`, (err) => {
|
||||
if (err) {
|
||||
console.error('Create view error:', err);
|
||||
} else {
|
||||
console.log('✓ View recreated');
|
||||
}
|
||||
|
||||
console.log('\n✅ Migration complete!');
|
||||
console.log('\n📊 Summary:');
|
||||
|
||||
db.get('SELECT COUNT(*) as count FROM cves', (err, row) => {
|
||||
if (!err) console.log(` Total CVE entries: ${row.count}`);
|
||||
|
||||
db.get('SELECT COUNT(DISTINCT cve_id) as count FROM cves', (err, row) => {
|
||||
if (!err) console.log(` Unique CVE IDs: ${row.count}`);
|
||||
|
||||
console.log('\n💡 Next steps:');
|
||||
console.log(' 1. Restart backend: pkill -f "node server.js" && node server.js &');
|
||||
console.log(' 2. Replace frontend/src/App.js with multi-vendor version');
|
||||
console.log(' 3. Test by adding same CVE with multiple vendors\n');
|
||||
|
||||
db.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
41
backend/migrations/README.md
Normal file
41
backend/migrations/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Database Migrations
|
||||
|
||||
These migration scripts were used to evolve the database schema during development. **They are NOT needed for fresh deployments** — `setup.js` contains the complete v1.0.0 schema.
|
||||
|
||||
These are retained for reference and for upgrading existing deployments that were set up before v1.0.0.
|
||||
|
||||
## Schema Migrations (run in order for existing deployments)
|
||||
|
||||
| Script | Purpose |
|
||||
|--------|---------|
|
||||
| `add_ivanti_sync_table.js` | Creates `ivanti_sync_state` table for tracking Ivanti sync status |
|
||||
| `add_ivanti_findings_tables.js` | Creates `ivanti_findings_cache`, `ivanti_finding_notes`, `ivanti_counts_cache`, `ivanti_finding_overrides` tables |
|
||||
| `add_ivanti_counts_history_table.js` | Creates `ivanti_counts_history` table for trend chart data |
|
||||
| `add_ivanti_todo_queue_table.js` | Creates `ivanti_todo_queue` table for FP/Archer workflow queuing |
|
||||
| `add_todo_queue_hostname.js` | Adds `hostname` column to `ivanti_todo_queue` |
|
||||
| `add_todo_queue_ip_address.js` | Adds `ip_address` column to `ivanti_todo_queue` |
|
||||
| `add_fp_submissions_table.js` | Creates `ivanti_fp_submissions` table for false positive workflow tracking |
|
||||
| `add_fp_submission_editing.js` | Adds `lifecycle_status`, `ivanti_workflow_batch_uuid`, `updated_at` columns and `ivanti_fp_submission_history` table |
|
||||
| `add_knowledge_base_table.js` | Creates `knowledge_base` table for KB article storage |
|
||||
| `add_user_groups.js` | Adds `user_group` column to `users` table with validation triggers |
|
||||
| `add_created_by_columns.js` | Adds `created_by` column to `compliance_notes` and `knowledge_base` tables |
|
||||
| `add_compliance_tables.js` | Creates `compliance_uploads`, `compliance_items`, `compliance_notes` tables |
|
||||
| `add_compliance_notes_group_id.js` | Adds `group_id` column to `compliance_notes` for multi-metric note grouping |
|
||||
| `add_archer_tickets_table.js` | Creates `archer_tickets` table for Archer exception tracking |
|
||||
| `add_archer_tickets_timestamps.js` | Adds `created_at` and `updated_at` columns to `archer_tickets` |
|
||||
| `add_jira_sync_columns.js` | Adds Jira sync-related columns to `jira_tickets` |
|
||||
| `add_card_workflow_type.js` | Adds `CARD` to `workflow_type` CHECK constraint on `ivanti_todo_queue` |
|
||||
| `add_granite_workflow_type.js` | Adds `GRANITE` to `workflow_type` CHECK constraint on `ivanti_todo_queue` |
|
||||
| `add_finding_archive_tables.js` | Creates `ivanti_finding_archives` and `ivanti_archive_transitions` tables |
|
||||
| `add_closed_gone_state.js` | Adds `CLOSED_GONE` to `current_state` CHECK constraint on `ivanti_finding_archives` |
|
||||
| `add_sync_anomaly_tables.js` | Creates `ivanti_sync_anomaly_log` and `ivanti_finding_bu_history` tables |
|
||||
| `add_atlas_action_plans_cache.js` | Creates `atlas_action_plans_cache` table for Atlas API caching |
|
||||
| `add_return_classification.js` | Adds `return_classification_json` column to `ivanti_sync_anomaly_log` |
|
||||
|
||||
## Data Migrations (one-time backfills)
|
||||
|
||||
| Script | Purpose |
|
||||
|--------|---------|
|
||||
| `backfill_anomaly_log.js` | Synthesizes anomaly log entries from existing archive transitions for historical chart data |
|
||||
| `backfill_return_classification.js` | Populates `return_classification_json` for existing anomaly rows with returned findings. Supports `--force` flag to re-run. |
|
||||
| `reclassify_bu_roundtrips.js` | Reclassifies archive transitions that were BU reassignment round-trips (archived then returned within 14 days) from the default `severity_score_drift` to `bu_reassignment` |
|
||||
37
backend/migrations/add_atlas_action_plans_cache.js
Normal file
37
backend/migrations/add_atlas_action_plans_cache.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// Migration: Add atlas_action_plans_cache table
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting Atlas action plans cache migration...');
|
||||
|
||||
db.serialize(() => {
|
||||
// Cache table — one row per host, holding cached Atlas action plan status
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS atlas_action_plans_cache (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
host_id INTEGER NOT NULL UNIQUE,
|
||||
has_action_plan INTEGER NOT NULL DEFAULT 0,
|
||||
plan_count INTEGER NOT NULL DEFAULT 0,
|
||||
plans_json TEXT NOT NULL DEFAULT '[]',
|
||||
synced_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`, (err) => {
|
||||
if (err) console.error('Error creating atlas_action_plans_cache table:', err);
|
||||
else console.log('✓ atlas_action_plans_cache table created');
|
||||
});
|
||||
|
||||
db.run(`
|
||||
CREATE INDEX IF NOT EXISTS idx_atlas_cache_host_id
|
||||
ON atlas_action_plans_cache(host_id)
|
||||
`, (err) => {
|
||||
if (err) console.error('Error creating host_id index:', err);
|
||||
else console.log('✓ idx_atlas_cache_host_id index created');
|
||||
});
|
||||
});
|
||||
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
130
backend/migrations/add_closed_gone_state.js
Normal file
130
backend/migrations/add_closed_gone_state.js
Normal file
@@ -0,0 +1,130 @@
|
||||
// Migration: Add CLOSED_GONE state to ivanti_finding_archives
|
||||
//
|
||||
// The archive table tracks findings that disappear from the Open findings set.
|
||||
// Previously it only tracked: ARCHIVED → RETURNED → CLOSED.
|
||||
//
|
||||
// This migration adds a CLOSED_GONE state for findings that were confirmed
|
||||
// in the Ivanti Closed set but then disappeared from it on a subsequent sync.
|
||||
// This closes a visibility gap where findings could vanish from the Closed API
|
||||
// results (e.g., due to VRR rescore below the severity threshold) without
|
||||
// being tracked.
|
||||
//
|
||||
// SQLite does not support ALTER TABLE to modify CHECK constraints, so this
|
||||
// migration recreates the table with the expanded constraint.
|
||||
//
|
||||
// Safe to re-run — uses IF NOT EXISTS and checks for existing data.
|
||||
//
|
||||
// Usage: node backend/migrations/add_closed_gone_state.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting CLOSED_GONE state migration...');
|
||||
|
||||
function run(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function all(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function migrate() {
|
||||
// Check if the table already has the CLOSED_GONE state
|
||||
const tableInfo = await all("SELECT sql FROM sqlite_master WHERE name='ivanti_finding_archives'");
|
||||
if (tableInfo.length > 0 && tableInfo[0].sql.includes('CLOSED_GONE')) {
|
||||
console.log('✓ ivanti_finding_archives already has CLOSED_GONE state — skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
if (tableInfo.length === 0) {
|
||||
// Table doesn't exist yet — create it fresh with the new constraint
|
||||
await run(`
|
||||
CREATE TABLE ivanti_finding_archives (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL UNIQUE,
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
ip_address TEXT NOT NULL DEFAULT '',
|
||||
current_state TEXT NOT NULL CHECK(current_state IN ('ARCHIVED','RETURNED','CLOSED','CLOSED_GONE')),
|
||||
last_severity REAL NOT NULL DEFAULT 0,
|
||||
first_archived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_transition_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
console.log('✓ Created ivanti_finding_archives with CLOSED_GONE state');
|
||||
return;
|
||||
}
|
||||
|
||||
// Table exists but needs the constraint updated — recreate with data migration
|
||||
console.log(' Recreating table with expanded CHECK constraint...');
|
||||
|
||||
await run('BEGIN TRANSACTION');
|
||||
try {
|
||||
// 1. Rename existing table
|
||||
await run('ALTER TABLE ivanti_finding_archives RENAME TO ivanti_finding_archives_old');
|
||||
|
||||
// 2. Create new table with expanded constraint
|
||||
await run(`
|
||||
CREATE TABLE ivanti_finding_archives (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL UNIQUE,
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
ip_address TEXT NOT NULL DEFAULT '',
|
||||
current_state TEXT NOT NULL CHECK(current_state IN ('ARCHIVED','RETURNED','CLOSED','CLOSED_GONE')),
|
||||
last_severity REAL NOT NULL DEFAULT 0,
|
||||
first_archived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_transition_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
// 3. Copy data
|
||||
await run(`
|
||||
INSERT INTO ivanti_finding_archives
|
||||
(id, finding_id, finding_title, host_name, ip_address, current_state,
|
||||
last_severity, first_archived_at, last_transition_at, created_at)
|
||||
SELECT id, finding_id, finding_title, host_name, ip_address, current_state,
|
||||
last_severity, first_archived_at, last_transition_at, created_at
|
||||
FROM ivanti_finding_archives_old
|
||||
`);
|
||||
|
||||
// 4. Recreate indexes
|
||||
await run('CREATE INDEX IF NOT EXISTS idx_archive_finding_id ON ivanti_finding_archives(finding_id)');
|
||||
await run('CREATE INDEX IF NOT EXISTS idx_archive_current_state ON ivanti_finding_archives(current_state)');
|
||||
|
||||
// 5. Drop old table
|
||||
await run('DROP TABLE ivanti_finding_archives_old');
|
||||
|
||||
await run('COMMIT');
|
||||
console.log('✓ ivanti_finding_archives updated with CLOSED_GONE state');
|
||||
} catch (err) {
|
||||
await run('ROLLBACK').catch(() => {});
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
migrate()
|
||||
.then(() => {
|
||||
console.log('Migration complete.');
|
||||
db.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Migration failed:', err);
|
||||
db.close();
|
||||
process.exit(1);
|
||||
});
|
||||
29
backend/migrations/add_compliance_notes_group_id.js
Normal file
29
backend/migrations/add_compliance_notes_group_id.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// Migration: Add group_id column to compliance_notes table
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting add_compliance_notes_group_id migration...');
|
||||
|
||||
db.serialize(() => {
|
||||
db.run(`ALTER TABLE compliance_notes ADD COLUMN group_id TEXT`, (err) => {
|
||||
if (err) console.error('Error adding group_id column:', err);
|
||||
else console.log('✓ group_id column added to compliance_notes');
|
||||
});
|
||||
|
||||
db.run(`CREATE INDEX IF NOT EXISTS idx_compliance_notes_group ON compliance_notes(group_id)`, (err) => {
|
||||
if (err) console.error('Error creating group_id index:', err);
|
||||
else console.log('✓ idx_compliance_notes_group created');
|
||||
});
|
||||
|
||||
db.run(`UPDATE compliance_notes SET group_id = 'legacy-' || id WHERE group_id IS NULL`, (err) => {
|
||||
if (err) console.error('Error backfilling group_id:', err);
|
||||
else console.log('✓ Existing rows backfilled with legacy group_id');
|
||||
});
|
||||
});
|
||||
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
94
backend/migrations/add_fp_submission_editing.js
Normal file
94
backend/migrations/add_fp_submission_editing.js
Normal file
@@ -0,0 +1,94 @@
|
||||
// Migration: Add FP submission editing support (lifecycle status, batch UUID, history table)
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting FP submission editing migration...');
|
||||
|
||||
db.serialize(() => {
|
||||
// Add lifecycle_status column to ivanti_fp_submissions
|
||||
// Wrapped in try/catch style via callback — SQLite throws if column already exists
|
||||
db.run(
|
||||
`ALTER TABLE ivanti_fp_submissions ADD COLUMN lifecycle_status TEXT NOT NULL DEFAULT 'submitted' CHECK(lifecycle_status IN ('submitted', 'approved', 'rejected', 'rework', 'resubmitted'))`,
|
||||
(err) => {
|
||||
if (err) {
|
||||
if (err.message.includes('duplicate column')) {
|
||||
console.log('✓ lifecycle_status column already exists');
|
||||
} else {
|
||||
console.error('Error adding lifecycle_status column:', err.message);
|
||||
}
|
||||
} else {
|
||||
console.log('✓ lifecycle_status column added');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Add ivanti_workflow_batch_uuid column
|
||||
db.run(
|
||||
`ALTER TABLE ivanti_fp_submissions ADD COLUMN ivanti_workflow_batch_uuid TEXT`,
|
||||
(err) => {
|
||||
if (err) {
|
||||
if (err.message.includes('duplicate column')) {
|
||||
console.log('✓ ivanti_workflow_batch_uuid column already exists');
|
||||
} else {
|
||||
console.error('Error adding ivanti_workflow_batch_uuid column:', err.message);
|
||||
}
|
||||
} else {
|
||||
console.log('✓ ivanti_workflow_batch_uuid column added');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Add updated_at column (SQLite requires constant defaults for ALTER TABLE, so default to NULL)
|
||||
db.run(
|
||||
`ALTER TABLE ivanti_fp_submissions ADD COLUMN updated_at DATETIME DEFAULT NULL`,
|
||||
(err) => {
|
||||
if (err) {
|
||||
if (err.message.includes('duplicate column')) {
|
||||
console.log('✓ updated_at column already exists');
|
||||
} else {
|
||||
console.error('Error adding updated_at column:', err.message);
|
||||
}
|
||||
} else {
|
||||
console.log('✓ updated_at column added');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Create submission history table
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS ivanti_fp_submission_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
submission_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
change_type TEXT NOT NULL CHECK(change_type IN (
|
||||
'created', 'fields_updated', 'findings_added',
|
||||
'attachments_added', 'status_changed'
|
||||
)),
|
||||
change_details_json TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (submission_id) REFERENCES ivanti_fp_submissions(id) ON DELETE CASCADE
|
||||
)
|
||||
`, (err) => {
|
||||
if (err) console.error('Error creating history table:', err.message);
|
||||
else console.log('✓ ivanti_fp_submission_history table created');
|
||||
});
|
||||
|
||||
// Create index on submission_id for history lookups
|
||||
db.run(
|
||||
`CREATE INDEX IF NOT EXISTS idx_fp_history_submission ON ivanti_fp_submission_history(submission_id)`,
|
||||
(err) => {
|
||||
if (err) console.error('Error creating history index:', err.message);
|
||||
else console.log('✓ idx_fp_history_submission index created');
|
||||
}
|
||||
);
|
||||
|
||||
console.log('✓ Migration statements queued');
|
||||
});
|
||||
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
80
backend/migrations/add_granite_workflow_type.js
Normal file
80
backend/migrations/add_granite_workflow_type.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// Migration: Add GRANITE to workflow_type CHECK constraint on ivanti_todo_queue
|
||||
// SQLite cannot ALTER a CHECK constraint, so this recreates the table.
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting add_granite_workflow_type migration...');
|
||||
|
||||
db.serialize(() => {
|
||||
db.run('PRAGMA foreign_keys = OFF', (err) => {
|
||||
if (err) console.error('PRAGMA error:', err);
|
||||
});
|
||||
|
||||
db.run('BEGIN TRANSACTION', (err) => {
|
||||
if (err) { console.error('BEGIN error:', err); return; }
|
||||
});
|
||||
|
||||
db.run(`
|
||||
CREATE TABLE ivanti_todo_queue_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
finding_id TEXT NOT NULL,
|
||||
finding_title TEXT,
|
||||
cves_json TEXT,
|
||||
ip_address TEXT,
|
||||
hostname TEXT,
|
||||
vendor TEXT NOT NULL,
|
||||
workflow_type TEXT NOT NULL CHECK(workflow_type IN ('FP', 'Archer', 'CARD', 'GRANITE')),
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'complete')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
)
|
||||
`, (err) => {
|
||||
if (err) console.error('Error creating new table:', err);
|
||||
else console.log('✓ ivanti_todo_queue_new created');
|
||||
});
|
||||
|
||||
db.run(
|
||||
'INSERT INTO ivanti_todo_queue_new SELECT id, user_id, finding_id, finding_title, cves_json, ip_address, hostname, vendor, workflow_type, status, created_at, updated_at FROM ivanti_todo_queue',
|
||||
(err) => {
|
||||
if (err) console.error('Error copying data:', err);
|
||||
else console.log('✓ Data copied');
|
||||
}
|
||||
);
|
||||
|
||||
db.run('DROP TABLE ivanti_todo_queue', (err) => {
|
||||
if (err) console.error('Error dropping old table:', err);
|
||||
else console.log('✓ Old table dropped');
|
||||
});
|
||||
|
||||
db.run(
|
||||
'ALTER TABLE ivanti_todo_queue_new RENAME TO ivanti_todo_queue',
|
||||
(err) => {
|
||||
if (err) console.error('Error renaming table:', err);
|
||||
else console.log('✓ Table renamed');
|
||||
}
|
||||
);
|
||||
|
||||
db.run(
|
||||
'CREATE INDEX IF NOT EXISTS idx_todo_queue_user ON ivanti_todo_queue(user_id, status)',
|
||||
(err) => {
|
||||
if (err) console.error('Error creating index:', err);
|
||||
else console.log('✓ Index recreated');
|
||||
}
|
||||
);
|
||||
|
||||
db.run('COMMIT', (err) => {
|
||||
if (err) console.error('COMMIT error:', err);
|
||||
else console.log('✓ Transaction committed');
|
||||
});
|
||||
|
||||
db.run('PRAGMA foreign_keys = ON', () => {}); // FIXME: Callback does not handle the error parameter (should be `(err) => { if (err) ... }`)
|
||||
});
|
||||
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
63
backend/migrations/add_jira_sync_columns.js
Normal file
63
backend/migrations/add_jira_sync_columns.js
Normal file
@@ -0,0 +1,63 @@
|
||||
// Migration: Add Jira API sync columns to jira_tickets table
|
||||
// Adds jira_id, jira_status, and last_synced_at columns to support
|
||||
// live synchronization with Jira Data Center REST API.
|
||||
// Idempotent — safe to run multiple times.
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting Jira sync columns migration...');
|
||||
|
||||
const newColumns = [
|
||||
{ name: 'jira_id', sql: 'ALTER TABLE jira_tickets ADD COLUMN jira_id TEXT' },
|
||||
{ name: 'jira_status', sql: 'ALTER TABLE jira_tickets ADD COLUMN jira_status TEXT' },
|
||||
{ name: 'last_synced_at', sql: 'ALTER TABLE jira_tickets ADD COLUMN last_synced_at DATETIME' }
|
||||
];
|
||||
|
||||
db.all('PRAGMA table_info(jira_tickets)', (err, columns) => {
|
||||
if (err) {
|
||||
console.error('Could not inspect jira_tickets:', err.message);
|
||||
console.log('Run migrate_jira_tickets.js first to create the table.');
|
||||
db.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const existingNames = new Set(columns.map(c => c.name));
|
||||
let pending = 0;
|
||||
|
||||
db.serialize(() => {
|
||||
newColumns.forEach(({ name, sql }) => {
|
||||
if (existingNames.has(name)) {
|
||||
console.log(`✓ jira_tickets.${name} already exists — skipping`);
|
||||
} else {
|
||||
pending++;
|
||||
db.run(sql, (runErr) => {
|
||||
if (runErr) {
|
||||
console.error(`✗ Failed to add ${name}:`, runErr.message);
|
||||
} else {
|
||||
console.log(`✓ Added jira_tickets.${name}`);
|
||||
}
|
||||
pending--;
|
||||
if (pending === 0) finish();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Create index on jira_id for lookups
|
||||
db.run('CREATE INDEX IF NOT EXISTS idx_jira_tickets_jira_id ON jira_tickets(jira_id)', (idxErr) => {
|
||||
if (idxErr) console.error('Index error:', idxErr.message);
|
||||
else console.log('✓ jira_id index created');
|
||||
});
|
||||
|
||||
if (pending === 0) finish();
|
||||
});
|
||||
});
|
||||
|
||||
function finish() {
|
||||
db.close(() => {
|
||||
console.log('Migration complete!');
|
||||
});
|
||||
}
|
||||
57
backend/migrations/add_return_classification.js
Normal file
57
backend/migrations/add_return_classification.js
Normal file
@@ -0,0 +1,57 @@
|
||||
// Migration: Add return_classification_json column to ivanti_sync_anomaly_log
|
||||
//
|
||||
// Stores the classification breakdown for returned findings (e.g., how many
|
||||
// returned due to BU reassignment back to team, severity re-escalation, etc.)
|
||||
//
|
||||
// Safe to re-run — uses ALTER TABLE with IF NOT EXISTS pattern.
|
||||
//
|
||||
// Usage: node backend/migrations/add_return_classification.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting return classification migration...');
|
||||
|
||||
function run(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function all(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function migrate() {
|
||||
// Check if column already exists
|
||||
const columns = await all(`PRAGMA table_info(ivanti_sync_anomaly_log)`);
|
||||
const hasColumn = columns.some(c => c.name === 'return_classification_json');
|
||||
|
||||
if (!hasColumn) {
|
||||
await run(`ALTER TABLE ivanti_sync_anomaly_log ADD COLUMN return_classification_json TEXT NOT NULL DEFAULT '{}'`);
|
||||
console.log('✓ Added return_classification_json column to ivanti_sync_anomaly_log');
|
||||
} else {
|
||||
console.log('✓ return_classification_json column already exists — skipping');
|
||||
}
|
||||
}
|
||||
|
||||
migrate()
|
||||
.then(() => {
|
||||
console.log('Migration complete.');
|
||||
db.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Migration failed:', err);
|
||||
db.close();
|
||||
process.exit(1);
|
||||
});
|
||||
90
backend/migrations/add_sync_anomaly_tables.js
Normal file
90
backend/migrations/add_sync_anomaly_tables.js
Normal file
@@ -0,0 +1,90 @@
|
||||
// Migration: Add sync anomaly detection and BU drift monitoring tables
|
||||
//
|
||||
// Creates two new tables:
|
||||
// - ivanti_sync_anomaly_log — stores one row per sync cycle with the
|
||||
// anomaly summary breakdown (count deltas, classification, significance).
|
||||
// - ivanti_finding_bu_history — records BU change events detected on
|
||||
// individual findings across syncs.
|
||||
//
|
||||
// Safe to re-run — uses CREATE TABLE IF NOT EXISTS and CREATE INDEX IF NOT EXISTS.
|
||||
//
|
||||
// Usage: node backend/migrations/add_sync_anomaly_tables.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const dbPath = path.join(__dirname, '..', 'cve_database.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
console.log('Starting sync anomaly tables migration...');
|
||||
|
||||
function run(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function all(sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function migrate() {
|
||||
// 1. Create ivanti_sync_anomaly_log table
|
||||
await run(`
|
||||
CREATE TABLE IF NOT EXISTS ivanti_sync_anomaly_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
sync_timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
open_count_delta INTEGER NOT NULL DEFAULT 0,
|
||||
closed_count_delta INTEGER NOT NULL DEFAULT 0,
|
||||
newly_archived_count INTEGER NOT NULL DEFAULT 0,
|
||||
returned_count INTEGER NOT NULL DEFAULT 0,
|
||||
classification_json TEXT NOT NULL DEFAULT '{}',
|
||||
is_significant INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
console.log('✓ ivanti_sync_anomaly_log table ready');
|
||||
|
||||
// 2. Create ivanti_finding_bu_history table
|
||||
await run(`
|
||||
CREATE TABLE IF NOT EXISTS ivanti_finding_bu_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL,
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
previous_bu TEXT NOT NULL,
|
||||
new_bu TEXT NOT NULL,
|
||||
detected_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
console.log('✓ ivanti_finding_bu_history table ready');
|
||||
|
||||
// 3. Create indexes
|
||||
await run('CREATE INDEX IF NOT EXISTS idx_anomaly_sync_timestamp ON ivanti_sync_anomaly_log(sync_timestamp)');
|
||||
console.log('✓ idx_anomaly_sync_timestamp index ready');
|
||||
|
||||
await run('CREATE INDEX IF NOT EXISTS idx_bu_history_finding_id ON ivanti_finding_bu_history(finding_id)');
|
||||
console.log('✓ idx_bu_history_finding_id index ready');
|
||||
|
||||
await run('CREATE INDEX IF NOT EXISTS idx_bu_history_detected_at ON ivanti_finding_bu_history(detected_at)');
|
||||
console.log('✓ idx_bu_history_detected_at index ready');
|
||||
}
|
||||
|
||||
migrate()
|
||||
.then(() => {
|
||||
console.log('Migration complete.');
|
||||
db.close();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Migration failed:', err);
|
||||
db.close();
|
||||
process.exit(1);
|
||||
});
|
||||
160
backend/migrations/backfill_anomaly_log.js
Normal file
160
backend/migrations/backfill_anomaly_log.js
Normal file
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env node
|
||||
// backfill_anomaly_log.js — One-time backfill of ivanti_sync_anomaly_log
|
||||
//
|
||||
// Synthesizes anomaly log entries from existing ivanti_archive_transitions
|
||||
// and ivanti_counts_history data so the archive activity sparkline on the
|
||||
// Findings Trend chart has historical data to display.
|
||||
//
|
||||
// Safe to run multiple times — checks for existing rows before inserting.
|
||||
//
|
||||
// Usage: node backend/migrations/backfill_anomaly_log.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
const DB_PATH = path.join(__dirname, '..', 'cve_database.db');
|
||||
|
||||
function dbAll(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dbGet(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const db = new sqlite3.Database(DB_PATH);
|
||||
|
||||
// Check if anomaly log already has data
|
||||
const existing = await dbGet(db, 'SELECT COUNT(*) as cnt FROM ivanti_sync_anomaly_log');
|
||||
if (existing.cnt > 0) {
|
||||
console.log(`ivanti_sync_anomaly_log already has ${existing.cnt} rows — skipping backfill.`);
|
||||
console.log('To force re-run, delete existing rows first:');
|
||||
console.log(' sqlite3 backend/cve_database.db "DELETE FROM ivanti_sync_anomaly_log;"');
|
||||
db.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get archive transitions grouped by date
|
||||
const transitions = await dbAll(db,
|
||||
`SELECT DATE(transitioned_at) as date,
|
||||
to_state,
|
||||
reason,
|
||||
COUNT(*) as cnt
|
||||
FROM ivanti_archive_transitions
|
||||
GROUP BY date, to_state, reason
|
||||
ORDER BY date`
|
||||
);
|
||||
|
||||
// Get counts history (last snapshot per day) for delta computation
|
||||
const countsRows = await dbAll(db,
|
||||
`SELECT date, open_count, closed_count FROM (
|
||||
SELECT DATE(recorded_at) AS date,
|
||||
open_count, closed_count,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY DATE(recorded_at)
|
||||
ORDER BY recorded_at DESC
|
||||
) AS rn
|
||||
FROM ivanti_counts_history
|
||||
) WHERE rn = 1
|
||||
ORDER BY date ASC`
|
||||
);
|
||||
|
||||
// Build a map of date -> { open_count, closed_count }
|
||||
const countsMap = {};
|
||||
for (const row of countsRows) {
|
||||
countsMap[row.date] = { open: row.open_count, closed: row.closed_count };
|
||||
}
|
||||
|
||||
// Build per-date anomaly summaries from transitions
|
||||
const dateMap = {};
|
||||
for (const t of transitions) {
|
||||
if (!dateMap[t.date]) {
|
||||
dateMap[t.date] = { archived: 0, returned: 0, classification: {} };
|
||||
}
|
||||
const entry = dateMap[t.date];
|
||||
|
||||
if (t.to_state === 'ARCHIVED') {
|
||||
entry.archived += t.cnt;
|
||||
// All pre-feature transitions have reason 'severity_score_drift'
|
||||
// but from the investigation we know the 04/24 batch was mostly
|
||||
// BU reassignment. We can't retroactively classify without the
|
||||
// Ivanti API, so we label them as 'unclassified' (pre-feature).
|
||||
entry.classification.unclassified = (entry.classification.unclassified || 0) + t.cnt;
|
||||
} else if (t.to_state === 'RETURNED') {
|
||||
entry.returned += t.cnt;
|
||||
}
|
||||
// CLOSED transitions are not archive events — they're findings
|
||||
// confirmed in the closed set, so we don't count them as archived.
|
||||
}
|
||||
|
||||
// Compute deltas and insert rows
|
||||
const dates = Object.keys(dateMap).sort();
|
||||
let inserted = 0;
|
||||
|
||||
for (const date of dates) {
|
||||
const entry = dateMap[date];
|
||||
const counts = countsMap[date];
|
||||
|
||||
// Find the previous day's counts for delta computation
|
||||
const dateIdx = countsRows.findIndex(r => r.date === date);
|
||||
let openDelta = 0;
|
||||
let closedDelta = 0;
|
||||
|
||||
if (counts && dateIdx > 0) {
|
||||
const prev = countsRows[dateIdx - 1];
|
||||
openDelta = counts.open - prev.open_count;
|
||||
closedDelta = counts.closed - prev.closed_count;
|
||||
}
|
||||
|
||||
const isSignificant = entry.archived > 5 ? 1 : 0;
|
||||
const classificationJson = JSON.stringify(entry.classification);
|
||||
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_sync_anomaly_log
|
||||
(sync_timestamp, open_count_delta, closed_count_delta,
|
||||
newly_archived_count, returned_count, classification_json, is_significant)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
`${date}T23:59:00`,
|
||||
openDelta,
|
||||
closedDelta,
|
||||
entry.archived,
|
||||
entry.returned,
|
||||
classificationJson,
|
||||
isSignificant,
|
||||
]
|
||||
);
|
||||
inserted++;
|
||||
|
||||
const sigLabel = isSignificant ? ' [SIGNIFICANT]' : '';
|
||||
console.log(` ${date}: ${entry.archived} archived, ${entry.returned} returned, delta open=${openDelta} closed=${closedDelta}${sigLabel}`);
|
||||
}
|
||||
|
||||
console.log(`\nBackfill complete: ${inserted} anomaly log entries created.`);
|
||||
db.close();
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Fatal error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
165
backend/migrations/backfill_return_classification.js
Normal file
165
backend/migrations/backfill_return_classification.js
Normal file
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env node
|
||||
// backfill_return_classification.js
|
||||
//
|
||||
// Retroactively populates return_classification_json for existing anomaly log
|
||||
// rows that have returned_count > 0 but an empty return classification.
|
||||
//
|
||||
// For each such row, looks at archive transitions that went ARCHIVED → RETURNED
|
||||
// on that date, then finds the *prior* archive reason (the most recent
|
||||
// transition to ARCHIVED for that same archive record) to determine why the
|
||||
// finding originally left — which tells us why it came back.
|
||||
//
|
||||
// Safe to run multiple times — only updates rows with empty classification.
|
||||
//
|
||||
// Usage: node backend/migrations/backfill_return_classification.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
const DB_PATH = path.join(__dirname, '..', 'cve_database.db');
|
||||
|
||||
function dbAll(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dbGet(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const db = new sqlite3.Database(DB_PATH);
|
||||
|
||||
// Find anomaly log rows that have returned findings but no return classification
|
||||
const rows = await dbAll(db,
|
||||
`SELECT id, sync_timestamp, returned_count, return_classification_json
|
||||
FROM ivanti_sync_anomaly_log
|
||||
WHERE returned_count > 0
|
||||
ORDER BY sync_timestamp ASC`
|
||||
);
|
||||
|
||||
if (rows.length === 0) {
|
||||
console.log('No anomaly log rows with returned findings found — nothing to backfill.');
|
||||
db.close();
|
||||
return;
|
||||
}
|
||||
|
||||
const force = process.argv.includes('--force');
|
||||
let updated = 0;
|
||||
let skipped = 0;
|
||||
|
||||
for (const row of rows) {
|
||||
// Skip if already has a non-empty classification (unless --force)
|
||||
if (!force) {
|
||||
let existing = {};
|
||||
try { existing = JSON.parse(row.return_classification_json || '{}'); } catch (_) {}
|
||||
const hasData = Object.values(existing).some(v => v > 0);
|
||||
if (hasData) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Find the date of this anomaly row
|
||||
const date = row.sync_timestamp.split('T')[0].split(' ')[0];
|
||||
|
||||
// Find all ARCHIVED → RETURNED transitions on this date
|
||||
const returnTransitions = await dbAll(db,
|
||||
`SELECT archive_id
|
||||
FROM ivanti_archive_transitions
|
||||
WHERE to_state = 'RETURNED'
|
||||
AND DATE(transitioned_at) = ?`,
|
||||
[date]
|
||||
);
|
||||
|
||||
if (returnTransitions.length === 0) {
|
||||
// No transitions found for this date — try a wider window (±1 day)
|
||||
// since sync_timestamp and transitioned_at might not align exactly
|
||||
const wider = await dbAll(db,
|
||||
`SELECT archive_id
|
||||
FROM ivanti_archive_transitions
|
||||
WHERE to_state = 'RETURNED'
|
||||
AND DATE(transitioned_at) BETWEEN DATE(?, '-1 day') AND DATE(?, '+1 day')`,
|
||||
[date, date]
|
||||
);
|
||||
if (wider.length === 0) {
|
||||
console.log(` ${date}: ${row.returned_count} returned but no matching transitions found — skipping`);
|
||||
continue;
|
||||
}
|
||||
returnTransitions.push(...wider);
|
||||
}
|
||||
|
||||
// For each returned finding, look up the prior archive reason
|
||||
const classification = { bu_reassignment: 0, severity_drift: 0, closed_on_platform: 0, decommissioned: 0 };
|
||||
const seen = new Set();
|
||||
|
||||
for (const rt of returnTransitions) {
|
||||
if (seen.has(rt.archive_id)) continue;
|
||||
seen.add(rt.archive_id);
|
||||
|
||||
// Find the most recent ARCHIVED transition *before* this return
|
||||
// (the reason it was archived before it came back)
|
||||
const archiveTransition = await dbGet(db,
|
||||
`SELECT reason FROM ivanti_archive_transitions
|
||||
WHERE archive_id = ? AND to_state = 'ARCHIVED'
|
||||
AND transitioned_at <= (
|
||||
SELECT transitioned_at FROM ivanti_archive_transitions
|
||||
WHERE archive_id = ? AND to_state = 'RETURNED'
|
||||
AND DATE(transitioned_at) BETWEEN DATE(?, '-1 day') AND DATE(?, '+1 day')
|
||||
ORDER BY transitioned_at DESC LIMIT 1
|
||||
)
|
||||
ORDER BY transitioned_at DESC LIMIT 1`,
|
||||
[rt.archive_id, rt.archive_id, date, date]
|
||||
);
|
||||
|
||||
if (archiveTransition && archiveTransition.reason) {
|
||||
const reasonKey = archiveTransition.reason.split(':')[0];
|
||||
if (reasonKey in classification) {
|
||||
classification[reasonKey]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const classificationJson = JSON.stringify(classification);
|
||||
await dbRun(db,
|
||||
`UPDATE ivanti_sync_anomaly_log
|
||||
SET return_classification_json = ?
|
||||
WHERE id = ?`,
|
||||
[classificationJson, row.id]
|
||||
);
|
||||
|
||||
const parts = Object.entries(classification)
|
||||
.filter(([, v]) => v > 0)
|
||||
.map(([k, v]) => `${v} ${k}`);
|
||||
const breakdown = parts.length > 0 ? parts.join(', ') : 'unclassified';
|
||||
|
||||
console.log(` ${date}: ${row.returned_count} returned — ${breakdown}`);
|
||||
updated++;
|
||||
}
|
||||
|
||||
console.log(`\nBackfill complete: ${updated} rows updated, ${skipped} already had data.`);
|
||||
db.close();
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Fatal error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
102
backend/migrations/reclassify_bu_roundtrips.js
Normal file
102
backend/migrations/reclassify_bu_roundtrips.js
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env node
|
||||
// reclassify_bu_roundtrips.js
|
||||
//
|
||||
// Reclassifies archive transitions that were part of a BU reassignment
|
||||
// round-trip. These are findings that were archived (disappeared from sync)
|
||||
// and then returned within a short window — indicating they were temporarily
|
||||
// reassigned to a different BU and then reassigned back.
|
||||
//
|
||||
// The original drift checker couldn't classify these correctly because by the
|
||||
// time it queried Ivanti, the findings had already been reassigned back to
|
||||
// the expected BUs.
|
||||
//
|
||||
// After running this, re-run backfill_return_classification.js to update
|
||||
// the anomaly log with the corrected reasons.
|
||||
//
|
||||
// Usage: node backend/migrations/reclassify_bu_roundtrips.js
|
||||
|
||||
const path = require('path');
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
|
||||
const DB_PATH = path.join(__dirname, '..', 'cve_database.db');
|
||||
|
||||
// Findings that were archived and returned within this many days are
|
||||
// considered BU reassignment round-trips
|
||||
const ROUNDTRIP_WINDOW_DAYS = 14;
|
||||
|
||||
function dbAll(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => {
|
||||
if (err) reject(err);
|
||||
else resolve(rows || []);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const db = new sqlite3.Database(DB_PATH);
|
||||
|
||||
// Find archive transitions where the finding was archived and then returned
|
||||
// within the roundtrip window, and the archive reason is still the default
|
||||
// severity_score_drift placeholder
|
||||
const roundtrips = await dbAll(db, `
|
||||
SELECT
|
||||
t_arch.id AS archive_transition_id,
|
||||
t_arch.archive_id,
|
||||
a.finding_id,
|
||||
a.finding_title,
|
||||
t_arch.reason AS current_reason,
|
||||
DATE(t_arch.transitioned_at) AS archived_date,
|
||||
DATE(t_ret.transitioned_at) AS returned_date,
|
||||
JULIANDAY(t_ret.transitioned_at) - JULIANDAY(t_arch.transitioned_at) AS days_between
|
||||
FROM ivanti_archive_transitions t_arch
|
||||
JOIN ivanti_finding_archives a ON a.id = t_arch.archive_id
|
||||
JOIN ivanti_archive_transitions t_ret
|
||||
ON t_ret.archive_id = t_arch.archive_id
|
||||
AND t_ret.to_state = 'RETURNED'
|
||||
AND t_ret.transitioned_at > t_arch.transitioned_at
|
||||
WHERE t_arch.to_state = 'ARCHIVED'
|
||||
AND t_arch.reason = 'severity_score_drift'
|
||||
AND (JULIANDAY(t_ret.transitioned_at) - JULIANDAY(t_arch.transitioned_at)) BETWEEN 0 AND ?
|
||||
ORDER BY t_arch.transitioned_at DESC
|
||||
`, [ROUNDTRIP_WINDOW_DAYS]);
|
||||
|
||||
if (roundtrips.length === 0) {
|
||||
console.log('No BU reassignment round-trips found to reclassify.');
|
||||
db.close();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Found ${roundtrips.length} archive transitions to reclassify as bu_reassignment:\n`);
|
||||
|
||||
let updated = 0;
|
||||
for (const rt of roundtrips) {
|
||||
console.log(` Finding ${rt.finding_id}: archived ${rt.archived_date}, returned ${rt.returned_date} (${Math.round(rt.days_between)}d) — ${rt.current_reason} → bu_reassignment`);
|
||||
|
||||
await dbRun(db,
|
||||
`UPDATE ivanti_archive_transitions SET reason = 'bu_reassignment' WHERE id = ?`,
|
||||
[rt.archive_transition_id]
|
||||
);
|
||||
updated++;
|
||||
}
|
||||
|
||||
console.log(`\nReclassified ${updated} transitions.`);
|
||||
console.log('\nNow run the return classification backfill to update anomaly log rows:');
|
||||
console.log(' node backend/migrations/backfill_return_classification.js');
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Fatal error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
587
backend/routes/atlas.js
Normal file
587
backend/routes/atlas.js
Normal file
@@ -0,0 +1,587 @@
|
||||
// Atlas InfoSec Action Plans Routes
|
||||
// Proxies CRUD operations to the Atlas API and maintains a local SQLite cache
|
||||
// for fast badge rendering on the ReportingPage.
|
||||
|
||||
const express = require('express');
|
||||
const { requireGroup } = require('../middleware/auth');
|
||||
const logAudit = require('../helpers/auditLog');
|
||||
const { isConfigured, atlasGet, atlasPut, atlasPatch, atlasPost } = require('../helpers/atlasApi');
|
||||
|
||||
const VALID_PLAN_TYPES = ['decommission', 'remediation', 'false_positive', 'risk_acceptance', 'scan_exclusion'];
|
||||
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DB helpers — promise wrappers for callback-based SQLite API
|
||||
// ---------------------------------------------------------------------------
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) { if (err) reject(err); else resolve(this); });
|
||||
});
|
||||
}
|
||||
|
||||
function dbGet(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => { if (err) reject(err); else resolve(row); });
|
||||
});
|
||||
}
|
||||
|
||||
function dbAll(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(sql, params, (err, rows) => { if (err) reject(err); else resolve(rows || []); });
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pure aggregation function — exported for testability
|
||||
// ---------------------------------------------------------------------------
|
||||
function aggregateAtlasMetrics(rows) {
|
||||
const result = {
|
||||
totalHosts: rows.length,
|
||||
hostsWithPlans: 0,
|
||||
hostsWithoutPlans: 0,
|
||||
plansByType: {},
|
||||
plansByStatus: {},
|
||||
totalPlans: 0
|
||||
};
|
||||
|
||||
for (const row of rows) {
|
||||
if (row.has_action_plan === 1) {
|
||||
result.hostsWithPlans++;
|
||||
} else {
|
||||
result.hostsWithoutPlans++;
|
||||
}
|
||||
|
||||
let plans;
|
||||
try {
|
||||
plans = JSON.parse(row.plans_json);
|
||||
} catch (e) {
|
||||
// Invalid JSON — skip plan details for this row
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!Array.isArray(plans)) continue;
|
||||
|
||||
for (const plan of plans) {
|
||||
result.totalPlans++;
|
||||
|
||||
if (plan.plan_type) {
|
||||
result.plansByType[plan.plan_type] = (result.plansByType[plan.plan_type] || 0) + 1;
|
||||
}
|
||||
|
||||
if (plan.status) {
|
||||
result.plansByStatus[plan.status] = (result.plansByStatus[plan.status] || 0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Router factory
|
||||
// ---------------------------------------------------------------------------
|
||||
function createAtlasRouter(db, requireAuth) {
|
||||
const router = express.Router();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /metrics
|
||||
// Return aggregated Atlas metrics for chart rendering.
|
||||
// Auth: any authenticated user
|
||||
//
|
||||
// Response 200:
|
||||
// { totalHosts: number, hostsWithPlans: number, hostsWithoutPlans: number,
|
||||
// plansByType: { [type: string]: number }, plansByStatus: { [status: string]: number },
|
||||
// totalPlans: number }
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 500: { error: string } — DB query failure
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/metrics', requireAuth(db), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const rows = await dbAll(db,
|
||||
`SELECT has_action_plan, plans_json FROM atlas_action_plans_cache`
|
||||
);
|
||||
const metrics = aggregateAtlasMetrics(rows);
|
||||
res.json(metrics);
|
||||
} catch (err) {
|
||||
console.error('[Atlas] Error fetching metrics:', err.message);
|
||||
res.status(500).json({ error: 'Failed to fetch Atlas metrics.' });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /status
|
||||
// Return all cached Atlas rows for badge rendering.
|
||||
// Auth: any authenticated user
|
||||
//
|
||||
// Response 200:
|
||||
// [ { host_id: number, has_action_plan: 0|1, plan_count: number, synced_at: string }, ... ]
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 500: { error: string } — DB query failure
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/status', requireAuth(db), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const rows = await dbAll(db,
|
||||
`SELECT host_id, has_action_plan, plan_count, synced_at FROM atlas_action_plans_cache`
|
||||
);
|
||||
res.json(rows);
|
||||
} catch (err) {
|
||||
console.error('[Atlas] Error fetching status:', err.message);
|
||||
res.status(500).json({ error: 'Failed to fetch Atlas status.' });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /sync
|
||||
// Sync Atlas action plan data for all hosts found in the Ivanti cache.
|
||||
// Auth: Admin or Standard_User
|
||||
//
|
||||
// Request body: none
|
||||
// Response 200:
|
||||
// { synced: number, withPlans: number, failed: number }
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 500: { error: string } — sync failure or Ivanti cache parse error
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/sync', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Read Ivanti findings cache and extract unique non-null hostIds
|
||||
const cacheRow = await dbGet(db, `SELECT findings_json FROM ivanti_findings_cache WHERE id = 1`);
|
||||
if (!cacheRow || !cacheRow.findings_json) {
|
||||
return res.json({ synced: 0, withPlans: 0, failed: 0 });
|
||||
}
|
||||
|
||||
let findings;
|
||||
try {
|
||||
findings = JSON.parse(cacheRow.findings_json);
|
||||
} catch (parseErr) {
|
||||
return res.status(500).json({ error: 'Failed to parse Ivanti findings cache.' });
|
||||
}
|
||||
|
||||
const hostIdSet = new Set();
|
||||
for (const f of findings) {
|
||||
if (f.hostId != null && typeof f.hostId === 'number' && f.hostId > 0) {
|
||||
hostIdSet.add(f.hostId);
|
||||
}
|
||||
}
|
||||
const hostIds = [...hostIdSet];
|
||||
|
||||
if (hostIds.length === 0) {
|
||||
return res.json({ synced: 0, withPlans: 0, failed: 0 });
|
||||
}
|
||||
|
||||
// 2. Process hosts in batches of 5 concurrent requests
|
||||
let synced = 0;
|
||||
let withPlans = 0;
|
||||
let failed = 0;
|
||||
const BATCH_SIZE = 5;
|
||||
|
||||
for (let i = 0; i < hostIds.length; i += BATCH_SIZE) {
|
||||
const batch = hostIds.slice(i, i + BATCH_SIZE);
|
||||
const results = await Promise.allSettled(
|
||||
batch.map(async (hostId) => {
|
||||
const result = await atlasGet('/hosts/' + hostId + '/action-plans');
|
||||
return { hostId, result };
|
||||
})
|
||||
);
|
||||
|
||||
for (const settled of results) {
|
||||
if (settled.status === 'rejected') {
|
||||
failed++;
|
||||
console.warn('[Atlas Sync] Request failed for host:', settled.reason?.message || settled.reason);
|
||||
continue;
|
||||
}
|
||||
|
||||
const { hostId, result } = settled.value;
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let allPlans = [];
|
||||
let activePlans = [];
|
||||
try {
|
||||
const parsed = JSON.parse(result.body);
|
||||
// Atlas returns { active: [...], inactive: [...] }
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
activePlans = Array.isArray(parsed.active) ? parsed.active : [];
|
||||
const inactive = Array.isArray(parsed.inactive) ? parsed.inactive : [];
|
||||
allPlans = [...activePlans, ...inactive];
|
||||
} else if (Array.isArray(parsed)) {
|
||||
allPlans = parsed;
|
||||
activePlans = parsed;
|
||||
}
|
||||
} catch (e) {
|
||||
allPlans = [];
|
||||
activePlans = [];
|
||||
}
|
||||
|
||||
// Badge counts only active plans — inactive are historical
|
||||
const planCount = activePlans.length;
|
||||
const hasActionPlan = planCount > 0 ? 1 : 0;
|
||||
|
||||
try {
|
||||
await dbRun(db,
|
||||
`INSERT INTO atlas_action_plans_cache (host_id, has_action_plan, plan_count, plans_json, synced_at)
|
||||
VALUES (?, ?, ?, ?, datetime('now'))
|
||||
ON CONFLICT(host_id) DO UPDATE SET
|
||||
has_action_plan = excluded.has_action_plan,
|
||||
plan_count = excluded.plan_count,
|
||||
plans_json = excluded.plans_json,
|
||||
synced_at = excluded.synced_at`,
|
||||
[hostId, hasActionPlan, planCount, JSON.stringify(allPlans)]
|
||||
);
|
||||
} catch (dbErr) {
|
||||
console.error('[Atlas Sync] DB upsert failed for host', hostId, ':', dbErr.message);
|
||||
}
|
||||
|
||||
synced++;
|
||||
if (hasActionPlan) withPlans++;
|
||||
} else {
|
||||
failed++;
|
||||
console.warn(`[Atlas Sync] Non-2xx response for host ${hostId}: status ${result.status}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Log audit entry
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'ATLAS_SYNC',
|
||||
entityType: 'atlas_action_plans',
|
||||
entityId: null,
|
||||
details: { synced, withPlans, failed, totalHosts: hostIds.length },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ synced, withPlans, failed });
|
||||
} catch (err) {
|
||||
console.error('[Atlas Sync] Unexpected error:', err.message);
|
||||
res.status(500).json({ error: 'Atlas sync failed: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /hosts/:hostId/action-plans
|
||||
// Proxy to Atlas API — returns live action plan data for a single host.
|
||||
// Auth: any authenticated user
|
||||
//
|
||||
// Params: hostId (positive integer)
|
||||
// Response 2xx: proxied Atlas response body (parsed JSON or raw)
|
||||
// Response 400: { error: string } — invalid hostId
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 502: { error: string } — Atlas API unreachable
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/hosts/:hostId/action-plans', requireAuth(db), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
const hostId = parseInt(req.params.hostId, 10);
|
||||
if (!Number.isInteger(hostId) || hostId <= 0) {
|
||||
return res.status(400).json({ error: 'hostId must be a positive integer' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await atlasGet('/hosts/' + hostId + '/action-plans');
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
body = result.body;
|
||||
}
|
||||
res.status(result.status).json(body);
|
||||
} else {
|
||||
// Forward non-2xx Atlas responses to the client
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
res.status(result.status).json(errorBody);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Atlas] GET action-plans failed for host', hostId, ':', err.message);
|
||||
res.status(502).json({ error: 'Failed to reach Atlas API: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// PUT /hosts/:hostId/action-plans
|
||||
// Create a new action plan for a host.
|
||||
// Auth: Admin or Standard_User
|
||||
//
|
||||
// Params: hostId (positive integer)
|
||||
// Request body:
|
||||
// { plan_type: string (one of VALID_PLAN_TYPES), commit_date: string (YYYY-MM-DD),
|
||||
// qualys_id?: string, active_host_findings_id?: string,
|
||||
// jira_vnr?: string, archer_exc?: string }
|
||||
// Response 2xx: proxied Atlas response body
|
||||
// Response 400: { error: string } — invalid hostId, plan_type, or commit_date
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 502: { error: string } — Atlas API unreachable
|
||||
// -----------------------------------------------------------------------
|
||||
router.put('/hosts/:hostId/action-plans', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
const hostId = parseInt(req.params.hostId, 10);
|
||||
if (!Number.isInteger(hostId) || hostId <= 0) {
|
||||
return res.status(400).json({ error: 'hostId must be a positive integer' });
|
||||
}
|
||||
|
||||
const { plan_type, commit_date } = req.body || {};
|
||||
|
||||
if (!plan_type || !VALID_PLAN_TYPES.includes(plan_type)) {
|
||||
return res.status(400).json({ error: 'plan_type must be one of: ' + VALID_PLAN_TYPES.join(', ') });
|
||||
}
|
||||
|
||||
if (!commit_date || !DATE_PATTERN.test(commit_date)) {
|
||||
return res.status(400).json({ error: 'commit_date must be a valid YYYY-MM-DD date string' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await atlasPut('/hosts/' + hostId + '/action-plans', req.body);
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'ATLAS_CREATE_PLAN',
|
||||
entityType: 'atlas_action_plan',
|
||||
entityId: String(hostId),
|
||||
details: { hostId, plan_type, commit_date },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
body = result.body;
|
||||
}
|
||||
res.status(result.status).json(body);
|
||||
} else {
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
res.status(result.status).json(errorBody);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Atlas] PUT action-plans failed for host', hostId, ':', err.message);
|
||||
res.status(502).json({ error: 'Failed to reach Atlas API: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// PATCH /hosts/:hostId/action-plans
|
||||
// Update an existing action plan for a host.
|
||||
// Auth: Admin or Standard_User
|
||||
//
|
||||
// Params: hostId (positive integer)
|
||||
// Request body:
|
||||
// { action_plan_id: string (non-empty), updates: object (non-null, non-array) }
|
||||
// Response 2xx: proxied Atlas response body
|
||||
// Response 400: { error: string } — invalid hostId, action_plan_id, or updates
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 502: { error: string } — Atlas API unreachable
|
||||
// -----------------------------------------------------------------------
|
||||
router.patch('/hosts/:hostId/action-plans', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
const hostId = parseInt(req.params.hostId, 10);
|
||||
if (!Number.isInteger(hostId) || hostId <= 0) {
|
||||
return res.status(400).json({ error: 'hostId must be a positive integer' });
|
||||
}
|
||||
|
||||
const { action_plan_id, updates } = req.body || {};
|
||||
|
||||
if (!action_plan_id || typeof action_plan_id !== 'string' || action_plan_id.trim() === '') {
|
||||
return res.status(400).json({ error: 'action_plan_id is required and must be a non-empty string' });
|
||||
}
|
||||
|
||||
if (!updates || typeof updates !== 'object' || Array.isArray(updates)) {
|
||||
return res.status(400).json({ error: 'updates is required and must be an object' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await atlasPatch('/hosts/' + hostId + '/action-plans', req.body);
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'ATLAS_UPDATE_PLAN',
|
||||
entityType: 'atlas_action_plan',
|
||||
entityId: String(hostId),
|
||||
details: { hostId, action_plan_id },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
body = result.body;
|
||||
}
|
||||
res.status(result.status).json(body);
|
||||
} else {
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
res.status(result.status).json(errorBody);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Atlas] PATCH action-plans failed for host', hostId, ':', err.message);
|
||||
res.status(502).json({ error: 'Failed to reach Atlas API: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /hosts/bulk-action-plans
|
||||
// Create action plans for multiple hosts at once.
|
||||
// Auth: Admin or Standard_User
|
||||
//
|
||||
// Request body:
|
||||
// { host_ids: number[] (non-empty, positive integers),
|
||||
// plan_type: string (one of VALID_PLAN_TYPES),
|
||||
// commit_date: string (YYYY-MM-DD) }
|
||||
// Response 2xx: proxied Atlas response body
|
||||
// Response 400: { error: string } — invalid host_ids, plan_type, or commit_date
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 502: { error: string } — Atlas API unreachable
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/hosts/bulk-action-plans', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
const { host_ids, plan_type, commit_date } = req.body || {};
|
||||
|
||||
if (!Array.isArray(host_ids) || host_ids.length === 0) {
|
||||
return res.status(400).json({ error: 'host_ids must be a non-empty array of positive integers' });
|
||||
}
|
||||
|
||||
for (const id of host_ids) {
|
||||
if (!Number.isInteger(id) || id <= 0) {
|
||||
return res.status(400).json({ error: 'host_ids must be a non-empty array of positive integers' });
|
||||
}
|
||||
}
|
||||
|
||||
if (!plan_type || !VALID_PLAN_TYPES.includes(plan_type)) {
|
||||
return res.status(400).json({ error: 'plan_type must be one of: ' + VALID_PLAN_TYPES.join(', ') });
|
||||
}
|
||||
|
||||
if (!commit_date || !DATE_PATTERN.test(commit_date)) {
|
||||
return res.status(400).json({ error: 'commit_date must be a valid YYYY-MM-DD date string' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await atlasPost('/hosts/create-bulk-action-plans', req.body);
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
body = result.body;
|
||||
}
|
||||
res.status(result.status).json(body);
|
||||
} else {
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
res.status(result.status).json(errorBody);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Atlas] POST bulk-action-plans failed:', err.message);
|
||||
res.status(502).json({ error: 'Failed to reach Atlas API: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /hosts/vulnerabilities
|
||||
// Fetch active Ivanti vulnerabilities for multiple hosts from Atlas.
|
||||
// Used by the bulk action plan modal to populate the qualys_id dropdown.
|
||||
// Auth: any authenticated user
|
||||
//
|
||||
// Request body: { host_ids: number[] }
|
||||
// Response 2xx: proxied Atlas response body
|
||||
// Response 400: { error: string } — invalid host_ids
|
||||
// Response 503: { error: string } — Atlas not configured
|
||||
// Response 502: { error: string } — Atlas API unreachable
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/hosts/vulnerabilities', requireAuth(db), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'Atlas API is not configured. Check ATLAS_API_URL, ATLAS_API_USER, and ATLAS_API_PASS environment variables.' });
|
||||
}
|
||||
|
||||
const { host_ids } = req.body || {};
|
||||
|
||||
if (!Array.isArray(host_ids) || host_ids.length === 0) {
|
||||
return res.status(400).json({ error: 'host_ids must be a non-empty array of positive integers' });
|
||||
}
|
||||
|
||||
for (const id of host_ids) {
|
||||
if (!Number.isInteger(id) || id <= 0) {
|
||||
return res.status(400).json({ error: 'host_ids must be a non-empty array of positive integers' });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await atlasPost('/ivanti-vulnerabilities-by-host', { host_ids }, { timeout: 30000 });
|
||||
|
||||
console.log('[Atlas] POST /ivanti-vulnerabilities-by-host status:', result.status, 'body length:', result.body?.length);
|
||||
console.log('[Atlas] Response preview:', result.body?.substring(0, 500));
|
||||
|
||||
if (result.status >= 200 && result.status < 300) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
body = result.body;
|
||||
}
|
||||
res.status(result.status).json(body);
|
||||
} else {
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (e) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
res.status(result.status).json(errorBody);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Atlas] POST hosts/vulnerabilities failed:', err.message);
|
||||
res.status(502).json({ error: 'Failed to reach Atlas API: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
module.exports = createAtlasRouter;
|
||||
module.exports.aggregateAtlasMetrics = aggregateAtlasMetrics;
|
||||
@@ -258,6 +258,137 @@ function createAuthRouter(db, logAudit) {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/auth/profile
|
||||
*
|
||||
* Returns the full profile for the currently authenticated user.
|
||||
* Queries the database for up-to-date account details including
|
||||
* creation date and last login timestamp.
|
||||
*
|
||||
* @returns {object} 200 - { id, username, email, group, created_at, last_login }
|
||||
* @returns {object} 401 - { error: 'Account is disabled' } (clears session cookie)
|
||||
* @returns {object} 500 - { error: 'Failed to fetch profile' }
|
||||
*/
|
||||
router.get('/profile', requireAuth(db), async (req, res) => {
|
||||
try {
|
||||
const user = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
'SELECT id, username, email, user_group, created_at, last_login, is_active FROM users WHERE id = ?',
|
||||
[req.user.id],
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (!user || !user.is_active) {
|
||||
res.clearCookie('session_id');
|
||||
return res.status(401).json({ error: 'Account is disabled' });
|
||||
}
|
||||
|
||||
res.json({
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
group: user.user_group,
|
||||
created_at: user.created_at,
|
||||
last_login: user.last_login
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Profile fetch error:', err);
|
||||
res.status(500).json({ error: 'Failed to fetch profile' });
|
||||
}
|
||||
});
|
||||
|
||||
// Rate limiter for password change — 5 attempts per 15-minute window, keyed by session cookie
|
||||
const passwordChangeLimiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 5,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
keyGenerator: (req) => req.cookies?.session_id || req.ip,
|
||||
message: { error: 'Too many password change attempts. Please try again later.' }
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/auth/change-password
|
||||
*
|
||||
* Allows the authenticated user to change their own password.
|
||||
* Rate-limited to 5 attempts per 15-minute window per session.
|
||||
*
|
||||
* @body {string} currentPassword - The user's current password
|
||||
* @body {string} newPassword - The desired new password (min 8 characters)
|
||||
* @returns {object} 200 - { message: 'Password changed successfully' }
|
||||
* @returns {object} 400 - { error: 'Current password and new password are required' } | { error: 'New password must be at least 8 characters' }
|
||||
* @returns {object} 401 - { error: 'Account is disabled' } | { error: 'Current password is incorrect' }
|
||||
* @returns {object} 429 - { error: 'Too many password change attempts. Please try again later.' }
|
||||
* @returns {object} 500 - { error: 'Failed to change password' }
|
||||
*/
|
||||
router.post('/change-password', requireAuth(db), passwordChangeLimiter, async (req, res) => {
|
||||
const { currentPassword, newPassword } = req.body;
|
||||
|
||||
if (!currentPassword || !newPassword) {
|
||||
return res.status(400).json({ error: 'Current password and new password are required' });
|
||||
}
|
||||
|
||||
if (newPassword.length < 8) {
|
||||
return res.status(400).json({ error: 'New password must be at least 8 characters' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Fetch user's password hash and active status
|
||||
const user = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
'SELECT password_hash, is_active FROM users WHERE id = ?',
|
||||
[req.user.id],
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (!user || !user.is_active) {
|
||||
return res.status(401).json({ error: 'Account is disabled' });
|
||||
}
|
||||
|
||||
// Verify current password
|
||||
const validPassword = await bcrypt.compare(currentPassword, user.password_hash);
|
||||
if (!validPassword) {
|
||||
return res.status(401).json({ error: 'Current password is incorrect' });
|
||||
}
|
||||
|
||||
// Hash new password and update
|
||||
const newHash = await bcrypt.hash(newPassword, 10);
|
||||
await new Promise((resolve, reject) => {
|
||||
db.run(
|
||||
'UPDATE users SET password_hash = ? WHERE id = ?',
|
||||
[newHash, req.user.id],
|
||||
(err) => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'password_change',
|
||||
entityType: 'auth',
|
||||
entityId: null,
|
||||
details: null,
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ message: 'Password changed successfully' });
|
||||
} catch (err) {
|
||||
console.error('Password change error:', err);
|
||||
res.status(500).json({ error: 'Failed to change password' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/auth/cleanup-sessions
|
||||
*
|
||||
|
||||
615
backend/routes/cardApi.js
Normal file
615
backend/routes/cardApi.js
Normal file
@@ -0,0 +1,615 @@
|
||||
// CARD Asset Ownership API Routes
|
||||
// Proxies CARD operations (confirm, decline, redirect, search) and orchestrates
|
||||
// the two-step update_token flow for mutations.
|
||||
|
||||
const express = require('express');
|
||||
const { requireGroup } = require('../middleware/auth');
|
||||
const logAudit = require('../helpers/auditLog');
|
||||
const {
|
||||
isConfigured,
|
||||
missingVars,
|
||||
getTeams,
|
||||
getTeamAssets,
|
||||
getOwner,
|
||||
confirmAsset,
|
||||
declineAsset,
|
||||
redirectAsset,
|
||||
} = require('../helpers/cardApi');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DB helpers — promise wrappers for callback-based SQLite API
|
||||
// ---------------------------------------------------------------------------
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.run(sql, params, function (err) { if (err) reject(err); else resolve(this); });
|
||||
});
|
||||
}
|
||||
|
||||
function dbGet(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.get(sql, params, (err, row) => { if (err) reject(err); else resolve(row); });
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Error classification — maps CARD API / token errors to client responses
|
||||
// ---------------------------------------------------------------------------
|
||||
function handleCardError(err, res) {
|
||||
const msg = err.message || String(err);
|
||||
console.error('[card-api]', msg);
|
||||
|
||||
// Token endpoint errors (from acquireToken rejections)
|
||||
if (msg.includes('Token acquisition failed')) {
|
||||
if (msg.includes('HTTP 401')) {
|
||||
return res.status(401).json({ error: 'CARD authorization failed. Check service account credentials.' });
|
||||
}
|
||||
if (msg.includes('HTTP 403')) {
|
||||
return res.status(403).json({ error: 'CARD access denied. The service account may not be onboarded with the CARD team.' });
|
||||
}
|
||||
if (msg.includes('HTTP 525')) {
|
||||
return res.status(502).json({ error: 'CARD LDAP error. The service account may not be provisioned correctly.' });
|
||||
}
|
||||
}
|
||||
|
||||
// API call errors (after automatic 401 retry in helper)
|
||||
if (msg.includes('401')) {
|
||||
return res.status(401).json({ error: 'CARD token expired or invalid. The request has been retried once automatically.' });
|
||||
}
|
||||
if (msg.includes('403')) {
|
||||
return res.status(403).json({ error: 'Insufficient CARD permissions for this operation.' });
|
||||
}
|
||||
|
||||
// Catch-all
|
||||
return res.status(502).json({ error: 'CARD API request failed.', details: msg });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Router factory
|
||||
// ---------------------------------------------------------------------------
|
||||
function createCardApiRouter(db, requireAuth) {
|
||||
const router = express.Router();
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// GET /status
|
||||
// Returns whether the CARD API integration is configured.
|
||||
// -------------------------------------------------------------------
|
||||
router.get('/status', requireAuth(db), (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({
|
||||
configured: false,
|
||||
error: 'CARD API is not configured.',
|
||||
missingVars,
|
||||
});
|
||||
}
|
||||
res.json({ configured: true });
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// GET /teams
|
||||
// Proxy CARD teams list.
|
||||
// -------------------------------------------------------------------
|
||||
router.get('/teams', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await getTeams();
|
||||
|
||||
if (result.ok) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
body = result.body;
|
||||
}
|
||||
// CARD API wraps teams in { teams: [...], response_time: ... }
|
||||
const teams = Array.isArray(body) ? body : (body && body.teams) || [];
|
||||
return res.json(teams);
|
||||
}
|
||||
|
||||
// Forward CARD error status
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
return res.status(result.status).json(errorBody);
|
||||
} catch (err) {
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// GET /teams/:teamName/assets
|
||||
// Proxy team assets with required disposition filter.
|
||||
// -------------------------------------------------------------------
|
||||
router.get('/teams/:teamName/assets', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
const { teamName } = req.params;
|
||||
const { disposition, page, page_size } = req.query;
|
||||
|
||||
if (!disposition) {
|
||||
return res.status(400).json({ error: 'disposition query parameter is required.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await getTeamAssets(teamName, {
|
||||
disposition,
|
||||
page: page ? parseInt(page, 10) : undefined,
|
||||
pageSize: page_size ? parseInt(page_size, 10) : 50,
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
body = result.body;
|
||||
}
|
||||
|
||||
// Audit log for asset search (fire-and-forget)
|
||||
let resultCount = 0;
|
||||
if (body && typeof body === 'object' && typeof body.total === 'number') {
|
||||
resultCount = body.total;
|
||||
} else if (body && Array.isArray(body.assets)) {
|
||||
resultCount = body.assets.length;
|
||||
}
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_search',
|
||||
entityType: 'card_asset',
|
||||
entityId: teamName,
|
||||
details: { disposition, resultCount },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
return res.json(body);
|
||||
}
|
||||
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
return res.status(result.status).json(errorBody);
|
||||
} catch (err) {
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// GET /owner/:assetId
|
||||
// Proxy owner record lookup.
|
||||
// -------------------------------------------------------------------
|
||||
router.get('/owner/:assetId', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
const { assetId } = req.params;
|
||||
|
||||
try {
|
||||
const result = await getOwner(assetId);
|
||||
|
||||
if (result.ok) {
|
||||
let body;
|
||||
try {
|
||||
body = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
body = result.body;
|
||||
}
|
||||
return res.json(body);
|
||||
}
|
||||
|
||||
let errorBody;
|
||||
try {
|
||||
errorBody = JSON.parse(result.body);
|
||||
} catch (_) {
|
||||
errorBody = { error: result.body };
|
||||
}
|
||||
return res.status(result.status).json(errorBody);
|
||||
} catch (err) {
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// POST /queue/:queueItemId/confirm
|
||||
// Confirm asset to a team via CARD API.
|
||||
// -------------------------------------------------------------------
|
||||
router.post('/queue/:queueItemId/confirm', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
const { queueItemId } = req.params;
|
||||
const { teamName, assetId, comment } = req.body;
|
||||
|
||||
// Validate required fields
|
||||
if (!teamName || typeof teamName !== 'string' || !teamName.trim()) {
|
||||
return res.status(400).json({ error: 'teamName is required.' });
|
||||
}
|
||||
if (!assetId || typeof assetId !== 'string' || !assetId.trim()) {
|
||||
return res.status(400).json({ error: 'assetId is required.' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Validate queue item
|
||||
const item = await dbGet(db,
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ? AND user_id = ? AND workflow_type = ?',
|
||||
[queueItemId, req.user.id, 'CARD']
|
||||
);
|
||||
|
||||
if (!item) {
|
||||
return res.status(404).json({ error: 'Queue item not found.' });
|
||||
}
|
||||
if (item.status !== 'pending') {
|
||||
return res.status(400).json({ error: 'Only pending queue items can be executed.' });
|
||||
}
|
||||
|
||||
// Step 1: Get owner record for update_token
|
||||
const ownerResult = await getOwner(assetId);
|
||||
if (!ownerResult.ok) {
|
||||
const errMsg = `Failed to fetch owner record: HTTP ${ownerResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'confirm', assetId, error: errMsg, cardStatus: ownerResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(ownerResult.body); } catch (_) { errorBody = { error: ownerResult.body }; }
|
||||
return res.status(ownerResult.status).json(errorBody);
|
||||
}
|
||||
|
||||
let ownerData;
|
||||
try { ownerData = JSON.parse(ownerResult.body); } catch (_) { ownerData = {}; }
|
||||
const updateToken = ownerData.owner && ownerData.owner.update_token;
|
||||
|
||||
if (!updateToken) {
|
||||
const errMsg = 'update_token not found in owner record.';
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'confirm', assetId, error: errMsg, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return res.status(502).json({ error: 'CARD API request failed.', details: errMsg });
|
||||
}
|
||||
|
||||
// Step 2: Execute confirm mutation
|
||||
const confirmResult = await confirmAsset(assetId, teamName.trim(), updateToken, comment || '');
|
||||
|
||||
if (confirmResult.ok) {
|
||||
// Update queue item to complete
|
||||
await dbRun(db,
|
||||
"UPDATE ivanti_todo_queue SET status = 'complete', updated_at = CURRENT_TIMESTAMP WHERE id = ?",
|
||||
[queueItemId]
|
||||
);
|
||||
|
||||
let cardResponse;
|
||||
try { cardResponse = JSON.parse(confirmResult.body); } catch (_) { cardResponse = confirmResult.body; }
|
||||
|
||||
// Audit log (fire-and-forget)
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_confirm',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { assetId, teamName: teamName.trim(), comment: comment || '', cardStatus: confirmResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
return res.json({ success: true, cardResponse });
|
||||
}
|
||||
|
||||
// Mutation failed — leave queue item as pending
|
||||
const errMsg = `Confirm failed: HTTP ${confirmResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'confirm', assetId, error: errMsg, cardStatus: confirmResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(confirmResult.body); } catch (_) { errorBody = { error: confirmResult.body }; }
|
||||
return res.status(confirmResult.status).json(errorBody);
|
||||
} catch (err) {
|
||||
console.error('[card-api] Confirm error:', err.message);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'confirm', assetId, error: err.message, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// POST /queue/:queueItemId/decline
|
||||
// Decline asset from a team via CARD API.
|
||||
// -------------------------------------------------------------------
|
||||
router.post('/queue/:queueItemId/decline', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
const { queueItemId } = req.params;
|
||||
const { teamName, assetId, comment } = req.body;
|
||||
|
||||
// Validate required fields
|
||||
if (!teamName || typeof teamName !== 'string' || !teamName.trim()) {
|
||||
return res.status(400).json({ error: 'teamName is required.' });
|
||||
}
|
||||
if (!assetId || typeof assetId !== 'string' || !assetId.trim()) {
|
||||
return res.status(400).json({ error: 'assetId is required.' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Validate queue item
|
||||
const item = await dbGet(db,
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ? AND user_id = ? AND workflow_type = ?',
|
||||
[queueItemId, req.user.id, 'CARD']
|
||||
);
|
||||
|
||||
if (!item) {
|
||||
return res.status(404).json({ error: 'Queue item not found.' });
|
||||
}
|
||||
if (item.status !== 'pending') {
|
||||
return res.status(400).json({ error: 'Only pending queue items can be executed.' });
|
||||
}
|
||||
|
||||
// Step 1: Get owner record for update_token
|
||||
const ownerResult = await getOwner(assetId);
|
||||
if (!ownerResult.ok) {
|
||||
const errMsg = `Failed to fetch owner record: HTTP ${ownerResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'decline', assetId, error: errMsg, cardStatus: ownerResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(ownerResult.body); } catch (_) { errorBody = { error: ownerResult.body }; }
|
||||
return res.status(ownerResult.status).json(errorBody);
|
||||
}
|
||||
|
||||
let ownerData;
|
||||
try { ownerData = JSON.parse(ownerResult.body); } catch (_) { ownerData = {}; }
|
||||
const updateToken = ownerData.owner && ownerData.owner.update_token;
|
||||
|
||||
if (!updateToken) {
|
||||
const errMsg = 'update_token not found in owner record.';
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'decline', assetId, error: errMsg, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return res.status(502).json({ error: 'CARD API request failed.', details: errMsg });
|
||||
}
|
||||
|
||||
// Step 2: Execute decline mutation
|
||||
const declineResult = await declineAsset(assetId, teamName.trim(), updateToken, comment || '');
|
||||
|
||||
if (declineResult.ok) {
|
||||
await dbRun(db,
|
||||
"UPDATE ivanti_todo_queue SET status = 'complete', updated_at = CURRENT_TIMESTAMP WHERE id = ?",
|
||||
[queueItemId]
|
||||
);
|
||||
|
||||
let cardResponse;
|
||||
try { cardResponse = JSON.parse(declineResult.body); } catch (_) { cardResponse = declineResult.body; }
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_decline',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { assetId, teamName: teamName.trim(), comment: comment || '', cardStatus: declineResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
return res.json({ success: true, cardResponse });
|
||||
}
|
||||
|
||||
// Mutation failed
|
||||
const errMsg = `Decline failed: HTTP ${declineResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'decline', assetId, error: errMsg, cardStatus: declineResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(declineResult.body); } catch (_) { errorBody = { error: declineResult.body }; }
|
||||
return res.status(declineResult.status).json(errorBody);
|
||||
} catch (err) {
|
||||
console.error('[card-api] Decline error:', err.message);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'decline', assetId, error: err.message, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// POST /queue/:queueItemId/redirect
|
||||
// Redirect asset from one team to another via CARD API.
|
||||
// -------------------------------------------------------------------
|
||||
router.post('/queue/:queueItemId/redirect', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!isConfigured) {
|
||||
return res.status(503).json({ error: 'CARD API is not configured.', missingVars });
|
||||
}
|
||||
|
||||
const { queueItemId } = req.params;
|
||||
const { fromTeam, toTeam, assetId } = req.body;
|
||||
|
||||
// Validate required fields
|
||||
if (!fromTeam || typeof fromTeam !== 'string' || !fromTeam.trim()) {
|
||||
return res.status(400).json({ error: 'fromTeam is required.' });
|
||||
}
|
||||
if (!toTeam || typeof toTeam !== 'string' || !toTeam.trim()) {
|
||||
return res.status(400).json({ error: 'toTeam is required.' });
|
||||
}
|
||||
if (!assetId || typeof assetId !== 'string' || !assetId.trim()) {
|
||||
return res.status(400).json({ error: 'assetId is required.' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Validate queue item
|
||||
const item = await dbGet(db,
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ? AND user_id = ? AND workflow_type = ?',
|
||||
[queueItemId, req.user.id, 'CARD']
|
||||
);
|
||||
|
||||
if (!item) {
|
||||
return res.status(404).json({ error: 'Queue item not found.' });
|
||||
}
|
||||
if (item.status !== 'pending') {
|
||||
return res.status(400).json({ error: 'Only pending queue items can be executed.' });
|
||||
}
|
||||
|
||||
// Step 1: Get owner record for update_token
|
||||
const ownerResult = await getOwner(assetId);
|
||||
if (!ownerResult.ok) {
|
||||
const errMsg = `Failed to fetch owner record: HTTP ${ownerResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'redirect', assetId, error: errMsg, cardStatus: ownerResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(ownerResult.body); } catch (_) { errorBody = { error: ownerResult.body }; }
|
||||
return res.status(ownerResult.status).json(errorBody);
|
||||
}
|
||||
|
||||
let ownerData;
|
||||
try { ownerData = JSON.parse(ownerResult.body); } catch (_) { ownerData = {}; }
|
||||
const updateToken = ownerData.owner && ownerData.owner.update_token;
|
||||
|
||||
if (!updateToken) {
|
||||
const errMsg = 'update_token not found in owner record.';
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'redirect', assetId, error: errMsg, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return res.status(502).json({ error: 'CARD API request failed.', details: errMsg });
|
||||
}
|
||||
|
||||
// Step 2: Execute redirect mutation
|
||||
const redirectResult = await redirectAsset(assetId, fromTeam.trim(), toTeam.trim(), updateToken);
|
||||
|
||||
if (redirectResult.ok) {
|
||||
await dbRun(db,
|
||||
"UPDATE ivanti_todo_queue SET status = 'complete', updated_at = CURRENT_TIMESTAMP WHERE id = ?",
|
||||
[queueItemId]
|
||||
);
|
||||
|
||||
let cardResponse;
|
||||
try { cardResponse = JSON.parse(redirectResult.body); } catch (_) { cardResponse = redirectResult.body; }
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_redirect',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { assetId, fromTeam: fromTeam.trim(), toTeam: toTeam.trim(), cardStatus: redirectResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
return res.json({ success: true, cardResponse });
|
||||
}
|
||||
|
||||
// Mutation failed
|
||||
const errMsg = `Redirect failed: HTTP ${redirectResult.status}`;
|
||||
console.error('[card-api]', errMsg);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'redirect', assetId, error: errMsg, cardStatus: redirectResult.status },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
let errorBody;
|
||||
try { errorBody = JSON.parse(redirectResult.body); } catch (_) { errorBody = { error: redirectResult.body }; }
|
||||
return res.status(redirectResult.status).json(errorBody);
|
||||
} catch (err) {
|
||||
console.error('[card-api] Redirect error:', err.message);
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'card_action_failed',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(queueItemId),
|
||||
details: { actionType: 'redirect', assetId, error: err.message, cardStatus: null },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
return handleCardError(err, res);
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
module.exports = createCardApiRouter;
|
||||
@@ -2,24 +2,35 @@
|
||||
// Handles xlsx upload/parse, non-compliant item history, and notes.
|
||||
//
|
||||
// Endpoints:
|
||||
// POST /preview — parse xlsx, compute diff vs DB, return summary (no DB write)
|
||||
// POST /commit — commit a previewed upload to DB
|
||||
// GET /uploads — list all uploads
|
||||
// GET /summary — metric health cards for a team (from latest upload)
|
||||
// GET /items — non-compliant devices grouped by hostname (?team=X&status=active)
|
||||
// GET /items/:hostname — detail panel: all metrics + notes + upload history for a device
|
||||
// POST /notes — add a note to a (hostname, metric_id) pair
|
||||
// POST /preview — parse xlsx, run drift check, compute diff (no DB write)
|
||||
// POST /reconcile-config — patch compliance_config.json to resolve drift findings
|
||||
// POST /commit — commit a previewed upload to DB
|
||||
// GET /uploads — list all uploads
|
||||
// POST /rollback/:uploadId — roll back the most recent upload (Admin only)
|
||||
// GET /summary — metric health cards for a team (from latest upload)
|
||||
// GET /items — non-compliant devices grouped by hostname (?team=X&status=active)
|
||||
// GET /items/:hostname — detail panel: all metrics + notes + upload history for a device
|
||||
// POST /notes — add a note to one or more (hostname, metric_id) pairs
|
||||
// GET /notes/:hostname/:metricId — notes for a specific device+metric
|
||||
// GET /trends — per-upload totals + per-team counts for time-series charts
|
||||
// GET /mttr — aging findings distribution by seen_count bucket and team
|
||||
// GET /top-recurring — net change waterfall (per-cycle start/new/recurring/resolved/end)
|
||||
// GET /category-trend — active counts per category per upload for stacked area chart
|
||||
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const crypto = require('crypto');
|
||||
const { spawn } = require('child_process');
|
||||
const { loadConfig, compareSchemaToDrift, reconcileConfig } = require('../helpers/driftChecker');
|
||||
const logAudit = require('../helpers/auditLog');
|
||||
|
||||
const PARSER_SCRIPT = path.join(__dirname, '../scripts/parse_compliance_xlsx.py');
|
||||
const PYTHON_BIN = process.env.PYTHON_BIN || 'python3';
|
||||
const TEMP_DIR = path.join(process.cwd(), 'uploads', 'temp');
|
||||
const ALLOWED_TEAMS = new Set(['STEAM', 'ACCESS-ENG', 'ACCESS-OPS', 'INTELDEV']);
|
||||
const PARSER_SCRIPT = path.join(__dirname, '../scripts/parse_compliance_xlsx.py');
|
||||
const SCHEMA_SCRIPT = path.join(__dirname, '../scripts/extract_xlsx_schema.py');
|
||||
const CONFIG_PATH = path.join(__dirname, '..', 'scripts', 'compliance_config.json');
|
||||
const PYTHON_BIN = process.env.PYTHON_BIN || 'python3';
|
||||
const TEMP_DIR = path.join(process.cwd(), 'uploads', 'temp');
|
||||
const ALLOWED_TEAMS = new Set(['STEAM', 'ACCESS-ENG', 'ACCESS-OPS', 'INTELDEV']);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DB helpers
|
||||
@@ -62,6 +73,25 @@ function parseXlsx(filePath) {
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Run Python schema extractor, return xlsx schema object
|
||||
// ---------------------------------------------------------------------------
|
||||
function extractXlsxSchema(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const py = spawn(PYTHON_BIN, [SCHEMA_SCRIPT, filePath]);
|
||||
let out = '';
|
||||
let err = '';
|
||||
py.stdout.on('data', d => { out += d; });
|
||||
py.stderr.on('data', d => { err += d; });
|
||||
py.on('close', code => {
|
||||
if (code !== 0) return reject(new Error(err || `Schema extractor exited with code ${code}`));
|
||||
try { resolve(JSON.parse(out)); }
|
||||
catch (e) { reject(new Error('Schema extractor returned invalid JSON')); }
|
||||
});
|
||||
py.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Validate that a temp file path is safely within uploads/temp/
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -210,6 +240,60 @@ function groupByHostname(rows, noteHostnames) {
|
||||
return Object.values(deviceMap);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pure function: bucket active items by age group and pivot per-team counts
|
||||
// ---------------------------------------------------------------------------
|
||||
const BUCKET_ORDER = ['1 cycle', '2–3 cycles', '4–6 cycles', '7+ cycles'];
|
||||
|
||||
function bucketAgingItems(items) {
|
||||
// Initialise empty buckets with all teams at zero
|
||||
const teams = ['STEAM', 'ACCESS-ENG', 'ACCESS-OPS', 'INTELDEV'];
|
||||
const buckets = {};
|
||||
for (const b of BUCKET_ORDER) {
|
||||
buckets[b] = { bucket: b, total: 0 };
|
||||
for (const t of teams) buckets[b][t] = 0;
|
||||
}
|
||||
|
||||
// Classify each item into a bucket
|
||||
for (const item of items) {
|
||||
const sc = item.seen_count;
|
||||
let label;
|
||||
if (sc === 1) label = '1 cycle';
|
||||
else if (sc >= 2 && sc <= 3) label = '2–3 cycles';
|
||||
else if (sc >= 4 && sc <= 6) label = '4–6 cycles';
|
||||
else label = '7+ cycles';
|
||||
|
||||
const team = item.team;
|
||||
buckets[label].total += 1;
|
||||
if (team in buckets[label]) {
|
||||
buckets[label][team] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Return in ascending age order
|
||||
return BUCKET_ORDER.map(b => buckets[b]);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pure function: compute waterfall chain from ordered upload records
|
||||
// ---------------------------------------------------------------------------
|
||||
function computeWaterfall(uploads) {
|
||||
let start = 0;
|
||||
return uploads.map((row) => {
|
||||
const end = start + row.new_count + row.recurring_count - row.resolved_count;
|
||||
const entry = {
|
||||
date: row.report_date,
|
||||
start,
|
||||
new_count: row.new_count,
|
||||
recurring_count: row.recurring_count,
|
||||
resolved_count: row.resolved_count,
|
||||
end,
|
||||
};
|
||||
start = end;
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Router factory
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -227,6 +311,15 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// POST /preview
|
||||
// Parse the uploaded xlsx, compute diff, save parsed data to a temp JSON.
|
||||
// Returns diff counts + tempFile path for the commit step.
|
||||
//
|
||||
// Body: multipart/form-data with `file` field (xlsx)
|
||||
// Response: {
|
||||
// drift: { breaking: [], silent_miss: [], cosmetic: [] } | null,
|
||||
// drift_error: string | null,
|
||||
// diff: { new_count, recurring_count, resolved_count },
|
||||
// tempFile: string, filename: string,
|
||||
// report_date: string, total_items: number
|
||||
// }
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/preview', requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
upload.single('file')(req, res, async (uploadErr) => {
|
||||
@@ -242,6 +335,31 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
}
|
||||
|
||||
try {
|
||||
// --- Drift check: load config, extract schema, compare ---
|
||||
let drift = null;
|
||||
let drift_error = null;
|
||||
|
||||
let config;
|
||||
try {
|
||||
config = loadConfig(CONFIG_PATH);
|
||||
} catch (configErr) {
|
||||
fs.unlink(req.file.path, () => {});
|
||||
return res.status(500).json({ error: 'Configuration file could not be loaded: ' + configErr.message });
|
||||
}
|
||||
|
||||
let xlsxSchema = null;
|
||||
try {
|
||||
xlsxSchema = await extractXlsxSchema(req.file.path);
|
||||
if (xlsxSchema.error) {
|
||||
throw new Error(xlsxSchema.error);
|
||||
}
|
||||
drift = compareSchemaToDrift(xlsxSchema, config);
|
||||
} catch (driftErr) {
|
||||
drift = null;
|
||||
drift_error = driftErr.message || 'Drift check failed';
|
||||
}
|
||||
|
||||
// --- Existing parse flow ---
|
||||
const parsed = await parseXlsx(req.file.path);
|
||||
|
||||
if (parsed.error) {
|
||||
@@ -267,6 +385,9 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
fs.unlink(req.file.path, () => {});
|
||||
|
||||
res.json({
|
||||
drift,
|
||||
drift_error,
|
||||
schema: xlsxSchema,
|
||||
diff: {
|
||||
new_count: diff.newCount,
|
||||
recurring_count: diff.recurringCount,
|
||||
@@ -286,10 +407,63 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
});
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /reconcile-config
|
||||
// Admin-only. Patches compliance_config.json to resolve breaking and
|
||||
// silent-miss drift findings, then re-runs the drift check and returns
|
||||
// the updated report. Logs every change to the audit trail.
|
||||
//
|
||||
// Body: { drift: { breaking: [...], silent_miss: [...] } }
|
||||
// Response: { changes: [{ action, key, value, detail }], message: string }
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/reconcile-config', requireGroup('Admin'), async (req, res) => {
|
||||
const { drift, schema } = req.body;
|
||||
|
||||
if (!drift || typeof drift !== 'object') {
|
||||
return res.status(400).json({ error: 'drift report is required in request body' });
|
||||
}
|
||||
|
||||
const hasFindings = (drift.breaking && drift.breaking.length > 0) ||
|
||||
(drift.silent_miss && drift.silent_miss.length > 0);
|
||||
if (!hasFindings) {
|
||||
return res.status(400).json({ error: 'No breaking or silent-miss findings to reconcile' });
|
||||
}
|
||||
|
||||
try {
|
||||
const { changes } = reconcileConfig(CONFIG_PATH, drift, schema || null);
|
||||
|
||||
if (changes.length === 0) {
|
||||
return res.json({ changes: [], message: 'No changes needed' });
|
||||
}
|
||||
|
||||
// Audit log each change
|
||||
for (const change of changes) {
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'compliance_config_reconcile',
|
||||
entityType: 'compliance_config',
|
||||
entityId: change.value,
|
||||
details: { action: change.action, key: change.key, detail: change.detail },
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
}
|
||||
|
||||
res.json({ changes, message: `Reconciled ${changes.length} config change(s)` });
|
||||
|
||||
} catch (err) {
|
||||
console.error('[Compliance] Reconcile config error:', err.message);
|
||||
res.status(500).json({ error: 'Failed to reconcile config: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /commit
|
||||
// Commit a previewed upload to the DB.
|
||||
// Body: { tempFile, filename, report_date }
|
||||
//
|
||||
// Body: { tempFile: string, filename: string, report_date: string }
|
||||
// Response: { upload: { id, filename, report_date, uploaded_at,
|
||||
// new_count, resolved_count, recurring_count } }
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/commit', requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
const { tempFile, filename, report_date } = req.body;
|
||||
@@ -340,6 +514,9 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /uploads
|
||||
// List all uploads, most recent first.
|
||||
//
|
||||
// Response: { uploads: [{ id, filename, report_date, uploaded_at,
|
||||
// new_count, resolved_count, recurring_count }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/uploads', async (req, res) => {
|
||||
try {
|
||||
@@ -356,9 +533,133 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /rollback/:uploadId
|
||||
// Admin-only. Rolls back a specific upload. Only the most recent upload
|
||||
// can be rolled back to avoid cascading data integrity issues.
|
||||
//
|
||||
// Params: uploadId — integer ID of the upload to roll back
|
||||
// Response: { message: string, rolled_back: { upload_id, filename,
|
||||
// report_date, items_deleted, items_reactivated } }
|
||||
//
|
||||
// Reversal logic:
|
||||
// 1. Delete items first seen in this upload (new items)
|
||||
// 2. Re-activate items resolved by this upload
|
||||
// 3. Revert recurring items: decrement seen_count, point upload_id
|
||||
// back to the previous upload
|
||||
// 4. Delete the upload record
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/rollback/:uploadId', requireGroup('Admin'), async (req, res) => {
|
||||
const uploadId = parseInt(req.params.uploadId, 10);
|
||||
if (isNaN(uploadId)) {
|
||||
return res.status(400).json({ error: 'Invalid upload ID' });
|
||||
}
|
||||
|
||||
try {
|
||||
// Verify the upload exists
|
||||
const upload = await dbGet(db,
|
||||
`SELECT id, filename, report_date, new_count, resolved_count, recurring_count
|
||||
FROM compliance_uploads WHERE id = ?`,
|
||||
[uploadId]
|
||||
);
|
||||
if (!upload) {
|
||||
return res.status(404).json({ error: 'Upload not found' });
|
||||
}
|
||||
|
||||
// Only allow rolling back the most recent upload
|
||||
const latest = await dbGet(db,
|
||||
`SELECT id FROM compliance_uploads ORDER BY id DESC LIMIT 1`
|
||||
);
|
||||
if (latest.id !== uploadId) {
|
||||
return res.status(400).json({
|
||||
error: 'Only the most recent upload can be rolled back',
|
||||
latest_upload_id: latest.id
|
||||
});
|
||||
}
|
||||
|
||||
// Find the previous upload (to restore recurring items' upload_id)
|
||||
const previousUpload = await dbGet(db,
|
||||
`SELECT id FROM compliance_uploads WHERE id < ? ORDER BY id DESC LIMIT 1`,
|
||||
[uploadId]
|
||||
);
|
||||
|
||||
await dbRun(db, 'BEGIN TRANSACTION');
|
||||
|
||||
try {
|
||||
// 1. Delete items that were NEW in this upload
|
||||
const deleteNew = await dbRun(db,
|
||||
`DELETE FROM compliance_items WHERE first_seen_upload_id = ? AND upload_id = ?`,
|
||||
[uploadId, uploadId]
|
||||
);
|
||||
|
||||
// 2. Re-activate items that were RESOLVED by this upload
|
||||
const reactivate = await dbRun(db,
|
||||
`UPDATE compliance_items
|
||||
SET status = 'active', resolved_upload_id = NULL
|
||||
WHERE resolved_upload_id = ?`,
|
||||
[uploadId]
|
||||
);
|
||||
|
||||
// 3. Revert RECURRING items: decrement seen_count, restore upload_id
|
||||
if (previousUpload) {
|
||||
await dbRun(db,
|
||||
`UPDATE compliance_items
|
||||
SET upload_id = ?, seen_count = MAX(seen_count - 1, 1)
|
||||
WHERE upload_id = ? AND first_seen_upload_id != ?`,
|
||||
[previousUpload.id, uploadId, uploadId]
|
||||
);
|
||||
}
|
||||
|
||||
// 4. Delete the upload record
|
||||
await dbRun(db, `DELETE FROM compliance_uploads WHERE id = ?`, [uploadId]);
|
||||
|
||||
await dbRun(db, 'COMMIT');
|
||||
|
||||
// Audit log
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'compliance_upload_rollback',
|
||||
entityType: 'compliance_upload',
|
||||
entityId: String(uploadId),
|
||||
details: {
|
||||
filename: upload.filename,
|
||||
report_date: upload.report_date,
|
||||
items_deleted: deleteNew.changes,
|
||||
items_reactivated: reactivate.changes,
|
||||
},
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
res.json({
|
||||
message: `Rolled back upload "${upload.filename}"`,
|
||||
rolled_back: {
|
||||
upload_id: uploadId,
|
||||
filename: upload.filename,
|
||||
report_date: upload.report_date,
|
||||
items_deleted: deleteNew.changes,
|
||||
items_reactivated: reactivate.changes,
|
||||
},
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
await dbRun(db, 'ROLLBACK').catch(() => {});
|
||||
throw err;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('[Compliance] Rollback error:', err.message);
|
||||
res.status(500).json({ error: 'Failed to rollback upload: ' + err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /summary?team=STEAM
|
||||
// Return metric health rows for a team from the latest upload's summary_json.
|
||||
//
|
||||
// Query: team — optional, one of ALLOWED_TEAMS
|
||||
// Response: { entries: [...], overall_scores: {}, upload: { id,
|
||||
// report_date, uploaded_at } | null }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/summary', async (req, res) => {
|
||||
const team = req.query.team;
|
||||
@@ -402,6 +703,12 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /items?team=STEAM&status=active
|
||||
// Return non-compliant devices grouped by hostname.
|
||||
//
|
||||
// Query: team — required, one of ALLOWED_TEAMS
|
||||
// status — optional, 'active' (default) or 'resolved'
|
||||
// Response: { devices: [{ hostname, ip_address, device_type, team,
|
||||
// status, failing_metrics, seen_count, first_seen, last_seen,
|
||||
// resolved_on, has_notes }], team, status }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/items', async (req, res) => {
|
||||
const { team, status = 'active' } = req.query;
|
||||
@@ -447,6 +754,12 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /items/:hostname
|
||||
// Detail panel: all metric rows for this hostname + notes + upload history.
|
||||
//
|
||||
// Params: hostname — device hostname string
|
||||
// Response: { hostname, ip_address, device_type, team,
|
||||
// metrics: [{ metric_id, metric_desc, category, status, seen_count,
|
||||
// extra, first_seen, last_seen, resolved_on, ... }],
|
||||
// notes: [{ id, metric_id, note, group_id, created_at, created_by }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/items/:hostname', async (req, res) => {
|
||||
const hostname = req.params.hostname;
|
||||
@@ -488,7 +801,7 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
|
||||
// Notes (all metrics for this hostname, sorted newest first)
|
||||
const notes = await dbAll(db,
|
||||
`SELECT cn.id, cn.metric_id, cn.note, cn.created_at,
|
||||
`SELECT cn.id, cn.metric_id, cn.note, cn.group_id, cn.created_at,
|
||||
u.username AS created_by
|
||||
FROM compliance_notes cn
|
||||
LEFT JOIN users u ON cn.created_by = u.id
|
||||
@@ -517,42 +830,86 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// POST /notes
|
||||
// Add a note to a (hostname, metric_id) pair.
|
||||
// Body: { hostname, metric_id, note }
|
||||
// Add a note to one or more (hostname, metric_id) pairs.
|
||||
//
|
||||
// Body: { hostname: string, metric_ids: string[], note: string }
|
||||
// — or legacy: { hostname: string, metric_id: string, note: string }
|
||||
// Response: { notes: [{ id, hostname, metric_id, note, group_id,
|
||||
// created_at, created_by }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.post('/notes', requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
const { hostname, metric_id, note } = req.body;
|
||||
const { hostname, metric_id, metric_ids, note } = req.body;
|
||||
|
||||
if (!hostname || typeof hostname !== 'string' || hostname.length > 300 || !/^[a-zA-Z0-9._-]+$/.test(hostname)) {
|
||||
return res.status(400).json({ error: 'Invalid hostname format' });
|
||||
}
|
||||
if (!metric_id || typeof metric_id !== 'string' || metric_id.length > 50) {
|
||||
return res.status(400).json({ error: 'Invalid metric_id' });
|
||||
|
||||
// --- Resolve metric IDs: metric_ids takes precedence over metric_id ---
|
||||
let resolvedIds;
|
||||
if (metric_ids !== undefined) {
|
||||
if (!Array.isArray(metric_ids)) {
|
||||
return res.status(400).json({ error: 'metric_ids must be an array' });
|
||||
}
|
||||
resolvedIds = metric_ids;
|
||||
} else if (metric_id !== undefined && metric_id !== null && metric_id !== '') {
|
||||
if (typeof metric_id !== 'string' || metric_id.length > 50) {
|
||||
return res.status(400).json({ error: 'Invalid metric_id' });
|
||||
}
|
||||
resolvedIds = [metric_id];
|
||||
} else {
|
||||
return res.status(400).json({ error: 'metric_id or metric_ids is required' });
|
||||
}
|
||||
|
||||
// --- Validate resolved metric IDs ---
|
||||
if (resolvedIds.length === 0) {
|
||||
return res.status(400).json({ error: 'At least one metric ID is required' });
|
||||
}
|
||||
for (let i = 0; i < resolvedIds.length; i++) {
|
||||
const mid = resolvedIds[i];
|
||||
if (!mid || typeof mid !== 'string' || mid.length === 0 || mid.length > 50) {
|
||||
return res.status(400).json({ error: `Invalid metric_id at index ${i}` });
|
||||
}
|
||||
}
|
||||
|
||||
const noteText = String(note || '').trim().slice(0, 1000);
|
||||
if (!noteText) {
|
||||
return res.status(400).json({ error: 'Note cannot be empty' });
|
||||
}
|
||||
|
||||
try {
|
||||
const { lastID } = await dbRun(db,
|
||||
`INSERT INTO compliance_notes (hostname, metric_id, note, created_by, created_at)
|
||||
VALUES (?, ?, ?, ?, datetime('now'))`,
|
||||
[hostname, metric_id, noteText, req.user?.id || null]
|
||||
);
|
||||
const groupId = crypto.randomUUID();
|
||||
const userId = req.user?.id || null;
|
||||
|
||||
const created = await dbGet(db,
|
||||
`SELECT cn.id, cn.hostname, cn.metric_id, cn.note, cn.created_at,
|
||||
try {
|
||||
await dbRun(db, 'BEGIN TRANSACTION');
|
||||
|
||||
const insertedIds = [];
|
||||
for (const mid of resolvedIds) {
|
||||
const { lastID } = await dbRun(db,
|
||||
`INSERT INTO compliance_notes (hostname, metric_id, note, group_id, created_by, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, datetime('now'))`,
|
||||
[hostname, mid, noteText, groupId, userId]
|
||||
);
|
||||
insertedIds.push(lastID);
|
||||
}
|
||||
|
||||
await dbRun(db, 'COMMIT');
|
||||
|
||||
// Fetch all created rows with username
|
||||
const placeholders = insertedIds.map(() => '?').join(', ');
|
||||
const notes = await dbAll(db,
|
||||
`SELECT cn.id, cn.hostname, cn.metric_id, cn.note, cn.group_id, cn.created_at,
|
||||
u.username AS created_by
|
||||
FROM compliance_notes cn
|
||||
LEFT JOIN users u ON cn.created_by = u.id
|
||||
WHERE cn.id = ?`,
|
||||
[lastID]
|
||||
WHERE cn.id IN (${placeholders})
|
||||
ORDER BY cn.id ASC`,
|
||||
insertedIds
|
||||
);
|
||||
|
||||
res.status(201).json(created);
|
||||
res.status(201).json({ notes });
|
||||
|
||||
} catch (err) {
|
||||
await dbRun(db, 'ROLLBACK').catch(() => {});
|
||||
console.error('[Compliance] POST /notes error:', err.message);
|
||||
res.status(500).json({ error: 'Failed to save note' });
|
||||
}
|
||||
@@ -561,6 +918,10 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /notes/:hostname/:metricId
|
||||
// Return all notes for a (hostname, metric_id) pair.
|
||||
//
|
||||
// Params: hostname — device hostname string
|
||||
// metricId — metric identifier string
|
||||
// Response: { notes: [{ id, note, created_at, created_by }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/notes/:hostname/:metricId', async (req, res) => {
|
||||
const { hostname, metricId } = req.params;
|
||||
@@ -584,10 +945,76 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// DELETE /notes/:id
|
||||
// Delete a note (or all notes in the same group_id) by note ID.
|
||||
// Only the note author or an Admin can delete.
|
||||
//
|
||||
// Params: id — note row ID
|
||||
// Query: ?group=true — delete all notes sharing the same group_id
|
||||
// Response: { deleted: number }
|
||||
// -----------------------------------------------------------------------
|
||||
router.delete('/notes/:id', requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
const noteId = parseInt(req.params.id, 10);
|
||||
if (isNaN(noteId)) return res.status(400).json({ error: 'Invalid note ID' });
|
||||
|
||||
const deleteGroup = req.query.group === 'true';
|
||||
|
||||
try {
|
||||
// Fetch the note to verify ownership
|
||||
const note = await dbGet(db,
|
||||
`SELECT id, hostname, metric_id, note, group_id, created_by FROM compliance_notes WHERE id = ?`,
|
||||
[noteId]
|
||||
);
|
||||
if (!note) return res.status(404).json({ error: 'Note not found' });
|
||||
|
||||
// Only the author or an Admin can delete
|
||||
const isAuthor = req.user && String(req.user.id) === String(note.created_by);
|
||||
const isAdminUser = req.user && req.user.group === 'Admin';
|
||||
if (!isAuthor && !isAdminUser) {
|
||||
return res.status(403).json({ error: 'You can only delete your own notes' });
|
||||
}
|
||||
|
||||
let deleted = 0;
|
||||
if (deleteGroup && note.group_id) {
|
||||
const result = await dbRun(db,
|
||||
`DELETE FROM compliance_notes WHERE group_id = ?`,
|
||||
[note.group_id]
|
||||
);
|
||||
deleted = result.changes || 0;
|
||||
} else {
|
||||
const result = await dbRun(db,
|
||||
`DELETE FROM compliance_notes WHERE id = ?`,
|
||||
[noteId]
|
||||
);
|
||||
deleted = result.changes || 0;
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'compliance_note_delete',
|
||||
entityType: 'compliance_note',
|
||||
entityId: String(noteId),
|
||||
details: JSON.stringify({ hostname: note.hostname, group_id: note.group_id, deleted_count: deleted }),
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
res.json({ deleted });
|
||||
} catch (err) {
|
||||
console.error('[Compliance] DELETE /notes error:', err.message);
|
||||
res.status(500).json({ error: 'Failed to delete note' });
|
||||
}
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /trends
|
||||
// Per-upload active totals + per-team counts for time-series charts.
|
||||
// Returns rows ordered ascending by report_date.
|
||||
//
|
||||
// Response: { trends: [{ report_date, new_count, recurring_count,
|
||||
// resolved_count, total_active, STEAM, ACCESS-ENG, ACCESS-OPS,
|
||||
// INTELDEV }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/trends', async (req, res) => {
|
||||
try {
|
||||
@@ -639,25 +1066,23 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /mttr
|
||||
// Mean time to resolution (calendar days) per team, for resolved items.
|
||||
// Aging Findings Distribution — active findings bucketed by seen_count
|
||||
// with per-team breakdown for stacked bar chart.
|
||||
//
|
||||
// Response: { aging: [{ bucket, total, STEAM, ACCESS-ENG, ACCESS-OPS, INTELDEV }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/mttr', async (req, res) => {
|
||||
try {
|
||||
const rows = await dbAll(db,
|
||||
`SELECT
|
||||
ci.team,
|
||||
ROUND(AVG(JULIANDAY(ru.report_date) - JULIANDAY(fu.report_date)), 1) AS avg_days,
|
||||
COUNT(*) AS resolved_count
|
||||
FROM compliance_items ci
|
||||
JOIN compliance_uploads fu ON ci.first_seen_upload_id = fu.id
|
||||
JOIN compliance_uploads ru ON ci.resolved_upload_id = ru.id
|
||||
WHERE ci.resolved_upload_id IS NOT NULL
|
||||
AND fu.report_date IS NOT NULL
|
||||
AND ru.report_date IS NOT NULL
|
||||
GROUP BY ci.team
|
||||
ORDER BY avg_days DESC`
|
||||
`SELECT COALESCE(seen_count, 1) AS seen_count, team
|
||||
FROM compliance_items
|
||||
WHERE status = 'active'`
|
||||
);
|
||||
res.json({ mttr: rows });
|
||||
if (rows.length === 0) {
|
||||
return res.json({ aging: [] });
|
||||
}
|
||||
const aging = bucketAgingItems(rows);
|
||||
res.json({ aging });
|
||||
} catch (err) {
|
||||
console.error('[Compliance] GET /mttr error:', err.message);
|
||||
res.status(500).json({ error: 'Database error' });
|
||||
@@ -666,20 +1091,24 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /top-recurring
|
||||
// Active findings grouped by team + metric_id, sorted by seen_count desc.
|
||||
// Identifies chronic compliance gaps that keep reappearing.
|
||||
// Net Change Waterfall — per-cycle net movement (start → +new →
|
||||
// +recurring → −resolved → end) computed from compliance_uploads.
|
||||
//
|
||||
// Response: { waterfall: [{ date, start, new_count, recurring_count,
|
||||
// resolved_count, end }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/top-recurring', async (req, res) => {
|
||||
try {
|
||||
const rows = await dbAll(db,
|
||||
`SELECT team, metric_id, metric_desc, seen_count, COUNT(*) AS host_count
|
||||
FROM compliance_items
|
||||
WHERE status = 'active'
|
||||
GROUP BY team, metric_id
|
||||
ORDER BY seen_count DESC, host_count DESC
|
||||
LIMIT 20`
|
||||
`SELECT id, report_date,
|
||||
COALESCE(new_count, 0) AS new_count,
|
||||
COALESCE(recurring_count, 0) AS recurring_count,
|
||||
COALESCE(resolved_count, 0) AS resolved_count
|
||||
FROM compliance_uploads
|
||||
ORDER BY report_date ASC`
|
||||
);
|
||||
res.json({ items: rows });
|
||||
const waterfall = computeWaterfall(rows);
|
||||
res.json({ waterfall });
|
||||
} catch (err) {
|
||||
console.error('[Compliance] GET /top-recurring error:', err.message);
|
||||
res.status(500).json({ error: 'Database error' });
|
||||
@@ -689,6 +1118,8 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
// -----------------------------------------------------------------------
|
||||
// GET /category-trend
|
||||
// Active item counts per category per upload, for stacked area chart.
|
||||
//
|
||||
// Response: { categoryTrend: [{ report_date, category, count }] }
|
||||
// -----------------------------------------------------------------------
|
||||
router.get('/category-trend', async (req, res) => {
|
||||
try {
|
||||
@@ -709,4 +1140,4 @@ function createComplianceRouter(db, upload, requireAuth, requireGroup) {
|
||||
return router;
|
||||
}
|
||||
|
||||
module.exports = createComplianceRouter;
|
||||
module.exports = { createComplianceRouter, bucketAgingItems, computeWaterfall };
|
||||
|
||||
@@ -3,6 +3,37 @@ const express = require('express');
|
||||
|
||||
const VALID_STATES = ['ACTIVE', 'ARCHIVED', 'RETURNED', 'CLOSED'];
|
||||
|
||||
/**
|
||||
* Find the most severe active finding related to an archived finding.
|
||||
*
|
||||
* A match requires:
|
||||
* - Exact hostname match (case-sensitive)
|
||||
* - The archive title is a case-insensitive substring of the active title, or vice versa
|
||||
* - The active finding ID differs from the archive's finding_id
|
||||
*
|
||||
* @param {Object} archive - Archive record from ivanti_finding_archives
|
||||
* @param {Array} activeFindings - Parsed entries from ivanti_findings_cache
|
||||
* @returns {{ id: string, title: string, severity: number } | null}
|
||||
*/
|
||||
function findRelatedActive(archive, activeFindings) {
|
||||
const archiveTitle = (archive.finding_title || '').toLowerCase();
|
||||
|
||||
const matches = activeFindings.filter(f => {
|
||||
if (f.hostName !== archive.host_name) return false;
|
||||
if (f.id === archive.finding_id) return false;
|
||||
|
||||
const activeTitle = (f.title || '').toLowerCase();
|
||||
if (!archiveTitle.includes(activeTitle) && !activeTitle.includes(archiveTitle)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (matches.length === 0) return null;
|
||||
|
||||
const best = matches.reduce((a, b) => (b.severity > a.severity ? b : a));
|
||||
return { id: best.id, title: best.title, severity: best.severity };
|
||||
}
|
||||
|
||||
function createIvantiArchiveRouter(db, requireAuth) {
|
||||
const router = express.Router();
|
||||
|
||||
@@ -45,7 +76,37 @@ function createIvantiArchiveRouter(db, requireAuth) {
|
||||
});
|
||||
});
|
||||
|
||||
res.json({ archives, total: archives.length });
|
||||
// Fetch and parse active findings cache for related-finding enrichment
|
||||
let activeFindings = [];
|
||||
try {
|
||||
const cacheRow = await new Promise((resolve, reject) => {
|
||||
db.get(
|
||||
'SELECT findings_json FROM ivanti_findings_cache WHERE id = 1',
|
||||
(err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (cacheRow && cacheRow.findings_json) {
|
||||
activeFindings = JSON.parse(cacheRow.findings_json);
|
||||
}
|
||||
} catch (cacheErr) {
|
||||
console.warn('Failed to load findings cache for related-active matching:', cacheErr);
|
||||
}
|
||||
|
||||
if (!Array.isArray(activeFindings)) {
|
||||
activeFindings = [];
|
||||
}
|
||||
|
||||
// Enrich each archive record with related active finding info
|
||||
const enrichedArchives = archives.map(archive => ({
|
||||
...archive,
|
||||
related_active: findRelatedActive(archive, activeFindings)
|
||||
}));
|
||||
|
||||
res.json({ archives: enrichedArchives, total: enrichedArchives.length });
|
||||
} catch (err) {
|
||||
console.error('Archive list error:', err);
|
||||
res.status(500).json({ error: 'Failed to fetch archive records' });
|
||||
|
||||
@@ -168,7 +168,7 @@ function initArchiveTables(db) {
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
ip_address TEXT NOT NULL DEFAULT '',
|
||||
current_state TEXT NOT NULL CHECK(current_state IN ('ARCHIVED','RETURNED','CLOSED')),
|
||||
current_state TEXT NOT NULL CHECK(current_state IN ('ARCHIVED','RETURNED','CLOSED','CLOSED_GONE')),
|
||||
last_severity REAL NOT NULL DEFAULT 0,
|
||||
first_archived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_transition_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -275,6 +275,7 @@ async function detectArchiveChanges(db, previousFindings, currentFindings) {
|
||||
|
||||
// 2. Returned findings: in current AND has existing ARCHIVED record → RETURNED
|
||||
const currentIdsList = [...currentIds];
|
||||
const returnedArchiveIds = []; // track archive IDs of returned findings for classification
|
||||
if (currentIdsList.length > 0) {
|
||||
try {
|
||||
const archivedRecords = await dbAll(db,
|
||||
@@ -297,6 +298,7 @@ async function detectArchiveChanges(db, previousFindings, currentFindings) {
|
||||
VALUES (?, 'ARCHIVED', 'RETURNED', ?, 'reappeared_in_sync', datetime('now'))`,
|
||||
[record.id, severity]
|
||||
);
|
||||
returnedArchiveIds.push(record.id);
|
||||
console.log(`[Archive Detection] Finding ${record.finding_id} returned (ARCHIVED → RETURNED)`);
|
||||
}
|
||||
}
|
||||
@@ -305,7 +307,40 @@ async function detectArchiveChanges(db, previousFindings, currentFindings) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Archive Detection] Processed ${disappearedIds.length} disappeared, checked ${currentIdsList.length} current findings against archive`);
|
||||
// Count returned findings for anomaly summary
|
||||
let returnedCount = returnedArchiveIds.length;
|
||||
|
||||
// Classify returned findings by looking up the reason they were originally archived.
|
||||
// This tells us *why* they came back (e.g., BU reassignment back to team).
|
||||
const returnClassification = { bu_reassignment: 0, severity_drift: 0, closed_on_platform: 0, decommissioned: 0 };
|
||||
for (const archiveId of returnedArchiveIds) {
|
||||
try {
|
||||
// Find the most recent ARCHIVED transition reason *before* this return
|
||||
const transition = await dbGet(db,
|
||||
`SELECT reason FROM ivanti_archive_transitions
|
||||
WHERE archive_id = ? AND to_state = 'ARCHIVED'
|
||||
AND transitioned_at <= datetime('now')
|
||||
ORDER BY transitioned_at DESC LIMIT 1`,
|
||||
[archiveId]
|
||||
);
|
||||
if (transition && transition.reason) {
|
||||
// Reason format is either a plain key or "key:detail" (e.g., "bu_reassignment:SOME-BU")
|
||||
const reasonKey = transition.reason.split(':')[0];
|
||||
if (reasonKey in returnClassification) {
|
||||
returnClassification[reasonKey]++;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// Non-fatal — skip this finding's classification
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Archive Detection] Processed ${disappearedIds.length} disappeared, ${returnedCount} returned, checked ${currentIdsList.length} current findings against archive`);
|
||||
if (returnedCount > 0) {
|
||||
console.log(`[Archive Detection] Return classification:`, returnClassification);
|
||||
}
|
||||
|
||||
return { disappearedIds, returnedCount, returnClassification };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -350,6 +385,54 @@ async function detectClosedFindings(db, closedFindingIds) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Closed-gone detection — find archive CLOSED findings that vanished from the
|
||||
// Ivanti closed API set. These are findings we previously confirmed as closed
|
||||
// but that no longer appear in the closed results (likely VRR rescore below
|
||||
// the severity threshold).
|
||||
// ---------------------------------------------------------------------------
|
||||
async function detectClosedGoneFindings(db, closedFindingIds) {
|
||||
if (!closedFindingIds) return;
|
||||
|
||||
const closedSet = new Set(closedFindingIds.map(String));
|
||||
|
||||
try {
|
||||
// Get all findings we previously marked as CLOSED in the archive
|
||||
const records = await dbAll(db,
|
||||
`SELECT id, finding_id, last_severity FROM ivanti_finding_archives WHERE current_state = 'CLOSED'`
|
||||
);
|
||||
|
||||
let goneCount = 0;
|
||||
for (const record of records) {
|
||||
// If this finding is still in the closed API set, it's fine
|
||||
if (closedSet.has(record.finding_id)) continue;
|
||||
|
||||
try {
|
||||
await dbRun(db,
|
||||
`UPDATE ivanti_finding_archives
|
||||
SET current_state = 'CLOSED_GONE', last_transition_at = datetime('now')
|
||||
WHERE id = ?`,
|
||||
[record.id]
|
||||
);
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_archive_transitions (archive_id, from_state, to_state, severity_at_transition, reason, transitioned_at)
|
||||
VALUES (?, 'CLOSED', 'CLOSED_GONE', ?, 'disappeared_from_closed_set', datetime('now'))`,
|
||||
[record.id, record.last_severity || 0]
|
||||
);
|
||||
goneCount++;
|
||||
} catch (err) {
|
||||
console.error(`[Archive Detection] Error marking finding ${record.finding_id} as CLOSED_GONE:`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (goneCount > 0) {
|
||||
console.warn(`[Archive Detection] ${goneCount} previously-closed findings disappeared from the Ivanti closed set (CLOSED → CLOSED_GONE)`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Archive Detection] Error in closed-gone detection:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Extract only the fields we need from a raw finding object
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -397,6 +480,7 @@ function extractFinding(f) {
|
||||
|
||||
return {
|
||||
id: String(f.id),
|
||||
hostId: f.host?.hostId || null,
|
||||
title: f.title || '',
|
||||
severity: typeof f.severity === 'number' ? f.severity : parseFloat(f.severity) || 0,
|
||||
vrrGroup: f.vrrGroup || f.severityGroup || '',
|
||||
@@ -460,14 +544,36 @@ async function syncClosedCount(db, openCount, apiKey, clientId, skipTls) {
|
||||
[openCount, closedCount]
|
||||
);
|
||||
|
||||
// Drift guard — if the new total (open+closed) drops by more than 50%
|
||||
// compared to the most recent history snapshot, skip writing to history.
|
||||
// This prevents partial API responses from corrupting the trend chart.
|
||||
const newTotal = openCount + closedCount;
|
||||
let skipHistory = false;
|
||||
try {
|
||||
const prev = await dbGet(db,
|
||||
`SELECT open_count, closed_count FROM ivanti_counts_history ORDER BY recorded_at DESC LIMIT 1`
|
||||
);
|
||||
if (prev) {
|
||||
const prevTotal = (prev.open_count || 0) + (prev.closed_count || 0);
|
||||
if (prevTotal > 0 && newTotal < prevTotal * 0.5) {
|
||||
console.warn(`[Ivanti Findings] Drift guard triggered — new total ${newTotal} is <50% of previous ${prevTotal}. Skipping history write.`);
|
||||
skipHistory = true;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Drift guard check failed (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
// Append a snapshot to history — every sync is stored; the history
|
||||
// endpoint aggregates to last-per-day at query time (Option B).
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_counts_history (open_count, closed_count) VALUES (?, ?)`,
|
||||
[openCount, closedCount]
|
||||
);
|
||||
if (!skipHistory) {
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_counts_history (open_count, closed_count) VALUES (?, ?)`,
|
||||
[openCount, closedCount]
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`[Ivanti Findings] Counts updated — open: ${openCount}, closed: ${closedCount}`);
|
||||
console.log(`[Ivanti Findings] Counts updated — open: ${openCount}, closed: ${closedCount}${skipHistory ? ' (history write skipped — drift guard)' : ''}`);
|
||||
|
||||
// Detect closed findings in the archive — wrap in try/catch so errors don't break sync
|
||||
try {
|
||||
@@ -475,6 +581,13 @@ async function syncClosedCount(db, openCount, apiKey, clientId, skipTls) {
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Closed finding archive detection failed (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
// Detect findings that vanished from the closed set — CLOSED → CLOSED_GONE
|
||||
try {
|
||||
await detectClosedGoneFindings(db, closedFindingIds);
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Closed-gone detection failed (non-fatal):', err.message);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Failed to fetch closed count:', err.message);
|
||||
// Still update open count so it stays in sync; leave closed_count as-is
|
||||
@@ -636,6 +749,29 @@ async function syncFindings(db) {
|
||||
console.error('[Ivanti Findings] Failed to read previous findings for archive detection:', err.message);
|
||||
}
|
||||
|
||||
// Per-finding BU comparison — detect BU changes across syncs (Task 5.1)
|
||||
try {
|
||||
const previousMap = new Map(previousFindings.map(f => [String(f.id), f]));
|
||||
for (const finding of allFindings) {
|
||||
try {
|
||||
const prev = previousMap.get(String(finding.id));
|
||||
if (prev && prev.buOwnership && finding.buOwnership && prev.buOwnership !== finding.buOwnership) {
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_finding_bu_history (finding_id, finding_title, host_name, previous_bu, new_bu, detected_at)
|
||||
VALUES (?, ?, ?, ?, ?, datetime('now'))`,
|
||||
[String(finding.id), finding.title || '', finding.hostName || '', prev.buOwnership, finding.buOwnership]
|
||||
);
|
||||
console.log(`[BU Tracking] Finding ${finding.id} BU changed: ${prev.buOwnership} → ${finding.buOwnership}`);
|
||||
}
|
||||
// First-time findings (no prev entry) — store BU without recording a change event
|
||||
} catch (err) {
|
||||
console.error(`[BU Tracking] Error recording BU change for finding ${finding.id}:`, err.message);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[BU Tracking] BU comparison failed (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
await dbRun(db,
|
||||
`UPDATE ivanti_findings_cache SET total=?, findings_json=?, synced_at=datetime('now'), sync_status='success', error_message=NULL WHERE id=1`,
|
||||
[allFindings.length, JSON.stringify(allFindings)]
|
||||
@@ -645,14 +781,61 @@ async function syncFindings(db) {
|
||||
|
||||
// Archive detection — compare previous vs current to detect disappeared/returned findings
|
||||
// Only runs after a successful sync (skipped on error per requirement 1.5)
|
||||
let archiveResult = { disappearedIds: [], returnedCount: 0, returnClassification: {} };
|
||||
try {
|
||||
await detectArchiveChanges(db, previousFindings, allFindings);
|
||||
archiveResult = await detectArchiveChanges(db, previousFindings, allFindings) || { disappearedIds: [], returnedCount: 0, returnClassification: {} };
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Archive detection failed (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
// Read previous counts BEFORE syncClosedCount updates them — needed for anomaly deltas
|
||||
let previousOpenCount = 0;
|
||||
let previousClosedCount = 0;
|
||||
try {
|
||||
const prevCounts = await dbGet(db,
|
||||
`SELECT open_count, closed_count FROM ivanti_counts_cache WHERE id = 1`
|
||||
);
|
||||
if (prevCounts) {
|
||||
previousOpenCount = prevCounts.open_count || 0;
|
||||
previousClosedCount = prevCounts.closed_count || 0;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Failed to read previous counts for anomaly summary (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
await syncClosedCount(db, allFindings.length, apiKey, clientId, skipTls);
|
||||
await syncFPWorkflowCounts(db, allFindings, apiKey, clientId, skipTls);
|
||||
|
||||
// Post-sync: BU drift checker for newly archived findings
|
||||
let classificationBreakdown = { bu_reassignment: 0, severity_drift: 0, closed_on_platform: 0, decommissioned: 0 };
|
||||
try {
|
||||
classificationBreakdown = await runBUDriftChecker(db, archiveResult.disappearedIds, apiKey, clientId, skipTls);
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] BU drift checker failed (non-fatal):', err.message);
|
||||
}
|
||||
|
||||
// Post-sync: Compute and store anomaly summary
|
||||
try {
|
||||
const currentCounts = await dbGet(db,
|
||||
`SELECT open_count, closed_count FROM ivanti_counts_cache WHERE id = 1`
|
||||
);
|
||||
const currentOpenCount = currentCounts?.open_count || 0;
|
||||
const currentClosedCount = currentCounts?.closed_count || 0;
|
||||
const openCountDelta = currentOpenCount - previousOpenCount;
|
||||
const closedCountDelta = currentClosedCount - previousClosedCount;
|
||||
|
||||
await computeAnomalySummary(
|
||||
db,
|
||||
openCountDelta,
|
||||
closedCountDelta,
|
||||
archiveResult.disappearedIds.length,
|
||||
archiveResult.returnedCount,
|
||||
classificationBreakdown,
|
||||
archiveResult.returnClassification || {}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] Anomaly summary failed (non-fatal):', err.message);
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = err.message || 'Unknown error';
|
||||
console.error('[Ivanti Findings] Sync failed:', msg);
|
||||
@@ -770,6 +953,155 @@ async function readStateWithNotes(db) {
|
||||
return state;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BU Drift Checker — post-sync classification of newly archived findings
|
||||
// ---------------------------------------------------------------------------
|
||||
const EXPECTED_BUS = new Set(['NTS-AEO-ACCESS-ENG', 'NTS-AEO-STEAM']);
|
||||
|
||||
async function runBUDriftChecker(db, newlyArchivedIds, apiKey, clientId, skipTls) {
|
||||
const summary = { bu_reassignment: 0, severity_drift: 0, closed_on_platform: 0, decommissioned: 0 };
|
||||
|
||||
if (!newlyArchivedIds || newlyArchivedIds.length === 0) return summary;
|
||||
|
||||
const urlPath = `/client/${encodeURIComponent(clientId)}/hostFinding/search`;
|
||||
const chunkSize = 50;
|
||||
|
||||
// Collect all API results across batches
|
||||
const foundMap = new Map();
|
||||
|
||||
for (let i = 0; i < newlyArchivedIds.length; i += chunkSize) {
|
||||
const chunk = newlyArchivedIds.slice(i, i + chunkSize);
|
||||
const idList = chunk.join(',');
|
||||
|
||||
try {
|
||||
const filters = [
|
||||
{
|
||||
field: 'id',
|
||||
exclusive: false,
|
||||
operator: 'IN',
|
||||
orWithPrevious: false,
|
||||
implicitFilters: [],
|
||||
value: idList,
|
||||
caseSensitive: false
|
||||
}
|
||||
];
|
||||
|
||||
let page = 0;
|
||||
let totalPages = 1;
|
||||
|
||||
do {
|
||||
const body = {
|
||||
filters,
|
||||
projection: 'internal',
|
||||
sort: [{ field: 'severity', direction: 'ASC' }],
|
||||
page,
|
||||
size: 100
|
||||
};
|
||||
|
||||
const result = await ivantiPost(urlPath, body, apiKey, skipTls);
|
||||
if (result.status !== 200) {
|
||||
console.error(`[BU Drift Checker] API returned status ${result.status} for batch starting at index ${i}`);
|
||||
break;
|
||||
}
|
||||
|
||||
const data = JSON.parse(result.body);
|
||||
totalPages = data.page?.totalPages || 1;
|
||||
const findings = data._embedded?.hostFindings || [];
|
||||
|
||||
for (const f of findings) {
|
||||
const bu = f.assetCustomAttributes?.['1550_host_1']?.[0] || 'UNKNOWN';
|
||||
const severity = typeof f.severity === 'number' ? f.severity : parseFloat(f.severity) || 0;
|
||||
const state = f.status || f.generic_state || '';
|
||||
foundMap.set(String(f.id), { bu, severity, state });
|
||||
}
|
||||
|
||||
page++;
|
||||
} while (page < totalPages);
|
||||
|
||||
console.log(`[BU Drift Checker] Batch ${Math.floor(i / chunkSize) + 1}: queried ${chunk.length} IDs, found ${foundMap.size} so far`);
|
||||
} catch (err) {
|
||||
console.error(`[BU Drift Checker] Error querying batch at index ${i}:`, err.message);
|
||||
// Skip failed batch, continue with remaining
|
||||
}
|
||||
}
|
||||
|
||||
// Classify each archived finding and update the archive transition reason
|
||||
for (const id of newlyArchivedIds) {
|
||||
const found = foundMap.get(id);
|
||||
let classification;
|
||||
let reason;
|
||||
|
||||
if (!found) {
|
||||
classification = 'decommissioned';
|
||||
reason = 'decommissioned';
|
||||
} else if (!EXPECTED_BUS.has(found.bu)) {
|
||||
classification = 'bu_reassignment';
|
||||
reason = `bu_reassignment:${found.bu}`;
|
||||
} else if (found.severity < 8.5) {
|
||||
classification = 'severity_drift';
|
||||
reason = `severity_drift:${found.severity}`;
|
||||
} else if (found.state === 'Closed') {
|
||||
classification = 'closed_on_platform';
|
||||
reason = 'closed_on_platform';
|
||||
} else {
|
||||
// BU matches, severity >= 8.5, not closed — unexpected, leave as default
|
||||
classification = 'decommissioned';
|
||||
reason = 'decommissioned';
|
||||
}
|
||||
|
||||
summary[classification] = (summary[classification] || 0) + 1;
|
||||
|
||||
// Update the most recent archive transition reason for this finding
|
||||
try {
|
||||
const archive = await dbGet(db,
|
||||
`SELECT id FROM ivanti_finding_archives WHERE finding_id = ?`,
|
||||
[id]
|
||||
);
|
||||
if (archive) {
|
||||
await dbRun(db,
|
||||
`UPDATE ivanti_archive_transitions SET reason = ?
|
||||
WHERE archive_id = ? AND id = (
|
||||
SELECT id FROM ivanti_archive_transitions
|
||||
WHERE archive_id = ? ORDER BY transitioned_at DESC LIMIT 1
|
||||
)`,
|
||||
[reason, archive.id, archive.id]
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`[BU Drift Checker] Error updating transition reason for finding ${id}:`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[BU Drift Checker] Classification complete:`, summary);
|
||||
return summary;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Anomaly Summary — compute and store post-sync anomaly report
|
||||
// ---------------------------------------------------------------------------
|
||||
async function computeAnomalySummary(db, openCountDelta, closedCountDelta, newlyArchivedCount, returnedCount, classificationBreakdown, returnClassificationBreakdown) {
|
||||
try {
|
||||
const isSignificant = newlyArchivedCount > 5 ? 1 : 0;
|
||||
const classificationJson = JSON.stringify(classificationBreakdown || {});
|
||||
const returnClassificationJson = JSON.stringify(returnClassificationBreakdown || {});
|
||||
|
||||
await dbRun(db,
|
||||
`INSERT INTO ivanti_sync_anomaly_log
|
||||
(sync_timestamp, open_count_delta, closed_count_delta, newly_archived_count, returned_count, classification_json, return_classification_json, is_significant)
|
||||
VALUES (datetime('now'), ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[openCountDelta, closedCountDelta, newlyArchivedCount, returnedCount, classificationJson, returnClassificationJson, isSignificant]
|
||||
);
|
||||
|
||||
console.log(`[Anomaly Summary] Sync anomaly logged — open_delta: ${openCountDelta}, closed_delta: ${closedCountDelta}, archived: ${newlyArchivedCount}, returned: ${returnedCount}, significant: ${!!isSignificant}`);
|
||||
console.log(`[Anomaly Summary] Classification:`, classificationBreakdown);
|
||||
if (returnedCount > 0) {
|
||||
console.log(`[Anomaly Summary] Return classification:`, returnClassificationBreakdown);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Anomaly Summary] Failed to write anomaly summary (non-fatal):', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Router
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -782,7 +1114,14 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
|
||||
router.use(requireAuth(db));
|
||||
|
||||
// GET / — cached findings with notes merged in
|
||||
/**
|
||||
* GET /api/ivanti/findings
|
||||
*
|
||||
* Return cached Ivanti findings with notes and overrides merged in.
|
||||
*
|
||||
* @returns {Object} 200 - { findings: Array<Object>, lastSync: string|null, overrides: Object }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
res.json(await readStateWithNotes(db));
|
||||
@@ -791,7 +1130,15 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// POST /sync — trigger immediate sync, return fresh state
|
||||
/**
|
||||
* POST /api/ivanti/findings/sync
|
||||
*
|
||||
* Trigger an immediate Ivanti findings sync and return the fresh state.
|
||||
* Requires Admin or Standard_User group.
|
||||
*
|
||||
* @returns {Object} 200 - { findings: Array<Object>, lastSync: string|null, overrides: Object }
|
||||
* @returns {Object} 500 - { error: string } if sync ran but state could not be read
|
||||
*/
|
||||
router.post('/sync', requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
await syncFindings(db);
|
||||
try {
|
||||
@@ -801,7 +1148,14 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /counts — open vs closed totals for pie chart
|
||||
/**
|
||||
* GET /api/ivanti/findings/counts
|
||||
*
|
||||
* Return open vs closed finding totals for the pie chart.
|
||||
*
|
||||
* @returns {Object} 200 - { open: number, closed: number }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/counts', async (req, res) => {
|
||||
try {
|
||||
res.json(await readCounts(db));
|
||||
@@ -810,8 +1164,15 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /counts/history — last snapshot per day, ascending, for the trend chart.
|
||||
// Uses a window function (ROW_NUMBER) to pick the final sync of each calendar day.
|
||||
/**
|
||||
* GET /api/ivanti/findings/counts/history
|
||||
*
|
||||
* Return the last snapshot per day (ascending) for the trend chart.
|
||||
* Uses a ROW_NUMBER window function to pick the final sync of each calendar day.
|
||||
*
|
||||
* @returns {Object} 200 - { history: Array<{ date: string, open_count: number, closed_count: number }> }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/counts/history', async (req, res) => {
|
||||
try {
|
||||
const rows = await new Promise((resolve, reject) => {
|
||||
@@ -837,7 +1198,15 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /fp-workflow-counts — FP finding + unique workflow counts (open + closed)
|
||||
/**
|
||||
* GET /api/ivanti/findings/fp-workflow-counts
|
||||
*
|
||||
* Return FP finding counts and unique workflow ID counts (open + closed),
|
||||
* broken down by workflow status.
|
||||
*
|
||||
* @returns {Object} 200 - { findingCounts: Object, findingTotal: number, idCounts: Object, idTotal: number }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/fp-workflow-counts', async (req, res) => {
|
||||
try {
|
||||
const row = await new Promise((resolve, reject) => {
|
||||
@@ -860,7 +1229,172 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /:findingId/override — save or clear a field override (editor/admin only)
|
||||
/**
|
||||
* GET /api/ivanti/findings/anomaly/latest
|
||||
*
|
||||
* Return the most recent anomaly summary row from ivanti_sync_anomaly_log.
|
||||
* The classification_json column is parsed into an object in the response.
|
||||
*
|
||||
* @returns {Object} 200 - { anomaly: Object|null }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/anomaly/latest', async (req, res) => {
|
||||
try {
|
||||
const row = await dbGet(db,
|
||||
`SELECT id, sync_timestamp, open_count_delta, closed_count_delta,
|
||||
newly_archived_count, returned_count, classification_json, return_classification_json, is_significant
|
||||
FROM ivanti_sync_anomaly_log
|
||||
ORDER BY sync_timestamp DESC LIMIT 1`
|
||||
);
|
||||
if (!row) return res.json({ anomaly: null });
|
||||
let classification = {};
|
||||
try { classification = JSON.parse(row.classification_json || '{}'); } catch (_) {}
|
||||
let return_classification = {};
|
||||
try { return_classification = JSON.parse(row.return_classification_json || '{}'); } catch (_) {}
|
||||
res.json({
|
||||
anomaly: {
|
||||
id: row.id,
|
||||
sync_timestamp: row.sync_timestamp,
|
||||
open_count_delta: row.open_count_delta,
|
||||
closed_count_delta: row.closed_count_delta,
|
||||
newly_archived_count: row.newly_archived_count,
|
||||
returned_count: row.returned_count,
|
||||
classification,
|
||||
return_classification,
|
||||
is_significant: !!row.is_significant
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] GET /anomaly/latest error:', err.message);
|
||||
res.status(500).json({ error: 'Database error reading latest anomaly' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/ivanti/findings/anomaly/history
|
||||
*
|
||||
* Return anomaly history. Accepts optional `from` and `to` query parameters
|
||||
* (ISO date strings) for date-range filtering (inclusive). If neither is
|
||||
* provided, returns the last 30 rows ordered by sync_timestamp descending.
|
||||
*
|
||||
* @query {string} [from] - Inclusive start date (ISO string)
|
||||
* @query {string} [to] - Inclusive end date (ISO string)
|
||||
*
|
||||
* @returns {Object} 200 - { history: Array<Object> }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/anomaly/history', async (req, res) => {
|
||||
try {
|
||||
const { from, to } = req.query;
|
||||
let rows;
|
||||
|
||||
if (from && to) {
|
||||
rows = await dbAll(db,
|
||||
`SELECT sync_timestamp, open_count_delta, closed_count_delta,
|
||||
newly_archived_count, returned_count, classification_json, return_classification_json, is_significant
|
||||
FROM ivanti_sync_anomaly_log
|
||||
WHERE sync_timestamp >= ? AND sync_timestamp <= ?
|
||||
ORDER BY sync_timestamp DESC`,
|
||||
[from, to]
|
||||
);
|
||||
} else {
|
||||
rows = await dbAll(db,
|
||||
`SELECT sync_timestamp, open_count_delta, closed_count_delta,
|
||||
newly_archived_count, returned_count, classification_json, return_classification_json, is_significant
|
||||
FROM ivanti_sync_anomaly_log
|
||||
ORDER BY sync_timestamp DESC LIMIT 30`
|
||||
);
|
||||
}
|
||||
|
||||
const history = rows.map(row => {
|
||||
let classification = {};
|
||||
try { classification = JSON.parse(row.classification_json || '{}'); } catch (_) {}
|
||||
let return_classification = {};
|
||||
try { return_classification = JSON.parse(row.return_classification_json || '{}'); } catch (_) {}
|
||||
return {
|
||||
sync_timestamp: row.sync_timestamp,
|
||||
open_count_delta: row.open_count_delta,
|
||||
closed_count_delta: row.closed_count_delta,
|
||||
newly_archived_count: row.newly_archived_count,
|
||||
returned_count: row.returned_count,
|
||||
classification,
|
||||
return_classification,
|
||||
is_significant: !!row.is_significant
|
||||
};
|
||||
});
|
||||
|
||||
res.json({ history });
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] GET /anomaly/history error:', err.message);
|
||||
res.status(500).json({ error: 'Database error reading anomaly history' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/ivanti/findings/bu-changes
|
||||
*
|
||||
* Return all BU change events from ivanti_finding_bu_history,
|
||||
* ordered by detected_at descending (newest first).
|
||||
*
|
||||
* @returns {Object} 200 - { changes: Array<Object> }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/bu-changes', async (req, res) => {
|
||||
try {
|
||||
const rows = await dbAll(db,
|
||||
`SELECT id, finding_id, finding_title, host_name, previous_bu, new_bu, detected_at
|
||||
FROM ivanti_finding_bu_history
|
||||
ORDER BY detected_at DESC`
|
||||
);
|
||||
res.json({ changes: rows });
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] GET /bu-changes error:', err.message);
|
||||
res.status(500).json({ error: 'Database error reading BU changes' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/ivanti/findings/:findingId/bu-history
|
||||
*
|
||||
* Return BU change history for a specific finding from ivanti_finding_bu_history,
|
||||
* ordered by detected_at descending (newest first).
|
||||
*
|
||||
* @param {string} findingId - The finding identifier (URL param)
|
||||
*
|
||||
* @returns {Object} 200 - { finding_id: string, history: Array<Object> }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.get('/:findingId/bu-history', async (req, res) => {
|
||||
try {
|
||||
const { findingId } = req.params;
|
||||
const rows = await dbAll(db,
|
||||
`SELECT previous_bu, new_bu, detected_at
|
||||
FROM ivanti_finding_bu_history
|
||||
WHERE finding_id = ?
|
||||
ORDER BY detected_at DESC`,
|
||||
[findingId]
|
||||
);
|
||||
res.json({ finding_id: findingId, history: rows });
|
||||
} catch (err) {
|
||||
console.error('[Ivanti Findings] GET /:findingId/bu-history error:', err.message);
|
||||
res.status(500).json({ error: 'Database error reading finding BU history' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT /api/ivanti/findings/:findingId/override
|
||||
*
|
||||
* Save or clear a field override for a finding. Requires Admin or Standard_User group.
|
||||
* Sending an empty value clears the override (reverts to Ivanti-sourced data).
|
||||
*
|
||||
* @param {string} findingId - The finding identifier (URL param)
|
||||
* @body {string} field - The field to override; must be one of 'hostName', 'dns'
|
||||
* @body {string} [value] - The override value; empty or omitted to clear
|
||||
*
|
||||
* @returns {Object} 200 - { finding_id: string, field: string, value: string|null }
|
||||
* @returns {Object} 400 - { error: string } when field is not in the allowed list
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
const OVERRIDE_ALLOWED = ['hostName', 'dns'];
|
||||
router.put('/:findingId/override', requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { findingId } = req.params;
|
||||
@@ -896,7 +1430,18 @@ function createIvantiFindingsRouter(db, requireAuth) {
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /:findingId/note — save or update a note (max 255 chars enforced here)
|
||||
/**
|
||||
* PUT /api/ivanti/findings/:findingId/note
|
||||
*
|
||||
* Save or update a note for a finding (max 255 characters).
|
||||
* Requires Admin or Standard_User group.
|
||||
*
|
||||
* @param {string} findingId - The finding identifier (URL param)
|
||||
* @body {string} [note] - The note text (truncated to 255 chars)
|
||||
*
|
||||
* @returns {Object} 200 - { finding_id: string, note: string }
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.put('/:findingId/note', requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { findingId } = req.params;
|
||||
const note = String(req.body.note || '').slice(0, 255);
|
||||
@@ -920,3 +1465,6 @@ module.exports = createIvantiFindingsRouter;
|
||||
module.exports.detectArchiveChanges = detectArchiveChanges;
|
||||
module.exports.detectClosedFindings = detectClosedFindings;
|
||||
module.exports.initArchiveTables = initArchiveTables;
|
||||
module.exports.runBUDriftChecker = runBUDriftChecker;
|
||||
module.exports.computeAnomalySummary = computeAnomalySummary;
|
||||
module.exports.extractFinding = extractFinding;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ const express = require('express');
|
||||
const { requireGroup } = require('../middleware/auth');
|
||||
const logAudit = require('../helpers/auditLog');
|
||||
|
||||
const VALID_WORKFLOW_TYPES = ['FP', 'Archer', 'CARD'];
|
||||
const VALID_WORKFLOW_TYPES = ['FP', 'Archer', 'CARD', 'GRANITE'];
|
||||
const VALID_STATUSES = ['pending', 'complete'];
|
||||
|
||||
function isValidVendor(vendor) {
|
||||
@@ -27,20 +27,27 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
*/
|
||||
router.get('/', requireAuth(db), (req, res) => {
|
||||
db.all(
|
||||
`SELECT * FROM ivanti_todo_queue
|
||||
WHERE user_id = ?
|
||||
ORDER BY vendor ASC, created_at ASC`,
|
||||
`SELECT q.*,
|
||||
o.value AS override_hostname
|
||||
FROM ivanti_todo_queue q
|
||||
LEFT JOIN ivanti_finding_overrides o
|
||||
ON o.finding_id = q.finding_id AND o.field = 'hostName'
|
||||
WHERE q.user_id = ?
|
||||
ORDER BY q.vendor ASC, q.created_at ASC`,
|
||||
[req.user.id],
|
||||
(err, rows) => {
|
||||
if (err) {
|
||||
console.error('Error fetching todo queue:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
// Parse cves_json back to array for each row
|
||||
// Parse cves_json back to array; prefer overridden hostname
|
||||
const parsed = rows.map((r) => ({
|
||||
...r,
|
||||
hostname: r.override_hostname || r.hostname,
|
||||
cves: r.cves_json ? JSON.parse(r.cves_json) : [],
|
||||
}));
|
||||
// Clean up the extra column from the response
|
||||
parsed.forEach((r) => delete r.override_hostname);
|
||||
res.json(parsed);
|
||||
}
|
||||
);
|
||||
@@ -57,8 +64,8 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
* @body {string[]} [findings[].cves] - Optional array of CVE identifiers
|
||||
* @body {string} [findings[].ip_address] - Optional IP address (max 64 chars)
|
||||
* @body {string} [findings[].hostname] - Optional hostname (max 255 chars)
|
||||
* @body {string} workflow_type - One of 'FP', 'Archer', 'CARD'
|
||||
* @body {string} vendor - Required for FP/Archer (max 200 chars); optional for CARD
|
||||
* @body {string} workflow_type - One of 'FP', 'Archer', 'CARD', 'GRANITE'
|
||||
* @body {string} vendor - Required for FP/Archer (max 200 chars); optional for CARD/GRANITE
|
||||
*
|
||||
* @returns {Object} 201 - { items: Array<Object> } array of created queue items,
|
||||
* each with: id, user_id, finding_id, finding_title, cves_json, ip_address,
|
||||
@@ -82,10 +89,10 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
}
|
||||
|
||||
if (!VALID_WORKFLOW_TYPES.includes(workflow_type)) {
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, or CARD.' });
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, CARD, or GRANITE.' });
|
||||
}
|
||||
|
||||
if (workflow_type !== 'CARD') {
|
||||
if (!['CARD', 'GRANITE'].includes(workflow_type)) {
|
||||
if (!isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'vendor is required for FP and Archer workflows.' });
|
||||
}
|
||||
@@ -95,7 +102,7 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(400).json({ error: 'vendor must be under 200 chars.' });
|
||||
}
|
||||
|
||||
const vendorVal = workflow_type === 'CARD' ? '' : vendor.trim();
|
||||
const vendorVal = ['CARD', 'GRANITE'].includes(workflow_type) ? '' : vendor.trim();
|
||||
const userId = req.user.id;
|
||||
|
||||
// --- Transactional batch insert ---
|
||||
@@ -154,7 +161,11 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
// Fetch all inserted rows
|
||||
const placeholders = insertedIds.map(() => '?').join(',');
|
||||
db.all(
|
||||
`SELECT * FROM ivanti_todo_queue WHERE id IN (${placeholders})`,
|
||||
`SELECT q.*, o.value AS override_hostname
|
||||
FROM ivanti_todo_queue q
|
||||
LEFT JOIN ivanti_finding_overrides o
|
||||
ON o.finding_id = q.finding_id AND o.field = 'hostName'
|
||||
WHERE q.id IN (${placeholders})`,
|
||||
insertedIds,
|
||||
(fetchErr, fetchedRows) => {
|
||||
if (fetchErr) {
|
||||
@@ -162,10 +173,15 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
const items = (fetchedRows || []).map((r) => ({
|
||||
...r,
|
||||
cves: r.cves_json ? JSON.parse(r.cves_json) : [],
|
||||
}));
|
||||
const items = (fetchedRows || []).map((r) => {
|
||||
const item = {
|
||||
...r,
|
||||
hostname: r.override_hostname || r.hostname,
|
||||
cves: r.cves_json ? JSON.parse(r.cves_json) : [],
|
||||
};
|
||||
delete item.override_hostname;
|
||||
return item;
|
||||
});
|
||||
|
||||
// Audit log (fire-and-forget)
|
||||
logAudit(db, {
|
||||
@@ -203,8 +219,9 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
* @body {string} [finding_title] - Optional finding title (max 500 chars)
|
||||
* @body {string[]} [cves] - Optional array of CVE identifiers
|
||||
* @body {string} [ip_address] - Optional IP address (max 64 chars)
|
||||
* @body {string} [hostname] - Optional hostname (max 255 chars) * @body {string} vendor - Required for FP/Archer (max 200 chars); optional for CARD
|
||||
* @body {string} workflow_type - One of 'FP', 'Archer', 'CARD'
|
||||
* @body {string} [hostname] - Optional hostname (max 255 chars)
|
||||
* @body {string} workflow_type - One of 'FP', 'Archer', 'CARD', 'GRANITE'
|
||||
* @body {string} vendor - Required for FP/Archer (max 200 chars); optional for CARD/GRANITE
|
||||
*
|
||||
* @returns {Object} 201 - Created queue item with parsed cves array:
|
||||
* id, user_id, finding_id, finding_title, cves_json, ip_address,
|
||||
@@ -219,17 +236,17 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(400).json({ error: 'finding_id is required.' });
|
||||
}
|
||||
if (!VALID_WORKFLOW_TYPES.includes(workflow_type)) {
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, or CARD.' });
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, CARD, or GRANITE.' });
|
||||
}
|
||||
// Vendor is required for FP and Archer, optional for CARD
|
||||
if (workflow_type !== 'CARD' && !isValidVendor(vendor)) {
|
||||
// Vendor is required for FP and Archer, optional for CARD/GRANITE
|
||||
if (!['CARD', 'GRANITE'].includes(workflow_type) && !isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'vendor is required for FP and Archer workflows.' });
|
||||
}
|
||||
if (vendor !== undefined && vendor !== '' && !isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'vendor must be under 200 chars.' });
|
||||
}
|
||||
|
||||
const vendorVal = workflow_type === 'CARD' ? '' : vendor.trim();
|
||||
const vendorVal = ['CARD', 'GRANITE'].includes(workflow_type) ? '' : vendor.trim();
|
||||
const cvesJson = Array.isArray(cves) ? JSON.stringify(cves) : null;
|
||||
const ipVal = ip_address && typeof ip_address === 'string' ? ip_address.trim().slice(0, 64) : null;
|
||||
const hostVal = hostname && typeof hostname === 'string' ? hostname.trim().slice(0, 255) : null;
|
||||
@@ -248,13 +265,23 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
db.get(
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ?',
|
||||
`SELECT q.*, o.value AS override_hostname
|
||||
FROM ivanti_todo_queue q
|
||||
LEFT JOIN ivanti_finding_overrides o
|
||||
ON o.finding_id = q.finding_id AND o.field = 'hostName'
|
||||
WHERE q.id = ?`,
|
||||
[this.lastID],
|
||||
(err2, row) => {
|
||||
if (err2 || !row) {
|
||||
return res.status(201).json({ id: this.lastID, message: 'Added to queue.' });
|
||||
}
|
||||
res.status(201).json({ ...row, cves: row.cves_json ? JSON.parse(row.cves_json) : [] });
|
||||
const result = {
|
||||
...row,
|
||||
hostname: row.override_hostname || row.hostname,
|
||||
cves: row.cves_json ? JSON.parse(row.cves_json) : [],
|
||||
};
|
||||
delete result.override_hostname;
|
||||
res.status(201).json(result);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -268,7 +295,7 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
*
|
||||
* @param {string} id - Queue item ID (URL parameter)
|
||||
* @body {string} [vendor] - New vendor string (max 200 chars)
|
||||
* @body {string} [workflow_type] - One of 'FP', 'Archer', 'CARD'
|
||||
* @body {string} [workflow_type] - One of 'FP', 'Archer', 'CARD', 'GRANITE'
|
||||
* @body {string} [status] - One of 'pending', 'complete'
|
||||
*
|
||||
* @returns {Object} 200 - Updated queue item with parsed cves array:
|
||||
@@ -286,7 +313,7 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(400).json({ error: 'vendor must be a non-empty string (max 200 chars).' });
|
||||
}
|
||||
if (workflow_type !== undefined && !VALID_WORKFLOW_TYPES.includes(workflow_type)) {
|
||||
return res.status(400).json({ error: 'workflow_type must be FP or Archer.' });
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, CARD, or GRANITE.' });
|
||||
}
|
||||
if (status !== undefined && !VALID_STATUSES.includes(status)) {
|
||||
return res.status(400).json({ error: 'status must be pending or complete.' });
|
||||
@@ -336,13 +363,134 @@ function createIvantiTodoQueueRouter(db, requireAuth) {
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
db.get(
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ?',
|
||||
`SELECT q.*, o.value AS override_hostname
|
||||
FROM ivanti_todo_queue q
|
||||
LEFT JOIN ivanti_finding_overrides o
|
||||
ON o.finding_id = q.finding_id AND o.field = 'hostName'
|
||||
WHERE q.id = ?`,
|
||||
[id],
|
||||
(err3, row) => {
|
||||
if (err3 || !row) {
|
||||
return res.json({ message: 'Queue item updated.' });
|
||||
}
|
||||
res.json({ ...row, cves: row.cves_json ? JSON.parse(row.cves_json) : [] });
|
||||
const result = {
|
||||
...row,
|
||||
hostname: row.override_hostname || row.hostname,
|
||||
cves: row.cves_json ? JSON.parse(row.cves_json) : [],
|
||||
};
|
||||
delete result.override_hostname;
|
||||
res.json(result);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/ivanti/todo-queue/:id/redirect
|
||||
*
|
||||
* Redirect a completed queue item to a different workflow type.
|
||||
* Creates a new pending item copying finding data from the original.
|
||||
*
|
||||
* @param {string} id - Original queue item ID (URL parameter)
|
||||
* @body {string} workflow_type - Target workflow type: 'FP', 'Archer', 'CARD', or 'GRANITE'
|
||||
* @body {string} [vendor] - Required for FP/Archer (max 200 chars); ignored for CARD/GRANITE
|
||||
*
|
||||
* @returns {Object} 201 - Newly created queue item with parsed cves array
|
||||
* @returns {Object} 400 - { error: string } on validation failure or item not complete
|
||||
* @returns {Object} 404 - { error: string } if item not found for current user
|
||||
* @returns {Object} 500 - { error: string } on database error
|
||||
*/
|
||||
router.post('/:id/redirect', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { workflow_type, vendor } = req.body;
|
||||
|
||||
// --- Validation ---
|
||||
if (!VALID_WORKFLOW_TYPES.includes(workflow_type)) {
|
||||
return res.status(400).json({ error: 'workflow_type must be FP, Archer, CARD, or GRANITE.' });
|
||||
}
|
||||
|
||||
if (!['CARD', 'GRANITE'].includes(workflow_type)) {
|
||||
if (!isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'vendor is required for FP and Archer workflows.' });
|
||||
}
|
||||
}
|
||||
|
||||
if (vendor !== undefined && vendor !== '' && typeof vendor === 'string' && vendor.trim().length > 200) {
|
||||
return res.status(400).json({ error: 'vendor must be under 200 chars.' });
|
||||
}
|
||||
|
||||
const vendorVal = ['CARD', 'GRANITE'].includes(workflow_type) ? '' : vendor.trim();
|
||||
|
||||
// --- Fetch original item scoped to current user ---
|
||||
db.get(
|
||||
'SELECT * FROM ivanti_todo_queue WHERE id = ? AND user_id = ?',
|
||||
[id, req.user.id],
|
||||
(err, original) => {
|
||||
if (err) {
|
||||
console.error('Error fetching queue item for redirect:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!original) {
|
||||
return res.status(404).json({ error: 'Queue item not found.' });
|
||||
}
|
||||
if (original.status !== 'complete') {
|
||||
return res.status(400).json({ error: 'Only completed queue items can be redirected.' });
|
||||
}
|
||||
|
||||
// --- INSERT new row copying finding data from original ---
|
||||
db.run(
|
||||
`INSERT INTO ivanti_todo_queue
|
||||
(user_id, finding_id, finding_title, cves_json, ip_address, hostname, vendor, workflow_type)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[req.user.id, original.finding_id, original.finding_title, original.cves_json, original.ip_address, original.hostname, vendorVal, workflow_type],
|
||||
function (insertErr) {
|
||||
if (insertErr) {
|
||||
console.error('Error inserting redirected queue item:', insertErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
const newId = this.lastID;
|
||||
|
||||
// --- Fetch the inserted row ---
|
||||
db.get(
|
||||
`SELECT q.*, o.value AS override_hostname
|
||||
FROM ivanti_todo_queue q
|
||||
LEFT JOIN ivanti_finding_overrides o
|
||||
ON o.finding_id = q.finding_id AND o.field = 'hostName'
|
||||
WHERE q.id = ?`,
|
||||
[newId],
|
||||
(fetchErr, row) => {
|
||||
if (fetchErr || !row) {
|
||||
console.error('Error fetching redirected queue item:', fetchErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
// Audit log (fire-and-forget)
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'queue_item_redirected',
|
||||
entityType: 'ivanti_todo_queue',
|
||||
entityId: String(original.id),
|
||||
details: {
|
||||
original_workflow_type: original.workflow_type,
|
||||
target_workflow_type: workflow_type,
|
||||
new_item_id: newId,
|
||||
vendor: vendorVal,
|
||||
},
|
||||
ipAddress: req.ip,
|
||||
});
|
||||
|
||||
const result = {
|
||||
...row,
|
||||
hostname: row.override_hostname || row.hostname,
|
||||
cves: row.cves_json ? JSON.parse(row.cves_json) : [],
|
||||
};
|
||||
delete result.override_hostname;
|
||||
return res.status(201).json(result);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
809
backend/routes/jiraTickets.js
Normal file
809
backend/routes/jiraTickets.js
Normal file
@@ -0,0 +1,809 @@
|
||||
// routes/jiraTickets.js
|
||||
// Jira ticket CRUD + Jira REST API integration endpoints.
|
||||
// Extracted from server.js inline endpoints and extended with live Jira
|
||||
// operations (lookup, sync, create-in-jira, connection test).
|
||||
//
|
||||
// Charter Jira REST API compliance:
|
||||
// - All GETs include explicit field lists (no /rest/api/2/field)
|
||||
// - Sync uses bulk JQL search, not one-issue-at-a-time GETs
|
||||
// - No /rest/api/2/issue/bulk — updates are one at a time
|
||||
// - Inter-request delays enforced in jiraApi.js (1s GET, 2s write)
|
||||
// - Rate limits enforced client-side (1440/day, 60/min burst)
|
||||
|
||||
const express = require('express');
|
||||
const { requireAuth, requireGroup } = require('../middleware/auth');
|
||||
const logAudit = require('../helpers/auditLog');
|
||||
const jiraApi = require('../helpers/jiraApi');
|
||||
|
||||
// Validation helpers
|
||||
const CVE_ID_PATTERN = /^CVE-\d{4}-\d{4,}$/;
|
||||
const VALID_TICKET_STATUSES = ['Open', 'In Progress', 'Closed'];
|
||||
|
||||
function isValidCveId(cveId) {
|
||||
return typeof cveId === 'string' && CVE_ID_PATTERN.test(cveId);
|
||||
}
|
||||
|
||||
function isValidVendor(vendor) {
|
||||
return typeof vendor === 'string' && vendor.trim().length > 0 && vendor.length <= 200;
|
||||
}
|
||||
|
||||
function createJiraTicketsRouter(db) {
|
||||
const router = express.Router();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Jira API integration endpoints
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* GET /api/jira/connection-test
|
||||
*
|
||||
* Verify Jira credentials and connectivity by testing the configured
|
||||
* Jira API connection. Admin only.
|
||||
*
|
||||
* @returns {object} 200 - { connected: true, user: { name, ... } }
|
||||
* @returns {object} 502 - { connected: false, status, error } | { connected: false, error }
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.get('/connection-test', requireAuth(db), requireGroup('Admin'), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured. Set JIRA_BASE_URL and credentials in backend/.env.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await jiraApi.testConnection();
|
||||
if (result.ok) {
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_connection_test',
|
||||
entityType: 'jira_integration',
|
||||
entityId: null,
|
||||
details: { success: true, user: result.user.name },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
return res.json({ connected: true, user: result.user });
|
||||
}
|
||||
return res.status(502).json({ connected: false, status: result.status, error: result.body || result.error });
|
||||
} catch (err) {
|
||||
return res.status(502).json({ connected: false, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/jira/rate-limit
|
||||
*
|
||||
* Return current Jira API rate limit usage. Admin only.
|
||||
*
|
||||
* @returns {object} 200 - { burst: { remaining, limit, ... }, daily: { remaining, limit, ... } }
|
||||
*/
|
||||
router.get('/rate-limit', requireAuth(db), requireGroup('Admin'), (req, res) => {
|
||||
res.json(jiraApi.getRateLimitStatus());
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/jira/lookup/:issueKey
|
||||
*
|
||||
* Fetch a single issue from Jira by its issue key (e.g., PROJECT-123).
|
||||
* Uses explicit `?fields=` parameter per Charter Jira REST API requirement.
|
||||
*
|
||||
* @param {string} issueKey - Jira issue key (path parameter, format: PROJECT-123)
|
||||
* @returns {object} 200 - { key, summary, status, assignee, priority, issuetype, created, updated, self }
|
||||
* @returns {object} 400 - { error } when issue key format is invalid
|
||||
* @returns {object} 404 - { error } when issue not found in Jira
|
||||
* @returns {object} 429 - { error } when Jira rate limit exceeded
|
||||
* @returns {object} 502 - { error, details } on Jira API error
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.get('/lookup/:issueKey', requireAuth(db), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured.' });
|
||||
}
|
||||
|
||||
const { issueKey } = req.params;
|
||||
if (!issueKey || !/^[A-Z][A-Z0-9_]+-\d+$/.test(issueKey)) {
|
||||
return res.status(400).json({ error: 'Invalid Jira issue key format. Expected PROJECT-123.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await jiraApi.getIssue(issueKey);
|
||||
if (result.ok) {
|
||||
const issue = result.data;
|
||||
return res.json({
|
||||
key: issue.key,
|
||||
summary: issue.fields.summary,
|
||||
status: issue.fields.status ? issue.fields.status.name : null,
|
||||
assignee: issue.fields.assignee ? issue.fields.assignee.displayName : null,
|
||||
priority: issue.fields.priority ? issue.fields.priority.name : null,
|
||||
issuetype: issue.fields.issuetype ? issue.fields.issuetype.name : null,
|
||||
created: issue.fields.created,
|
||||
updated: issue.fields.updated,
|
||||
self: issue.self
|
||||
});
|
||||
}
|
||||
if (result.rateLimited) {
|
||||
return res.status(429).json({ error: 'Jira rate limit exceeded. Try again later.' });
|
||||
}
|
||||
return res.status(result.status === 404 ? 404 : 502).json({
|
||||
error: result.status === 404 ? 'Issue not found in Jira.' : 'Jira API error.',
|
||||
details: result.body
|
||||
});
|
||||
} catch (err) {
|
||||
return res.status(502).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/jira/search
|
||||
*
|
||||
* Search Jira issues using a JQL query. Results are capped at 1000 per page.
|
||||
* Charter compliance: JQL must include project+updated, assignee+updated,
|
||||
* or status+updated. Fields are always specified explicitly.
|
||||
*
|
||||
* @body {string} jql - JQL query string (required, max 2000 chars)
|
||||
* @body {number} [startAt] - Pagination offset
|
||||
* @body {number} [maxResults] - Page size (max 1000)
|
||||
* @body {string[]} [fields] - Explicit field list for the Jira response
|
||||
* @returns {object} 200 - { total, startAt, maxResults, issues: [{ key, summary, status, assignee, priority, issuetype, created, updated }] }
|
||||
* @returns {object} 400 - { error } when JQL is missing or too long
|
||||
* @returns {object} 429 - { error } when Jira rate limit exceeded
|
||||
* @returns {object} 502 - { error, details } on Jira search failure
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.post('/search', requireAuth(db), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured.' });
|
||||
}
|
||||
|
||||
const { jql, startAt, maxResults, fields } = req.body;
|
||||
if (!jql || typeof jql !== 'string' || jql.trim().length === 0) {
|
||||
return res.status(400).json({ error: 'JQL query is required.' });
|
||||
}
|
||||
if (jql.length > 2000) {
|
||||
return res.status(400).json({ error: 'JQL query too long (max 2000 chars).' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await jiraApi.searchIssues(jql, {
|
||||
startAt,
|
||||
maxResults: Math.min(maxResults || 1000, 1000),
|
||||
fields: fields || undefined
|
||||
});
|
||||
if (result.ok) {
|
||||
const data = result.data;
|
||||
return res.json({
|
||||
total: data.total,
|
||||
startAt: data.startAt,
|
||||
maxResults: data.maxResults,
|
||||
issues: (data.issues || []).map(issue => ({
|
||||
key: issue.key,
|
||||
summary: issue.fields.summary,
|
||||
status: issue.fields.status ? issue.fields.status.name : null,
|
||||
assignee: issue.fields.assignee ? issue.fields.assignee.displayName : null,
|
||||
priority: issue.fields.priority ? issue.fields.priority.name : null,
|
||||
issuetype: issue.fields.issuetype ? issue.fields.issuetype.name : null,
|
||||
created: issue.fields.created,
|
||||
updated: issue.fields.updated
|
||||
}))
|
||||
});
|
||||
}
|
||||
if (result.rateLimited) {
|
||||
return res.status(429).json({ error: 'Jira rate limit exceeded. Try again later.' });
|
||||
}
|
||||
return res.status(502).json({ error: 'Jira search failed.', details: result.body });
|
||||
} catch (err) {
|
||||
return res.status(502).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/jira/create-in-jira
|
||||
*
|
||||
* Create a new issue in Jira via the REST API and insert a linked local
|
||||
* record in the `jira_tickets` table. Requires Admin or Standard_User group.
|
||||
* Subject to 2s write delay enforced by jiraApi.
|
||||
*
|
||||
* @body {string} cve_id - CVE identifier (required, format: CVE-YYYY-NNNNN)
|
||||
* @body {string} vendor - Vendor name (required, max 200 chars)
|
||||
* @body {string} summary - Issue summary (required, max 255 chars)
|
||||
* @body {string} [description] - Issue description
|
||||
* @body {string} [project_key] - Jira project key (defaults to JIRA_PROJECT_KEY env var)
|
||||
* @body {string} [issue_type] - Jira issue type name (defaults to JIRA_ISSUE_TYPE env var)
|
||||
* @returns {object} 201 - { id, ticket_key, jira_url, message }
|
||||
* @returns {object} 207 - { warning, jira_key, jira_url, error } when Jira issue created but local save failed
|
||||
* @returns {object} 400 - { error } on validation failure
|
||||
* @returns {object} 429 - { error } when Jira rate limit exceeded
|
||||
* @returns {object} 502 - { error, details } on Jira API failure
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.post('/create-in-jira', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured.' });
|
||||
}
|
||||
|
||||
const { cve_id, vendor, summary, description, project_key, issue_type } = req.body;
|
||||
|
||||
if (!cve_id || !isValidCveId(cve_id)) {
|
||||
return res.status(400).json({ error: 'Valid CVE ID is required.' });
|
||||
}
|
||||
if (!vendor || !isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'Valid vendor is required.' });
|
||||
}
|
||||
if (!summary || typeof summary !== 'string' || summary.trim().length === 0 || summary.length > 255) {
|
||||
return res.status(400).json({ error: 'Summary is required (max 255 chars).' });
|
||||
}
|
||||
|
||||
const projectKey = project_key || jiraApi.JIRA_PROJECT_KEY;
|
||||
const issueType = issue_type || jiraApi.JIRA_ISSUE_TYPE;
|
||||
|
||||
if (!projectKey) {
|
||||
return res.status(400).json({ error: 'Project key is required. Set JIRA_PROJECT_KEY in .env or provide project_key in request.' });
|
||||
}
|
||||
|
||||
const fields = {
|
||||
project: { key: projectKey },
|
||||
summary: summary.trim(),
|
||||
issuetype: { name: issueType }
|
||||
};
|
||||
|
||||
if (description) {
|
||||
fields.description = description;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await jiraApi.createIssue(fields);
|
||||
if (!result.ok) {
|
||||
if (result.rateLimited) {
|
||||
return res.status(429).json({ error: 'Jira rate limit exceeded. Try again later.' });
|
||||
}
|
||||
return res.status(502).json({ error: 'Failed to create Jira issue.', details: result.body });
|
||||
}
|
||||
|
||||
const jiraIssue = result.data;
|
||||
const ticketKey = jiraIssue.key;
|
||||
const jiraUrl = jiraIssue.self
|
||||
? jiraIssue.self.replace(/\/rest\/api\/2\/issue\/.*/, `/browse/${ticketKey}`)
|
||||
: null;
|
||||
|
||||
db.run(
|
||||
`INSERT INTO jira_tickets (cve_id, vendor, ticket_key, url, summary, status, jira_id, jira_status, last_synced_at, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), ?)`,
|
||||
[cve_id, vendor, ticketKey, jiraUrl, summary.trim(), 'Open', jiraIssue.id, 'Open', req.user.id],
|
||||
function(err) {
|
||||
if (err) {
|
||||
console.error('Error saving local Jira ticket record:', err);
|
||||
return res.status(207).json({
|
||||
warning: 'Issue created in Jira but local record failed to save.',
|
||||
jira_key: ticketKey,
|
||||
jira_url: jiraUrl,
|
||||
error: err.message
|
||||
});
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_create_via_api',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: this.lastID.toString(),
|
||||
details: { cve_id, vendor, ticket_key: ticketKey, jira_id: jiraIssue.id, project_key: projectKey },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
id: this.lastID,
|
||||
ticket_key: ticketKey,
|
||||
jira_url: jiraUrl,
|
||||
message: 'Jira issue created and linked successfully'
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
return res.status(502).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/jira/sync-all
|
||||
*
|
||||
* Bulk-sync all local tickets that have a Jira key by fetching their
|
||||
* latest status from Jira. Uses a single JQL bulk search per batch
|
||||
* instead of one GET per ticket (Charter-compliant). Stops early if
|
||||
* the rate limit budget is running low. Admin only.
|
||||
*
|
||||
* @returns {object} 200 - { synced, failed, skipped, unchanged, errors: string[] }
|
||||
* @returns {object} 500 - { error } on database error
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.post('/sync-all', requireAuth(db), requireGroup('Admin'), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured.' });
|
||||
}
|
||||
|
||||
db.all(
|
||||
"SELECT * FROM jira_tickets WHERE ticket_key IS NOT NULL AND ticket_key != ''",
|
||||
[],
|
||||
async (err, tickets) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
if (tickets.length === 0) {
|
||||
return res.json({ synced: 0, failed: 0, skipped: 0, unchanged: 0, errors: [] });
|
||||
}
|
||||
|
||||
const results = { synced: 0, failed: 0, skipped: 0, unchanged: 0, errors: [] };
|
||||
|
||||
// Batch keys into groups of 100 for JQL (avoid overly long queries)
|
||||
const BATCH_SIZE = 100;
|
||||
const batches = [];
|
||||
for (let i = 0; i < tickets.length; i += BATCH_SIZE) {
|
||||
batches.push(tickets.slice(i, i + BATCH_SIZE));
|
||||
}
|
||||
|
||||
for (const batch of batches) {
|
||||
// Check rate limit before each batch
|
||||
const rateStatus = jiraApi.getRateLimitStatus();
|
||||
if (rateStatus.burst.remaining <= 5 || rateStatus.daily.remaining <= 10) {
|
||||
const remaining = tickets.length - results.synced - results.failed - results.unchanged;
|
||||
results.skipped += remaining;
|
||||
results.errors.push('Rate limit approaching — stopped sync early to preserve budget.');
|
||||
break;
|
||||
}
|
||||
|
||||
const keys = batch.map(t => t.ticket_key);
|
||||
try {
|
||||
// Bulk JQL search — Charter-compliant, single request per batch
|
||||
const result = await jiraApi.searchIssuesByKeys(keys);
|
||||
if (!result.ok) {
|
||||
if (result.rateLimited) {
|
||||
results.skipped += batch.length;
|
||||
results.errors.push('Jira rate limit hit during sync.');
|
||||
break;
|
||||
}
|
||||
results.failed += batch.length;
|
||||
results.errors.push(`Batch search failed: HTTP ${result.status}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Build a map of key → Jira issue data
|
||||
const issueMap = {};
|
||||
for (const issue of (result.data.issues || [])) {
|
||||
issueMap[issue.key] = issue;
|
||||
}
|
||||
|
||||
// Update each local ticket from the search results
|
||||
for (const ticket of batch) {
|
||||
const issue = issueMap[ticket.ticket_key];
|
||||
if (!issue) {
|
||||
// Issue not returned — either not updated in last 24h or not found
|
||||
results.unchanged++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const jiraStatus = issue.fields.status ? issue.fields.status.name : null;
|
||||
const jiraSummary = issue.fields.summary || ticket.summary;
|
||||
const localStatus = mapJiraStatusToLocal(jiraStatus);
|
||||
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
db.run(
|
||||
`UPDATE jira_tickets SET summary = ?, status = ?, jira_status = ?, last_synced_at = datetime('now'), updated_at = CURRENT_TIMESTAMP WHERE id = ?`,
|
||||
[jiraSummary, localStatus, jiraStatus, ticket.id],
|
||||
(updateErr) => updateErr ? reject(updateErr) : resolve()
|
||||
);
|
||||
});
|
||||
results.synced++;
|
||||
} catch (dbErr) {
|
||||
results.failed++;
|
||||
results.errors.push(`${ticket.ticket_key}: DB update failed — ${dbErr.message}`);
|
||||
}
|
||||
}
|
||||
} catch (searchErr) {
|
||||
results.failed += batch.length;
|
||||
results.errors.push(`Batch search error: ${searchErr.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_sync_all',
|
||||
entityType: 'jira_integration',
|
||||
entityId: null,
|
||||
details: results,
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json(results);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/jira/:id/sync
|
||||
*
|
||||
* Sync a single local ticket with Jira by fetching the latest status,
|
||||
* summary, and mapping the Jira status to the local three-state model.
|
||||
* Uses getIssue with explicit fields (Charter-compliant GET).
|
||||
* Requires Admin or Standard_User group.
|
||||
*
|
||||
* @param {number} id - Local jira_tickets row ID (path parameter)
|
||||
* @returns {object} 200 - { message, ticket_key, jira_status, local_status, summary }
|
||||
* @returns {object} 400 - { error } when ticket has no Jira key
|
||||
* @returns {object} 404 - { error } when local ticket not found
|
||||
* @returns {object} 429 - { error } when Jira rate limit exceeded
|
||||
* @returns {object} 500 - { error } on database error
|
||||
* @returns {object} 502 - { error, details } on Jira API failure
|
||||
* @returns {object} 503 - { error } when Jira API is not configured
|
||||
*/
|
||||
router.post('/:id/sync', requireAuth(db), requireGroup('Admin', 'Standard_User'), async (req, res) => {
|
||||
if (!jiraApi.isConfigured) {
|
||||
return res.status(503).json({ error: 'Jira API is not configured.' });
|
||||
}
|
||||
|
||||
const { id } = req.params;
|
||||
|
||||
db.get('SELECT * FROM jira_tickets WHERE id = ?', [id], async (err, ticket) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!ticket) {
|
||||
return res.status(404).json({ error: 'JIRA ticket not found.' });
|
||||
}
|
||||
if (!ticket.ticket_key) {
|
||||
return res.status(400).json({ error: 'Ticket has no Jira key to sync.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await jiraApi.getIssue(ticket.ticket_key);
|
||||
if (!result.ok) {
|
||||
if (result.rateLimited) {
|
||||
return res.status(429).json({ error: 'Jira rate limit exceeded. Try again later.' });
|
||||
}
|
||||
return res.status(502).json({ error: 'Failed to fetch issue from Jira.', details: result.body });
|
||||
}
|
||||
|
||||
const issue = result.data;
|
||||
const jiraStatus = issue.fields.status ? issue.fields.status.name : null;
|
||||
const jiraSummary = issue.fields.summary || ticket.summary;
|
||||
const localStatus = mapJiraStatusToLocal(jiraStatus);
|
||||
|
||||
db.run(
|
||||
`UPDATE jira_tickets SET summary = ?, status = ?, jira_status = ?, last_synced_at = datetime('now'), updated_at = CURRENT_TIMESTAMP WHERE id = ?`,
|
||||
[jiraSummary, localStatus, jiraStatus, id],
|
||||
function(updateErr) {
|
||||
if (updateErr) {
|
||||
console.error('Error updating synced ticket:', updateErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_sync',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: id,
|
||||
details: { ticket_key: ticket.ticket_key, jira_status: jiraStatus, local_status: localStatus },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({
|
||||
message: 'Ticket synced with Jira',
|
||||
ticket_key: ticket.ticket_key,
|
||||
jira_status: jiraStatus,
|
||||
local_status: localStatus,
|
||||
summary: jiraSummary
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
return res.status(502).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Local CRUD endpoints (migrated from server.js)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* GET /api/jira
|
||||
*
|
||||
* List all local JIRA ticket records with optional filters.
|
||||
* Results are ordered by `created_at` descending.
|
||||
*
|
||||
* @query {string} [cve_id] - Filter by CVE ID
|
||||
* @query {string} [vendor] - Filter by vendor name
|
||||
* @query {string} [status] - Filter by ticket status (Open, In Progress, Closed)
|
||||
* @returns {object[]} 200 - Array of jira_tickets rows
|
||||
* @returns {object} 500 - { error } on database error
|
||||
*/
|
||||
router.get('/', requireAuth(db), (req, res) => {
|
||||
const { cve_id, vendor, status } = req.query;
|
||||
|
||||
let query = 'SELECT * FROM jira_tickets WHERE 1=1';
|
||||
const params = [];
|
||||
|
||||
if (cve_id) {
|
||||
query += ' AND cve_id = ?';
|
||||
params.push(cve_id);
|
||||
}
|
||||
if (vendor) {
|
||||
query += ' AND vendor = ?';
|
||||
params.push(vendor);
|
||||
}
|
||||
if (status) {
|
||||
query += ' AND status = ?';
|
||||
params.push(status);
|
||||
}
|
||||
|
||||
query += ' ORDER BY created_at DESC';
|
||||
|
||||
db.all(query, params, (err, rows) => {
|
||||
if (err) {
|
||||
console.error('Error fetching JIRA tickets:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
res.json(rows);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /api/jira
|
||||
*
|
||||
* Create a local JIRA ticket record (manual entry, no Jira API call).
|
||||
* Requires Admin or Standard_User group.
|
||||
*
|
||||
* @body {string} cve_id - CVE identifier (required, format: CVE-YYYY-NNNNN)
|
||||
* @body {string} vendor - Vendor name (required, max 200 chars)
|
||||
* @body {string} ticket_key - Jira issue key (required, max 50 chars)
|
||||
* @body {string} [url] - URL to the Jira issue (max 500 chars)
|
||||
* @body {string} [summary] - Ticket summary (max 500 chars)
|
||||
* @body {string} [status] - Ticket status: Open, In Progress, or Closed (defaults to Open)
|
||||
* @returns {object} 201 - { id, message }
|
||||
* @returns {object} 400 - { error } on validation failure
|
||||
* @returns {object} 500 - { error } on database error
|
||||
*/
|
||||
router.post('/', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { cve_id, vendor, ticket_key, url, summary, status } = req.body;
|
||||
|
||||
if (!cve_id || !isValidCveId(cve_id)) {
|
||||
return res.status(400).json({ error: 'Valid CVE ID is required.' });
|
||||
}
|
||||
if (!vendor || !isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'Valid vendor is required.' });
|
||||
}
|
||||
if (!ticket_key || typeof ticket_key !== 'string' || ticket_key.trim().length === 0 || ticket_key.length > 50) {
|
||||
return res.status(400).json({ error: 'Ticket key is required (max 50 chars).' });
|
||||
}
|
||||
if (url && (typeof url !== 'string' || url.length > 500)) {
|
||||
return res.status(400).json({ error: 'URL must be under 500 characters.' });
|
||||
}
|
||||
if (summary && (typeof summary !== 'string' || summary.length > 500)) {
|
||||
return res.status(400).json({ error: 'Summary must be under 500 characters.' });
|
||||
}
|
||||
if (status && !VALID_TICKET_STATUSES.includes(status)) {
|
||||
return res.status(400).json({ error: `Status must be one of: ${VALID_TICKET_STATUSES.join(', ')}` });
|
||||
}
|
||||
|
||||
const ticketStatus = status || 'Open';
|
||||
|
||||
db.run(
|
||||
`INSERT INTO jira_tickets (cve_id, vendor, ticket_key, url, summary, status, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[cve_id, vendor, ticket_key.trim(), url || null, summary || null, ticketStatus, req.user.id],
|
||||
function(err) {
|
||||
if (err) {
|
||||
console.error('Error creating JIRA ticket:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_create',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: this.lastID.toString(),
|
||||
details: { cve_id, vendor, ticket_key, status: ticketStatus },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
id: this.lastID,
|
||||
message: 'JIRA ticket created successfully'
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* PUT /api/jira/:id
|
||||
*
|
||||
* Update a local JIRA ticket record. Only provided fields are updated.
|
||||
* Requires Admin or Standard_User group.
|
||||
*
|
||||
* @param {number} id - Local jira_tickets row ID (path parameter)
|
||||
* @body {string} [ticket_key] - Jira issue key (max 50 chars)
|
||||
* @body {string} [url] - URL to the Jira issue (max 500 chars, or null)
|
||||
* @body {string} [summary] - Ticket summary (max 500 chars, or null)
|
||||
* @body {string} [status] - Ticket status: Open, In Progress, or Closed
|
||||
* @returns {object} 200 - { message, changes }
|
||||
* @returns {object} 400 - { error } on validation failure or no fields provided
|
||||
* @returns {object} 404 - { error } when ticket not found
|
||||
* @returns {object} 500 - { error } on database error
|
||||
*/
|
||||
router.put('/:id', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { ticket_key, url, summary, status } = req.body;
|
||||
|
||||
if (ticket_key !== undefined && (typeof ticket_key !== 'string' || ticket_key.trim().length === 0 || ticket_key.length > 50)) {
|
||||
return res.status(400).json({ error: 'Ticket key must be under 50 chars.' });
|
||||
}
|
||||
if (url !== undefined && url !== null && (typeof url !== 'string' || url.length > 500)) {
|
||||
return res.status(400).json({ error: 'URL must be under 500 characters.' });
|
||||
}
|
||||
if (summary !== undefined && summary !== null && (typeof summary !== 'string' || summary.length > 500)) {
|
||||
return res.status(400).json({ error: 'Summary must be under 500 characters.' });
|
||||
}
|
||||
if (status !== undefined && !VALID_TICKET_STATUSES.includes(status)) {
|
||||
return res.status(400).json({ error: `Status must be one of: ${VALID_TICKET_STATUSES.join(', ')}` });
|
||||
}
|
||||
|
||||
const fields = [];
|
||||
const values = [];
|
||||
|
||||
if (ticket_key !== undefined) { fields.push('ticket_key = ?'); values.push(ticket_key.trim()); }
|
||||
if (url !== undefined) { fields.push('url = ?'); values.push(url); }
|
||||
if (summary !== undefined) { fields.push('summary = ?'); values.push(summary); }
|
||||
if (status !== undefined) { fields.push('status = ?'); values.push(status); }
|
||||
|
||||
if (fields.length === 0) {
|
||||
return res.status(400).json({ error: 'No fields to update.' });
|
||||
}
|
||||
|
||||
fields.push('updated_at = CURRENT_TIMESTAMP');
|
||||
values.push(id);
|
||||
|
||||
db.get('SELECT * FROM jira_tickets WHERE id = ?', [id], (err, existing) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!existing) {
|
||||
return res.status(404).json({ error: 'JIRA ticket not found.' });
|
||||
}
|
||||
|
||||
db.run(`UPDATE jira_tickets SET ${fields.join(', ')} WHERE id = ?`, values, function(updateErr) {
|
||||
if (updateErr) {
|
||||
console.error('Error updating JIRA ticket:', updateErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_update',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: id,
|
||||
details: { before: existing, changes: req.body },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ message: 'JIRA ticket updated successfully', changes: this.changes });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* DELETE /api/jira/:id
|
||||
*
|
||||
* Delete a local JIRA ticket record. Admins bypass all restrictions.
|
||||
* Standard_User can only delete tickets they created, and cannot delete
|
||||
* tickets linked to active compliance items.
|
||||
*
|
||||
* @param {number} id - Local jira_tickets row ID (path parameter)
|
||||
* @returns {object} 200 - { message }
|
||||
* @returns {object} 403 - { error } when ownership check fails or ticket is linked to compliance
|
||||
* @returns {object} 404 - { error } when ticket not found
|
||||
* @returns {object} 500 - { error } on database error
|
||||
*/
|
||||
router.delete('/:id', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
db.get('SELECT * FROM jira_tickets WHERE id = ?', [id], (err, ticket) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!ticket) {
|
||||
return res.status(404).json({ error: 'JIRA ticket not found.' });
|
||||
}
|
||||
|
||||
// Admin bypasses all delete restrictions
|
||||
if (req.user.group === 'Admin') {
|
||||
return performJiraDelete();
|
||||
}
|
||||
|
||||
// Standard_User: ownership check
|
||||
if (ticket.created_by && ticket.created_by !== req.user.id) {
|
||||
return res.status(403).json({ error: 'You can only delete resources you created' });
|
||||
}
|
||||
|
||||
// Standard_User: compliance linkage check
|
||||
const ticketKey = ticket.ticket_key;
|
||||
db.all(
|
||||
`SELECT ci.id, ci.extra_json
|
||||
FROM compliance_items ci
|
||||
JOIN compliance_uploads cu ON ci.upload_id = cu.id
|
||||
WHERE ci.status = 'active' AND ci.extra_json LIKE ?`,
|
||||
[`%${ticketKey}%`],
|
||||
(compErr, compLinks) => {
|
||||
if (compErr && compErr.message && compErr.message.includes('no such table')) {
|
||||
compLinks = [];
|
||||
} else if (compErr) {
|
||||
console.error(compErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
const isLinked = (compLinks || []).some(cl => {
|
||||
const json = cl.extra_json || '';
|
||||
return json.includes(ticketKey);
|
||||
});
|
||||
|
||||
if (isLinked) {
|
||||
return res.status(403).json({ error: 'Cannot delete ticket linked to compliance report. Contact an admin.' });
|
||||
}
|
||||
|
||||
return performJiraDelete();
|
||||
}
|
||||
);
|
||||
|
||||
function performJiraDelete() {
|
||||
db.run('DELETE FROM jira_tickets WHERE id = ?', [id], function(deleteErr) {
|
||||
if (deleteErr) {
|
||||
console.error('Error deleting JIRA ticket:', deleteErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_delete',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: id,
|
||||
details: { ticket_key: ticket.ticket_key, cve_id: ticket.cve_id, vendor: ticket.vendor },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ message: 'JIRA ticket deleted successfully' });
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Map a Jira workflow status name to the local three-state model.
|
||||
* Jira statuses vary by project workflow, so this uses broad categories.
|
||||
*/
|
||||
function mapJiraStatusToLocal(jiraStatus) {
|
||||
if (!jiraStatus) return 'Open';
|
||||
const lower = jiraStatus.toLowerCase();
|
||||
if (['closed', 'done', 'resolved', 'complete', 'completed', 'cancelled', 'canceled', "won't do", 'declined'].some(s => lower.includes(s))) {
|
||||
return 'Closed';
|
||||
}
|
||||
if (['in progress', 'in review', 'in development', 'in testing', 'review', 'testing', 'dev', 'active', 'implementing'].some(s => lower.includes(s))) {
|
||||
return 'In Progress';
|
||||
}
|
||||
return 'Open';
|
||||
}
|
||||
|
||||
module.exports = createJiraTicketsRouter;
|
||||
388
backend/scripts/card-granite-lookup.js
Normal file
388
backend/scripts/card-granite-lookup.js
Normal file
@@ -0,0 +1,388 @@
|
||||
#!/usr/bin/env node
|
||||
// ==========================================================================
|
||||
// CARD → Granite Lookup Script (v2)
|
||||
// ==========================================================================
|
||||
// Queries CARD team assets endpoint (which returns full enriched records
|
||||
// including ncim_discovery with EQUIP_INST_ID) for the 109 reassigned IPs
|
||||
// from the findings-count investigation Appendix C.
|
||||
//
|
||||
// Generates:
|
||||
// docs/card-lookup-results.csv — full CARD data for review
|
||||
// docs/granite-reassignment-upload.csv — Team_Device Loader format
|
||||
//
|
||||
// Usage:
|
||||
// cd backend
|
||||
// node scripts/card-granite-lookup.js
|
||||
// ==========================================================================
|
||||
|
||||
require('dotenv').config({ path: require('path').join(__dirname, '..', '.env') });
|
||||
|
||||
const cardApi = require('../helpers/cardApi');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// IP → hostname mapping from Appendix C
|
||||
// ---------------------------------------------------------------------------
|
||||
const REASSIGNED = {
|
||||
// With approved FP workflows (58)
|
||||
'98.120.0.78': 'syn-098-120-000-078', '98.120.32.185': 'syn-098-120-032-185',
|
||||
'10.240.78.177': 'mon15-agg-sw', '10.240.78.176': 'mon16-agg-sw',
|
||||
'10.240.78.133': 'mon15-sw14', '10.240.78.130': 'mon15-sw11',
|
||||
'10.240.78.150': 'mon19-sw3', '10.240.78.107': 'mon16-sw2',
|
||||
'10.240.78.110': 'mon16-sw5', '10.240.78.106': 'mon16-sw1',
|
||||
'10.240.78.149': 'mon19-sw2', '10.240.78.154': 'mon19-sw7',
|
||||
'10.240.78.111': 'mon16-sw6', '10.240.78.153': 'mon19-sw6',
|
||||
'10.240.78.132': 'mon15-sw13', '10.240.78.115': 'mon16-sw10',
|
||||
'10.240.78.109': 'mon16-sw4', '10.240.78.112': 'mon16-sw7',
|
||||
'10.240.78.119': 'mon16-sw14', '10.240.78.114': 'mon16-sw9',
|
||||
'10.240.78.118': 'mon16-sw13', '10.240.78.117': 'mon16-sw12',
|
||||
'10.240.78.108': 'mon16-sw3', '10.240.78.155': 'mon19-sw8',
|
||||
'10.240.78.157': 'mon19-sw10', '10.240.78.151': 'mon19-sw4',
|
||||
'10.240.78.116': 'mon16-sw11', '10.240.78.152': 'mon19-sw5',
|
||||
'10.240.78.161': 'mon19-sw14', '10.240.78.160': 'mon19-sw13',
|
||||
'10.240.78.159': 'mon19-sw12', '10.240.78.158': 'mon19-sw11',
|
||||
'10.240.78.123': 'mon15-sw4', '10.240.78.137': 'mon20-sw4',
|
||||
'10.240.78.148': 'mon19-sw1', '10.240.78.125': 'mon15-sw6',
|
||||
'10.240.78.156': 'mon19-sw9', '10.241.0.63': '',
|
||||
'10.244.11.51': 'apc01se1shcc-n01-bmc', '172.27.72.1': '',
|
||||
'96.37.185.145': '', '10.240.78.170': 'mon17-sw9',
|
||||
'10.240.78.172': 'mon17-sw11', '10.240.78.169': 'mon17-sw8',
|
||||
'10.240.78.166': 'mon17-sw5', '10.240.78.174': 'mon17-sw13',
|
||||
'10.240.78.173': 'mon17-sw12', '10.240.78.167': 'mon17-sw6',
|
||||
'10.240.78.175': 'mon17-sw14', '10.240.78.168': 'mon17-sw7',
|
||||
'10.240.78.171': 'mon17-sw10', '66.61.128.10': 'syn-066-061-128-010',
|
||||
'66.61.128.233': 'apa01se1shcc-bvi101-secondary',
|
||||
'66.61.128.49': 'syn-066-061-128-049', '66.61.128.18': 'syn-066-061-128-018',
|
||||
'10.244.4.26': '', '10.244.11.5': '', '10.244.11.6': '',
|
||||
// With rejected FP workflows (8)
|
||||
'10.244.4.55': 'apc15se1shcc-n03', '10.244.11.53': 'apc01se1shcc-n03-bmc',
|
||||
'10.244.4.30': '', '10.244.11.63': 'apc04se1shcc-n01-cimc',
|
||||
'24.28.208.125': '', '24.28.210.101': 'syn-024-028-210-101',
|
||||
'10.244.11.27': '', '10.240.1.203': '',
|
||||
// Without FP workflows (43)
|
||||
'10.240.78.20': '', '172.16.1.229': '',
|
||||
'10.244.11.96': '', '10.244.11.54': 'apc02se1shcc-n01-cimc',
|
||||
'10.244.4.51': 'apc14se1shcc-n02', '10.244.11.86': '',
|
||||
'10.244.11.55': 'apc02se1shcc-n02-cimc', '24.28.208.105': 'syn-024-028-208-105',
|
||||
'10.244.4.50': 'apc14se1shcc-n01', '10.244.4.53': 'apc15se1shcc-n01',
|
||||
'10.244.11.73': 'apc07se1shcc-n02-cimc', '10.244.11.64': 'apc04se1shcc-n02-cimc',
|
||||
'10.244.4.54': 'apc15se1shcc-n02', '10.244.4.28': '',
|
||||
'10.244.11.94': '', '10.241.0.43': 'c220-wzp27340ss5',
|
||||
'10.244.11.56': 'apc02se1shcc-n03-cimc', '10.244.11.66': 'apc05se1shcc-n01-bmc',
|
||||
'10.244.4.47': 'apc13se1shcc-n01', '10.244.4.49': 'apc13se1shcc-n03',
|
||||
'10.244.4.52': 'apc14se1shcc-n03', '10.244.11.72': 'apc07se1shcc-n01-cimc',
|
||||
'10.244.4.25': 'apc02ctsbcom7-n03-cimc', '10.244.4.29': '',
|
||||
'10.244.11.74': 'apc07se1shcc-n03-cimc', '10.244.4.48': 'apc13se1shcc-n02',
|
||||
'10.244.11.65': 'apc04se1shcc-n03-cimc', '10.244.4.24': 'apc02ctsbcom7-n02-cimc',
|
||||
'10.244.11.87': '', '10.244.11.68': 'apc05se1shcc-n03-bmc',
|
||||
'10.244.11.67': 'apc05se1shcc-n02-bmc', '10.244.4.23': 'apc02ctsbcom7-n01-cimc',
|
||||
'10.244.11.57': '', '10.244.11.95': '',
|
||||
'98.120.32.145': 'syn-098-120-032-145', '98.120.0.129': 'syn-098-120-000-129',
|
||||
'68.114.184.84': 'rphy-runner-vecima',
|
||||
};
|
||||
|
||||
const TARGET_IPS = new Set(Object.keys(REASSIGNED));
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fetch all assets for both teams, then match against our IP list
|
||||
// ---------------------------------------------------------------------------
|
||||
async function fetchTeamAssets(teamName) {
|
||||
const allAssets = [];
|
||||
let page = 1;
|
||||
const pageSize = 200;
|
||||
|
||||
while (true) {
|
||||
// Fetch confirmed assets (these have the richest data)
|
||||
const result = await cardApi.getTeamAssets(teamName, {
|
||||
disposition: 'confirmed',
|
||||
page,
|
||||
pageSize,
|
||||
});
|
||||
|
||||
if (!result.ok) {
|
||||
console.error(` Failed to fetch ${teamName} page ${page}: HTTP ${result.status}`);
|
||||
break;
|
||||
}
|
||||
|
||||
let data;
|
||||
try { data = JSON.parse(result.body); } catch (_) { break; }
|
||||
|
||||
const assets = Array.isArray(data) ? data : (data.assets || data.results || []);
|
||||
allAssets.push(...assets);
|
||||
|
||||
const total = data.total || assets.length;
|
||||
console.log(` ${teamName} page ${page}: ${assets.length} assets (total: ${total})`);
|
||||
|
||||
if (allAssets.length >= total || assets.length === 0) break;
|
||||
page++;
|
||||
}
|
||||
|
||||
return allAssets;
|
||||
}
|
||||
|
||||
function extractIPFromAssetId(assetId) {
|
||||
// Asset IDs are like "10.240.78.110-CTEC" — strip the suffix
|
||||
if (!assetId) return null;
|
||||
const parts = assetId.split('-');
|
||||
// Rejoin all but the last part (the suffix like CTEC, NATL, etc.)
|
||||
// But only if the last part looks like a suffix (not a number)
|
||||
const last = parts[parts.length - 1];
|
||||
if (/^\d+$/.test(last)) return assetId; // All numeric, probably just an IP
|
||||
return parts.slice(0, -1).join('-');
|
||||
}
|
||||
|
||||
function extractGraniteData(asset) {
|
||||
const id = asset._id || '';
|
||||
const ip = extractIPFromAssetId(id);
|
||||
const flags = (asset.card_flags && asset.card_flags[0]) || {};
|
||||
const ncim = asset.ncim_discovery || [];
|
||||
const qualys = asset.qualys_hosts || [];
|
||||
const ivanti = asset.ivanti_assets || [];
|
||||
const granite = asset.netops_granite_allips || null;
|
||||
const iseGranite = asset.ise_granite_equipment || null;
|
||||
|
||||
// Extract EQUIP_INST_ID from ncim_discovery (primary source)
|
||||
let equipInstId = null;
|
||||
let graniteTeam = null;
|
||||
let entityId = null;
|
||||
let sysLocation = null;
|
||||
let ncimHostname = null;
|
||||
|
||||
if (ncim.length > 0) {
|
||||
equipInstId = ncim[0].EQUIP_INST_ID || null;
|
||||
graniteTeam = ncim[0].GRANITE_RESP_TEAM || ncim[0].RESPONSIBLE_TEAM || null;
|
||||
entityId = ncim[0].ENTITYID || null;
|
||||
sysLocation = ncim[0].SYSLOCATION || null;
|
||||
ncimHostname = ncim[0].HOSTNAME || null;
|
||||
}
|
||||
|
||||
// Fallback: check netops_granite_allips
|
||||
if (!equipInstId && granite && Array.isArray(granite) && granite.length > 0) {
|
||||
equipInstId = granite[0].EQUIP_INST_ID || null;
|
||||
}
|
||||
|
||||
// Fallback: check ise_granite_equipment
|
||||
if (!equipInstId && iseGranite && Array.isArray(iseGranite) && iseGranite.length > 0) {
|
||||
equipInstId = iseGranite[0].EQUIP_INST_ID || null;
|
||||
}
|
||||
|
||||
const hostname = ncimHostname
|
||||
|| (flags.CARD_HOSTNAME && flags.CARD_HOSTNAME[0])
|
||||
|| (qualys.length > 0 && qualys[0].HOSTNAME)
|
||||
|| (ivanti.length > 0 && ivanti[0].hostName)
|
||||
|| '';
|
||||
|
||||
const confirmedTeam = asset.owner && asset.owner.confirmed
|
||||
? asset.owner.confirmed.name : null;
|
||||
|
||||
return {
|
||||
ip,
|
||||
assetId: id,
|
||||
hostname,
|
||||
equipInstId,
|
||||
graniteTeam,
|
||||
entityId,
|
||||
sysLocation,
|
||||
confirmedTeam,
|
||||
deviceId: flags.CARD_DEVICE_ID || null,
|
||||
asn: flags.CARD_ASN || null,
|
||||
vendorModel: (flags.CARD_VENDOR_MODEL || []).map(v => v.vendor_model || v).join(', '),
|
||||
status: flags.status || null,
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Main
|
||||
// ---------------------------------------------------------------------------
|
||||
async function main() {
|
||||
console.log('=== CARD → Granite Lookup (v2 — team assets endpoint) ===');
|
||||
console.log(`Target IPs: ${TARGET_IPS.size}`);
|
||||
console.log(`CARD_API_URL: ${process.env.CARD_API_URL}`);
|
||||
console.log('');
|
||||
|
||||
if (!cardApi.isConfigured) {
|
||||
console.error('CARD API is not configured.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Fetch assets from both teams
|
||||
const teams = ['NTS-AEO-STEAM', 'NTS-AEO-ACCESS-ENG'];
|
||||
const allAssets = [];
|
||||
|
||||
for (const team of teams) {
|
||||
console.log(`Fetching ${team}...`);
|
||||
const assets = await fetchTeamAssets(team);
|
||||
allAssets.push(...assets);
|
||||
console.log(` Total: ${assets.length} assets\n`);
|
||||
}
|
||||
|
||||
// Also fetch candidate/unconfirmed in case some were reassigned
|
||||
for (const team of teams) {
|
||||
for (const disp of ['candidate', 'unconfirmed']) {
|
||||
console.log(`Fetching ${team} (${disp})...`);
|
||||
try {
|
||||
const result = await cardApi.getTeamAssets(team, { disposition: disp, pageSize: 200 });
|
||||
if (result.ok) {
|
||||
const data = JSON.parse(result.body);
|
||||
const assets = Array.isArray(data) ? data : (data.assets || data.results || []);
|
||||
allAssets.push(...assets);
|
||||
console.log(` ${assets.length} assets`);
|
||||
}
|
||||
} catch (_) { /* skip */ }
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nTotal assets fetched: ${allAssets.length}`);
|
||||
|
||||
// Build IP → asset map
|
||||
const ipMap = new Map();
|
||||
for (const asset of allAssets) {
|
||||
const id = asset._id || '';
|
||||
const ip = extractIPFromAssetId(id);
|
||||
if (ip && !ipMap.has(ip)) {
|
||||
ipMap.set(ip, asset);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Unique IPs in CARD: ${ipMap.size}`);
|
||||
|
||||
// Match against our target IPs
|
||||
const matched = [];
|
||||
const notFound = [];
|
||||
|
||||
for (const ip of TARGET_IPS) {
|
||||
const asset = ipMap.get(ip);
|
||||
if (asset) {
|
||||
matched.push(extractGraniteData(asset));
|
||||
} else {
|
||||
notFound.push(ip);
|
||||
}
|
||||
}
|
||||
|
||||
// For IPs not found in team assets, fall back to individual owner lookup
|
||||
if (notFound.length > 0) {
|
||||
console.log(`\n${notFound.length} IPs not in team assets — trying individual owner lookups...`);
|
||||
const SUFFIXES = ['CTEC', 'NATL', 'TWC', 'BHN', 'CHTR'];
|
||||
const stillNotFound = [];
|
||||
|
||||
for (const ip of notFound) {
|
||||
let found = false;
|
||||
for (const suffix of SUFFIXES) {
|
||||
try {
|
||||
const result = await cardApi.getOwner(`${ip}-${suffix}`);
|
||||
if (result.ok) {
|
||||
const data = JSON.parse(result.body);
|
||||
// Owner endpoint is slim — extract what we can
|
||||
const ncim = data.ncim_discovery || [];
|
||||
matched.push({
|
||||
ip,
|
||||
assetId: data._id || `${ip}-${suffix}`,
|
||||
hostname: REASSIGNED[ip] || '',
|
||||
equipInstId: ncim.length > 0 ? (ncim[0].EQUIP_INST_ID || null) : null,
|
||||
graniteTeam: ncim.length > 0 ? (ncim[0].GRANITE_RESP_TEAM || null) : null,
|
||||
entityId: ncim.length > 0 ? (ncim[0].ENTITYID || null) : null,
|
||||
sysLocation: ncim.length > 0 ? (ncim[0].SYSLOCATION || null) : null,
|
||||
confirmedTeam: data.owner && data.owner.confirmed ? data.owner.confirmed.name : null,
|
||||
deviceId: null,
|
||||
asn: null,
|
||||
vendorModel: '',
|
||||
status: null,
|
||||
});
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
} catch (_) { /* continue */ }
|
||||
}
|
||||
if (!found) stillNotFound.push(ip);
|
||||
}
|
||||
|
||||
if (stillNotFound.length > 0) {
|
||||
console.log(`\n${stillNotFound.length} IPs not found anywhere in CARD:`);
|
||||
stillNotFound.forEach(ip => console.log(` ${ip} (${REASSIGNED[ip] || 'no hostname'})`));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by IP
|
||||
matched.sort((a, b) => {
|
||||
const aParts = a.ip.split('.').map(Number);
|
||||
const bParts = b.ip.split('.').map(Number);
|
||||
for (let i = 0; i < 4; i++) {
|
||||
if (aParts[i] !== bParts[i]) return aParts[i] - bParts[i];
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
// Summary
|
||||
const withEquipId = matched.filter(r => r.equipInstId);
|
||||
const withoutEquipId = matched.filter(r => !r.equipInstId);
|
||||
|
||||
console.log('\n=== Summary ===');
|
||||
console.log(`Matched in CARD: ${matched.length}`);
|
||||
console.log(`With EQUIP_INST_ID: ${withEquipId.length}`);
|
||||
console.log(`Without EQUIP_INST_ID: ${withoutEquipId.length}`);
|
||||
|
||||
// Print results
|
||||
console.log('\n=== Results with EQUIP_INST_ID ===');
|
||||
console.log('IP Address | EQUIP_INST_ID | Hostname | Granite Team');
|
||||
console.log('-'.repeat(100));
|
||||
for (const r of withEquipId) {
|
||||
console.log(`${r.ip.padEnd(20)} | ${String(r.equipInstId).padEnd(13)} | ${(r.hostname || '').padEnd(30)} | ${r.graniteTeam || '-'}`);
|
||||
}
|
||||
|
||||
if (withoutEquipId.length > 0) {
|
||||
console.log('\n=== Results WITHOUT EQUIP_INST_ID ===');
|
||||
for (const r of withoutEquipId) {
|
||||
console.log(` ${r.ip.padEnd(20)} ${(r.hostname || REASSIGNED[r.ip] || '').padEnd(30)} confirmed: ${r.confirmedTeam || '-'}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Write full CSV
|
||||
const csvPath = path.join(__dirname, '..', '..', 'docs', 'card-lookup-results.csv');
|
||||
const csvHeader = 'IP Address,CARD Asset ID,Hostname,EQUIP_INST_ID,Granite Team,Entity ID,SysLocation,Confirmed Team,Device ID,ASN,Vendor Model,Status';
|
||||
const csvRows = matched.map(r =>
|
||||
[r.ip, r.assetId, r.hostname, r.equipInstId, r.graniteTeam, r.entityId, r.sysLocation, r.confirmedTeam, r.deviceId, r.asn, r.vendorModel, r.status]
|
||||
.map(v => v === null || v === undefined ? '' : `"${String(v).replace(/"/g, '""')}"`)
|
||||
.join(',')
|
||||
);
|
||||
fs.writeFileSync(csvPath, csvHeader + '\n' + csvRows.join('\n') + '\n', 'utf8');
|
||||
console.log(`\nFull CSV: ${csvPath}`);
|
||||
|
||||
// Write Granite Team_Device Loader CSV
|
||||
const graniteHeaders = [
|
||||
'DELETE', 'SET_CONFIRMED', 'EQUIPMENT CLASS', 'EQUIP_INST_ID', 'SITE_NAME',
|
||||
'EQUIP_NAME', 'EQUIP_TEMPLATE', 'EQUIP_STATUS',
|
||||
'UDA#RESPONSIBLE ORGANIZATION#RESPONSIBLE TEAM',
|
||||
'UDA#IP_ADDRESSING#IPV4_ADDRESS',
|
||||
'UDA#IP_ADDRESSING#MAC ADDRESS', 'UDA#IP_ADDRESSING#MGMT_IP_ASN', 'SERIALNUMBER',
|
||||
];
|
||||
|
||||
const graniteRows = withEquipId.map(r => [
|
||||
'', // DELETE
|
||||
'', // SET_CONFIRMED
|
||||
'S', // EQUIPMENT CLASS (Shelf)
|
||||
r.equipInstId, // EQUIP_INST_ID
|
||||
'', // SITE_NAME
|
||||
r.hostname || REASSIGNED[r.ip] || '', // EQUIP_NAME
|
||||
'', // EQUIP_TEMPLATE
|
||||
'', // EQUIP_STATUS
|
||||
'NTS-AEO-STEAM', // RESPONSIBLE TEAM
|
||||
r.ip, // IPV4_ADDRESS
|
||||
'', // MAC ADDRESS
|
||||
r.asn || '', // MGMT_IP_ASN
|
||||
r.deviceId || '', // SERIALNUMBER
|
||||
]);
|
||||
|
||||
const granitePath = path.join(__dirname, '..', '..', 'docs', 'granite-reassignment-upload.csv');
|
||||
const graniteContent = [
|
||||
graniteHeaders.join(','),
|
||||
...graniteRows.map(r => r.map(v => `"${String(v).replace(/"/g, '""')}"`).join(','))
|
||||
].join('\n');
|
||||
fs.writeFileSync(granitePath, graniteContent + '\n', 'utf8');
|
||||
console.log(`Granite upload CSV (${withEquipId.length} rows): ${granitePath}`);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('Unhandled error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
44
backend/scripts/compliance_config.json
Normal file
44
backend/scripts/compliance_config.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"metric_categories": {
|
||||
"1.1.1": "Logging & Monitoring",
|
||||
"1.1.3": "Logging & Monitoring",
|
||||
"1.4.1": "Logging & Monitoring",
|
||||
"2.3.4i": "Vulnerability Management",
|
||||
"2.3.6i": "Vulnerability Management",
|
||||
"2.3.8i": "Vulnerability Management",
|
||||
"5.2.4": "Access & MFA",
|
||||
"5.2.5": "Access & MFA",
|
||||
"5.2.6": "Access & MFA",
|
||||
"5.2.7": "Access & MFA",
|
||||
"5.2.8": "Access & MFA",
|
||||
"5.3.4": "Endpoint Protection",
|
||||
"5.5.4i": "Vulnerability Management",
|
||||
"5.5.5": "Decommissioned Assets",
|
||||
"5.8.1": "Application Security",
|
||||
"7.1.1": "Logging & Monitoring",
|
||||
"7.1.4": "Logging & Monitoring",
|
||||
"7.6.13": "Disaster Recovery",
|
||||
"7.6.16": "Disaster Recovery",
|
||||
"Missing_AppID": "Asset Data Quality",
|
||||
"Missing_DF": "Asset Data Quality",
|
||||
"Missing_OS": "Asset Data Quality",
|
||||
"5.5.2": "Other"
|
||||
},
|
||||
"core_cols": [
|
||||
"Preferred - Hostname",
|
||||
"GRANITE - IPv4_Address",
|
||||
"GRANITE - Type",
|
||||
"Team",
|
||||
"Compliant",
|
||||
"Source_Network",
|
||||
"Vertical",
|
||||
"GRANITE - Equip_Inst_ID",
|
||||
"GRANITE - RESPONSIBLE_TEAM"
|
||||
],
|
||||
"skip_sheets": [
|
||||
"Summary",
|
||||
"CMDB_9box",
|
||||
"Vulns",
|
||||
"Aging Dashboard"
|
||||
]
|
||||
}
|
||||
84
backend/scripts/dump_xlsx_schema.py
Normal file
84
backend/scripts/dump_xlsx_schema.py
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Dump the structural schema of a compliance xlsx file as JSON.
|
||||
Usage: python3 dump_xlsx_schema.py <path_to_xlsx>
|
||||
|
||||
Output:
|
||||
{
|
||||
"sheets": [
|
||||
{
|
||||
"name": "SheetName",
|
||||
"columns": ["Col A", "Col B", ...],
|
||||
"row_count": 150,
|
||||
"metric_values": ["2.3.4i", "5.2.4", ...] // only if a Metric column exists
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
|
||||
Dependencies: openpyxl (already in requirements.txt)
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
from openpyxl import load_workbook
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(json.dumps({'error': 'No file path provided'}))
|
||||
sys.exit(1)
|
||||
|
||||
filepath = sys.argv[1]
|
||||
|
||||
try:
|
||||
wb = load_workbook(filepath, read_only=True, data_only=True)
|
||||
except Exception as e:
|
||||
print(json.dumps({'error': f'Cannot open file: {str(e)}'}))
|
||||
sys.exit(1)
|
||||
|
||||
sheets = []
|
||||
for sheet_name in wb.sheetnames:
|
||||
ws = wb[sheet_name]
|
||||
rows = list(ws.iter_rows(max_row=1, values_only=True))
|
||||
columns = [str(c).strip() for c in rows[0] if c is not None] if rows else []
|
||||
|
||||
# Count data rows (excluding header)
|
||||
row_count = 0
|
||||
for _ in ws.iter_rows(min_row=2, values_only=True):
|
||||
row_count += 1
|
||||
|
||||
# Extract metric values if a Metric column exists in the Summary sheet
|
||||
metric_values = []
|
||||
if sheet_name == 'Summary':
|
||||
# Summary has header at row 4 (0-indexed row 3), read from row 5 onward
|
||||
header_rows = list(ws.iter_rows(min_row=4, max_row=4, values_only=True))
|
||||
if header_rows:
|
||||
summary_cols = [str(c).strip() if c else '' for c in header_rows[0]]
|
||||
metric_idx = None
|
||||
for i, col in enumerate(summary_cols):
|
||||
if col == 'Metric':
|
||||
metric_idx = i
|
||||
break
|
||||
if metric_idx is not None:
|
||||
for row in ws.iter_rows(min_row=5, values_only=True):
|
||||
if row[metric_idx] is not None:
|
||||
val = str(row[metric_idx]).strip()
|
||||
if val and val != 'Metric':
|
||||
metric_values.append(val)
|
||||
|
||||
entry = {
|
||||
'name': sheet_name,
|
||||
'columns': columns,
|
||||
'row_count': row_count,
|
||||
}
|
||||
if metric_values:
|
||||
entry['metric_values'] = sorted(set(metric_values))
|
||||
|
||||
sheets.append(entry)
|
||||
|
||||
wb.close()
|
||||
print(json.dumps({'sheets': sheets}, indent=2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
91
backend/scripts/extract_xlsx_schema.py
Normal file
91
backend/scripts/extract_xlsx_schema.py
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Extract the structural schema of a compliance xlsx file as JSON.
|
||||
Usage: python3 extract_xlsx_schema.py <path_to_xlsx>
|
||||
|
||||
Output:
|
||||
{
|
||||
"sheets": [
|
||||
{
|
||||
"name": "Summary",
|
||||
"columns": ["Metric", "Non-Compliant", "..."],
|
||||
"metric_values": ["2.3.4i", "5.2.4", "..."]
|
||||
},
|
||||
{
|
||||
"name": "2.3.4i",
|
||||
"columns": ["Preferred - Hostname", "GRANITE - IPv4_Address", "..."]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
- Uses openpyxl in read-only mode.
|
||||
- Extracts sheet names, first-row column headers per sheet, and unique metric
|
||||
values from the Summary sheet (header at row 4, data from row 5 onward).
|
||||
- On error, returns { "error": "..." } on stdout and exits with non-zero code.
|
||||
|
||||
Dependencies: openpyxl (already in requirements.txt)
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
from openpyxl import load_workbook
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(json.dumps({"error": "No file path provided"}))
|
||||
sys.exit(1)
|
||||
|
||||
filepath = sys.argv[1]
|
||||
|
||||
try:
|
||||
wb = load_workbook(filepath, read_only=True, data_only=True)
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": f"Cannot open file: {str(e)}"}))
|
||||
sys.exit(1)
|
||||
|
||||
if not wb.sheetnames:
|
||||
print(json.dumps({"error": "Workbook contains no sheets"}))
|
||||
wb.close()
|
||||
sys.exit(1)
|
||||
|
||||
sheets = []
|
||||
for sheet_name in wb.sheetnames:
|
||||
ws = wb[sheet_name]
|
||||
|
||||
# Extract first-row column headers
|
||||
rows = list(ws.iter_rows(max_row=1, values_only=True))
|
||||
columns = [str(c).strip() for c in rows[0] if c is not None] if rows else []
|
||||
|
||||
entry = {
|
||||
"name": sheet_name,
|
||||
"columns": columns,
|
||||
}
|
||||
|
||||
# Extract metric values from the Summary sheet
|
||||
# Summary has header at row 4, data from row 5 onward
|
||||
if sheet_name == "Summary":
|
||||
metric_values = []
|
||||
header_rows = list(ws.iter_rows(min_row=4, max_row=4, values_only=True))
|
||||
if header_rows:
|
||||
summary_cols = [str(c).strip() if c else "" for c in header_rows[0]]
|
||||
metric_idx = None
|
||||
for i, col in enumerate(summary_cols):
|
||||
if col == "Metric":
|
||||
metric_idx = i
|
||||
break
|
||||
if metric_idx is not None:
|
||||
for row in ws.iter_rows(min_row=5, values_only=True):
|
||||
if row[metric_idx] is not None:
|
||||
val = str(row[metric_idx]).strip()
|
||||
if val and val != "Metric":
|
||||
metric_values.append(val)
|
||||
entry["metric_values"] = sorted(set(metric_values))
|
||||
|
||||
sheets.append(entry)
|
||||
|
||||
wb.close()
|
||||
print(json.dumps({"sheets": sheets}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -12,39 +12,35 @@ Output:
|
||||
}
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
|
||||
METRIC_CATEGORIES = {
|
||||
'2.3.4i': 'Vulnerability Management',
|
||||
'2.3.6i': 'Vulnerability Management',
|
||||
'2.3.8i': 'Vulnerability Management',
|
||||
'5.2.4': 'Access & MFA',
|
||||
'5.2.5': 'Access & MFA',
|
||||
'5.2.6': 'Access & MFA',
|
||||
'5.3.4': 'Endpoint Protection',
|
||||
'5.5.2': 'End-of-Life OS',
|
||||
'5.5.4i': 'Vulnerability Management',
|
||||
'5.5.5': 'Decommissioned Assets',
|
||||
'5.8.1': 'Application Security',
|
||||
'7.1.1': 'Logging & Monitoring',
|
||||
'7.6.13': 'Disaster Recovery',
|
||||
'7.6.16': 'Disaster Recovery',
|
||||
'Missing_AppID': 'Asset Data Quality',
|
||||
'Missing_DF': 'Asset Data Quality',
|
||||
'Missing_OS': 'Asset Data Quality',
|
||||
}
|
||||
|
||||
# Columns that go into the main item fields — everything else becomes extra_json
|
||||
CORE_COLS = {
|
||||
'Preferred - Hostname', 'GRANITE - IPv4_Address', 'GRANITE - Type',
|
||||
'Team', 'Compliant', 'Source_Network', 'Vertical',
|
||||
'GRANITE - Equip_Inst_ID', 'GRANITE - RESPONSIBLE_TEAM',
|
||||
}
|
||||
def load_config():
|
||||
"""Load parser configuration from compliance_config.json."""
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
config_path = os.path.join(script_dir, 'compliance_config.json')
|
||||
|
||||
SKIP_SHEETS = {'Summary', 'CMDB_9box'}
|
||||
try:
|
||||
with open(config_path, 'r') as f:
|
||||
config = json.load(f)
|
||||
except FileNotFoundError:
|
||||
print(f"Error: Configuration file not found: {config_path}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error: Invalid JSON in configuration file {config_path}: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
_config = load_config()
|
||||
METRIC_CATEGORIES = _config['metric_categories']
|
||||
CORE_COLS = set(_config['core_cols'])
|
||||
SKIP_SHEETS = set(_config['skip_sheets'])
|
||||
|
||||
|
||||
def safe_str(val):
|
||||
|
||||
@@ -25,7 +25,10 @@ const createIvantiFindingsRouter = require('./routes/ivantiFindings');
|
||||
const createIvantiTodoQueueRouter = require('./routes/ivantiTodoQueue');
|
||||
const createIvantiArchiveRouter = require('./routes/ivantiArchive');
|
||||
const createIvantiFpWorkflowRouter = require('./routes/ivantiFpWorkflow');
|
||||
const createComplianceRouter = require('./routes/compliance');
|
||||
const { createComplianceRouter } = require('./routes/compliance');
|
||||
const createAtlasRouter = require('./routes/atlas');
|
||||
const createJiraTicketsRouter = require('./routes/jiraTickets');
|
||||
const createCardApiRouter = require('./routes/cardApi');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
@@ -234,6 +237,15 @@ app.use('/api/ivanti/fp-workflow', createIvantiFpWorkflowRouter(db, requireAuth)
|
||||
// AEO compliance routes — xlsx upload, non-compliant item tracking, notes
|
||||
app.use('/api/compliance', createComplianceRouter(db, upload, requireAuth, requireGroup));
|
||||
|
||||
// Atlas InfoSec action plan routes — proxy CRUD to Atlas API, local cache for badges
|
||||
app.use('/api/atlas', createAtlasRouter(db, requireAuth));
|
||||
|
||||
// Jira ticket routes — local CRUD + Jira REST API integration (lookup, sync, create)
|
||||
app.use('/api/jira-tickets', createJiraTicketsRouter(db));
|
||||
|
||||
// CARD Asset Ownership API routes — proxy CARD operations, mutation flow, asset search
|
||||
app.use('/api/card', createCardApiRouter(db, requireAuth));
|
||||
|
||||
// ========== CVE ENDPOINTS ==========
|
||||
|
||||
// Get all CVEs with optional filters (authenticated users)
|
||||
@@ -1181,234 +1193,6 @@ app.get('/api/stats', requireAuth(db), (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// ========== JIRA TICKET ENDPOINTS ==========
|
||||
|
||||
// Get all JIRA tickets (with optional filters)
|
||||
app.get('/api/jira-tickets', requireAuth(db), (req, res) => {
|
||||
const { cve_id, vendor, status } = req.query;
|
||||
|
||||
let query = 'SELECT * FROM jira_tickets WHERE 1=1';
|
||||
const params = [];
|
||||
|
||||
if (cve_id) {
|
||||
query += ' AND cve_id = ?';
|
||||
params.push(cve_id);
|
||||
}
|
||||
if (vendor) {
|
||||
query += ' AND vendor = ?';
|
||||
params.push(vendor);
|
||||
}
|
||||
if (status) {
|
||||
query += ' AND status = ?';
|
||||
params.push(status);
|
||||
}
|
||||
|
||||
query += ' ORDER BY created_at DESC';
|
||||
|
||||
db.all(query, params, (err, rows) => {
|
||||
if (err) {
|
||||
console.error('Error fetching JIRA tickets:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
res.json(rows);
|
||||
});
|
||||
});
|
||||
|
||||
// Create JIRA ticket
|
||||
app.post('/api/jira-tickets', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { cve_id, vendor, ticket_key, url, summary, status } = req.body;
|
||||
|
||||
// Validation
|
||||
if (!cve_id || !isValidCveId(cve_id)) {
|
||||
return res.status(400).json({ error: 'Valid CVE ID is required.' });
|
||||
}
|
||||
if (!vendor || !isValidVendor(vendor)) {
|
||||
return res.status(400).json({ error: 'Valid vendor is required.' });
|
||||
}
|
||||
if (!ticket_key || typeof ticket_key !== 'string' || ticket_key.trim().length === 0 || ticket_key.length > 50) {
|
||||
return res.status(400).json({ error: 'Ticket key is required (max 50 chars).' });
|
||||
}
|
||||
if (url && (typeof url !== 'string' || url.length > 500)) {
|
||||
return res.status(400).json({ error: 'URL must be under 500 characters.' });
|
||||
}
|
||||
if (summary && (typeof summary !== 'string' || summary.length > 500)) {
|
||||
return res.status(400).json({ error: 'Summary must be under 500 characters.' });
|
||||
}
|
||||
if (status && !VALID_TICKET_STATUSES.includes(status)) {
|
||||
return res.status(400).json({ error: `Status must be one of: ${VALID_TICKET_STATUSES.join(', ')}` });
|
||||
}
|
||||
|
||||
const ticketStatus = status || 'Open';
|
||||
|
||||
const query = `
|
||||
INSERT INTO jira_tickets (cve_id, vendor, ticket_key, url, summary, status, created_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`;
|
||||
|
||||
db.run(query, [cve_id, vendor, ticket_key.trim(), url || null, summary || null, ticketStatus, req.user.id], function(err) {
|
||||
if (err) {
|
||||
console.error('Error creating JIRA ticket:', err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_create',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: this.lastID.toString(),
|
||||
details: { cve_id, vendor, ticket_key, status: ticketStatus },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
id: this.lastID,
|
||||
message: 'JIRA ticket created successfully'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Update JIRA ticket
|
||||
app.put('/api/jira-tickets/:id', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { ticket_key, url, summary, status } = req.body;
|
||||
|
||||
// Validation
|
||||
if (ticket_key !== undefined && (typeof ticket_key !== 'string' || ticket_key.trim().length === 0 || ticket_key.length > 50)) {
|
||||
return res.status(400).json({ error: 'Ticket key must be under 50 chars.' });
|
||||
}
|
||||
if (url !== undefined && url !== null && (typeof url !== 'string' || url.length > 500)) {
|
||||
return res.status(400).json({ error: 'URL must be under 500 characters.' });
|
||||
}
|
||||
if (summary !== undefined && summary !== null && (typeof summary !== 'string' || summary.length > 500)) {
|
||||
return res.status(400).json({ error: 'Summary must be under 500 characters.' });
|
||||
}
|
||||
if (status !== undefined && !VALID_TICKET_STATUSES.includes(status)) {
|
||||
return res.status(400).json({ error: `Status must be one of: ${VALID_TICKET_STATUSES.join(', ')}` });
|
||||
}
|
||||
|
||||
// Build dynamic update
|
||||
const fields = [];
|
||||
const values = [];
|
||||
|
||||
if (ticket_key !== undefined) { fields.push('ticket_key = ?'); values.push(ticket_key.trim()); }
|
||||
if (url !== undefined) { fields.push('url = ?'); values.push(url); }
|
||||
if (summary !== undefined) { fields.push('summary = ?'); values.push(summary); }
|
||||
if (status !== undefined) { fields.push('status = ?'); values.push(status); }
|
||||
|
||||
if (fields.length === 0) {
|
||||
return res.status(400).json({ error: 'No fields to update.' });
|
||||
}
|
||||
|
||||
fields.push('updated_at = CURRENT_TIMESTAMP');
|
||||
values.push(id);
|
||||
|
||||
db.get('SELECT * FROM jira_tickets WHERE id = ?', [id], (err, existing) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!existing) {
|
||||
return res.status(404).json({ error: 'JIRA ticket not found.' });
|
||||
}
|
||||
|
||||
db.run(`UPDATE jira_tickets SET ${fields.join(', ')} WHERE id = ?`, values, function(updateErr) {
|
||||
if (updateErr) {
|
||||
console.error('Error updating JIRA ticket:', updateErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_update',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: id,
|
||||
details: { before: existing, changes: req.body },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ message: 'JIRA ticket updated successfully', changes: this.changes });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Delete JIRA ticket
|
||||
app.delete('/api/jira-tickets/:id', requireAuth(db), requireGroup('Admin', 'Standard_User'), (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
db.get('SELECT * FROM jira_tickets WHERE id = ?', [id], (err, ticket) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
if (!ticket) {
|
||||
return res.status(404).json({ error: 'JIRA ticket not found.' });
|
||||
}
|
||||
|
||||
// Admin bypasses all delete restrictions
|
||||
if (req.user.group === 'Admin') {
|
||||
return performJiraDelete();
|
||||
}
|
||||
|
||||
// Standard_User: ownership check
|
||||
if (ticket.created_by && ticket.created_by !== req.user.id) {
|
||||
return res.status(403).json({ error: 'You can only delete resources you created' });
|
||||
}
|
||||
|
||||
// Standard_User: compliance linkage check
|
||||
const ticketKey = ticket.ticket_key;
|
||||
db.all(
|
||||
`SELECT ci.id, ci.extra_json
|
||||
FROM compliance_items ci
|
||||
JOIN compliance_uploads cu ON ci.upload_id = cu.id
|
||||
WHERE ci.status = 'active' AND ci.extra_json LIKE ?`,
|
||||
[`%${ticketKey}%`],
|
||||
(compErr, compLinks) => {
|
||||
// If compliance_items table doesn't exist yet, treat as no linkage
|
||||
if (compErr && compErr.message && compErr.message.includes('no such table')) {
|
||||
compLinks = [];
|
||||
} else if (compErr) {
|
||||
console.error(compErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
const isLinked = (compLinks || []).some(cl => {
|
||||
const json = cl.extra_json || '';
|
||||
return json.includes(ticketKey);
|
||||
});
|
||||
|
||||
if (isLinked) {
|
||||
return res.status(403).json({ error: 'Cannot delete ticket linked to compliance report. Contact an admin.' });
|
||||
}
|
||||
|
||||
return performJiraDelete();
|
||||
}
|
||||
);
|
||||
|
||||
function performJiraDelete() {
|
||||
db.run('DELETE FROM jira_tickets WHERE id = ?', [id], function(deleteErr) {
|
||||
if (deleteErr) {
|
||||
console.error('Error deleting JIRA ticket:', deleteErr);
|
||||
return res.status(500).json({ error: 'Internal server error.' });
|
||||
}
|
||||
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
username: req.user.username,
|
||||
action: 'jira_ticket_delete',
|
||||
entityType: 'jira_ticket',
|
||||
entityId: id,
|
||||
details: { ticket_key: ticket.ticket_key, cve_id: ticket.cve_id, vendor: ticket.vendor },
|
||||
ipAddress: req.ip
|
||||
});
|
||||
|
||||
res.json({ message: 'JIRA ticket deleted successfully' });
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Start server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`CVE API server running on http://${API_HOST}:${PORT}`);
|
||||
|
||||
887
backend/setup.js
887
backend/setup.js
@@ -1,5 +1,12 @@
|
||||
// Setup Script for CVE Database
|
||||
// This creates a fresh database with multi-vendor support built-in
|
||||
// Setup Script for CVE Dashboard v1.0.0
|
||||
// Creates a fresh database with the complete schema including all tables,
|
||||
// indexes, triggers, and views needed for a new deployment.
|
||||
//
|
||||
// Usage: node backend/setup.js
|
||||
//
|
||||
// This consolidates the original schema plus all migration scripts into a
|
||||
// single idempotent setup. Migration scripts in backend/migrations/ are
|
||||
// retained for reference but are NOT needed on fresh deployments.
|
||||
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const bcrypt = require('bcryptjs');
|
||||
@@ -7,334 +14,628 @@ const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const DB_FILE = './cve_database.db';
|
||||
const UPLOADS_DIR = './uploads';
|
||||
const DB_FILE = path.join(__dirname, 'cve_database.db');
|
||||
const UPLOADS_DIR = path.join(__dirname, 'uploads');
|
||||
|
||||
// Initialize database with schema
|
||||
function initializeDatabase() {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Database helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
function dbRun(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const db = new sqlite3.Database(DB_FILE, (err) => {
|
||||
db.run(sql, params, function (err) {
|
||||
if (err) reject(err);
|
||||
});
|
||||
|
||||
const schema = `
|
||||
CREATE TABLE IF NOT EXISTS cves (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
severity VARCHAR(20) NOT NULL,
|
||||
description TEXT,
|
||||
published_date DATE,
|
||||
status VARCHAR(50) DEFAULT 'Open',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(cve_id, vendor)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS documents (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
file_path VARCHAR(500) NOT NULL,
|
||||
file_size VARCHAR(20),
|
||||
mime_type VARCHAR(100),
|
||||
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
notes TEXT,
|
||||
FOREIGN KEY (cve_id) REFERENCES cves(cve_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS required_documents (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
document_type VARCHAR(50) NOT NULL,
|
||||
is_mandatory BOOLEAN DEFAULT 1,
|
||||
description TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_cve_id ON cves(cve_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_vendor ON cves(vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_severity ON cves(severity);
|
||||
CREATE INDEX IF NOT EXISTS idx_status ON cves(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_cve_id ON documents(cve_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_vendor ON documents(vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_type ON documents(type);
|
||||
|
||||
-- Users table for authentication
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL DEFAULT 'viewer',
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login TIMESTAMP,
|
||||
CHECK (role IN ('admin', 'editor', 'viewer'))
|
||||
);
|
||||
|
||||
-- Sessions table for session management
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id VARCHAR(255) UNIQUE NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_session_id ON sessions(session_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
||||
|
||||
-- Audit log table for tracking user actions
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
username VARCHAR(50) NOT NULL,
|
||||
action VARCHAR(50) NOT NULL,
|
||||
entity_type VARCHAR(50) NOT NULL,
|
||||
entity_id VARCHAR(100),
|
||||
details TEXT,
|
||||
ip_address VARCHAR(45),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_user_id ON audit_logs(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_action ON audit_logs(action);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_entity_type ON audit_logs(entity_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_created_at ON audit_logs(created_at);
|
||||
|
||||
INSERT OR IGNORE INTO required_documents (vendor, document_type, is_mandatory, description) VALUES
|
||||
('Microsoft', 'advisory', 1, 'Official Microsoft Security Advisory'),
|
||||
('Microsoft', 'screenshot', 0, 'Proof of patch application'),
|
||||
('Cisco', 'advisory', 1, 'Cisco Security Advisory'),
|
||||
('Oracle', 'advisory', 1, 'Oracle Security Alert'),
|
||||
('VMware', 'advisory', 1, 'VMware Security Advisory'),
|
||||
('Adobe', 'advisory', 1, 'Adobe Security Bulletin');
|
||||
|
||||
CREATE VIEW IF NOT EXISTS cve_document_status AS
|
||||
SELECT
|
||||
c.id as record_id,
|
||||
c.cve_id,
|
||||
c.vendor,
|
||||
c.severity,
|
||||
c.status,
|
||||
COUNT(DISTINCT d.id) as total_documents,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) as advisory_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'email' THEN d.id END) as email_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'screenshot' THEN d.id END) as screenshot_count,
|
||||
CASE
|
||||
WHEN COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) > 0
|
||||
THEN 'Complete'
|
||||
ELSE 'Missing Required Docs'
|
||||
END as compliance_status
|
||||
FROM cves c
|
||||
LEFT JOIN documents d ON c.cve_id = d.cve_id AND c.vendor = d.vendor
|
||||
GROUP BY c.id, c.cve_id, c.vendor, c.severity, c.status;
|
||||
`;
|
||||
|
||||
db.exec(schema, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
console.log('✓ Database initialized successfully');
|
||||
resolve(db);
|
||||
}
|
||||
else resolve(this);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Create uploads directory structure
|
||||
function createUploadsDirectory() {
|
||||
if (!fs.existsSync(UPLOADS_DIR)) {
|
||||
fs.mkdirSync(UPLOADS_DIR, { recursive: true });
|
||||
console.log('✓ Created uploads directory');
|
||||
} else {
|
||||
console.log('✓ Uploads directory already exists');
|
||||
}
|
||||
}
|
||||
|
||||
// Create default admin user
|
||||
async function createDefaultAdmin(db) {
|
||||
function dbGet(db, sql, params = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Check if admin already exists
|
||||
db.get('SELECT id FROM users WHERE username = ?', ['admin'], async (err, row) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (row) {
|
||||
console.log('✓ Default admin user already exists');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate a random admin password on first run
|
||||
const generatedPassword = crypto.randomBytes(12).toString('base64url');
|
||||
const passwordHash = await bcrypt.hash(generatedPassword, 10);
|
||||
|
||||
db.run(
|
||||
`INSERT INTO users (username, email, password_hash, role, is_active)
|
||||
VALUES (?, ?, ?, ?, ?)`,
|
||||
['admin', 'admin@localhost', passwordHash, 'admin', 1],
|
||||
(err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
console.log('✓ Created default admin user');
|
||||
console.log(`\n ╔══════════════════════════════════════════╗`);
|
||||
console.log(` ║ Admin credentials (save these now!) ║`);
|
||||
console.log(` ║ Username: admin ║`);
|
||||
console.log(` ║ Password: ${generatedPassword.padEnd(29)}║`);
|
||||
console.log(` ╚══════════════════════════════════════════╝\n`);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
);
|
||||
db.get(sql, params, (err, row) => {
|
||||
if (err) reject(err);
|
||||
else resolve(row);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Add sample CVE data (optional - for testing)
|
||||
async function addSampleData(db) {
|
||||
console.log('\n📝 Adding sample CVE data for testing...');
|
||||
|
||||
const sampleCVEs = [
|
||||
{
|
||||
cve_id: 'CVE-2024-SAMPLE-1',
|
||||
vendor: 'Microsoft',
|
||||
severity: 'Critical',
|
||||
description: 'Sample remote code execution vulnerability',
|
||||
published_date: '2024-01-15'
|
||||
},
|
||||
{
|
||||
cve_id: 'CVE-2024-SAMPLE-1',
|
||||
vendor: 'Cisco',
|
||||
severity: 'High',
|
||||
description: 'Sample remote code execution vulnerability',
|
||||
published_date: '2024-01-15'
|
||||
}
|
||||
function dbExec(db, sql) {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.exec(sql, (err) => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Schema — complete v1.0.0 database structure
|
||||
// ---------------------------------------------------------------------------
|
||||
async function initializeDatabase(db) {
|
||||
await dbExec(db, `
|
||||
|
||||
-- =================================================================
|
||||
-- Core CVE tracking tables
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS cves (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
severity VARCHAR(20) NOT NULL,
|
||||
description TEXT,
|
||||
published_date DATE,
|
||||
status VARCHAR(50) DEFAULT 'Open',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(cve_id, vendor)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS documents (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id VARCHAR(20) NOT NULL,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
file_path VARCHAR(500) NOT NULL,
|
||||
file_size VARCHAR(20),
|
||||
mime_type VARCHAR(100),
|
||||
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
notes TEXT,
|
||||
FOREIGN KEY (cve_id) REFERENCES cves(cve_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS required_documents (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
vendor VARCHAR(100) NOT NULL,
|
||||
document_type VARCHAR(50) NOT NULL,
|
||||
is_mandatory BOOLEAN DEFAULT 1,
|
||||
description TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_cve_id ON cves(cve_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_vendor ON cves(vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_severity ON cves(severity);
|
||||
CREATE INDEX IF NOT EXISTS idx_status ON cves(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_cve_id ON documents(cve_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_vendor ON documents(vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_type ON documents(type);
|
||||
|
||||
-- =================================================================
|
||||
-- Authentication and session management
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username VARCHAR(50) UNIQUE NOT NULL,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
role VARCHAR(20) NOT NULL DEFAULT 'viewer',
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_login TIMESTAMP,
|
||||
user_group VARCHAR(20) NOT NULL DEFAULT 'Read_Only',
|
||||
CHECK (role IN ('admin', 'editor', 'viewer'))
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
session_id VARCHAR(255) UNIQUE NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_session_id ON sessions(session_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_username ON users(username);
|
||||
CREATE INDEX IF NOT EXISTS idx_users_user_group ON users(user_group);
|
||||
|
||||
-- =================================================================
|
||||
-- Audit logging
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
username VARCHAR(50) NOT NULL,
|
||||
action VARCHAR(50) NOT NULL,
|
||||
entity_type VARCHAR(50) NOT NULL,
|
||||
entity_id VARCHAR(100),
|
||||
details TEXT,
|
||||
ip_address VARCHAR(45),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_user_id ON audit_logs(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_action ON audit_logs(action);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_entity_type ON audit_logs(entity_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_created_at ON audit_logs(created_at);
|
||||
|
||||
-- =================================================================
|
||||
-- Jira integration
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS jira_tickets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
cve_id TEXT NOT NULL,
|
||||
vendor TEXT NOT NULL,
|
||||
ticket_key TEXT NOT NULL,
|
||||
url TEXT,
|
||||
summary TEXT,
|
||||
status TEXT DEFAULT 'Open' CHECK(status IN ('Open', 'In Progress', 'Closed')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (cve_id, vendor) REFERENCES cves(cve_id, vendor) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_jira_tickets_cve ON jira_tickets(cve_id, vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_jira_tickets_status ON jira_tickets(status);
|
||||
|
||||
-- =================================================================
|
||||
-- Archer integration
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS archer_tickets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
exc_number TEXT NOT NULL UNIQUE,
|
||||
archer_url TEXT,
|
||||
status TEXT DEFAULT 'Draft' CHECK(status IN ('Draft', 'Open', 'Under Review', 'Accepted')),
|
||||
cve_id TEXT NOT NULL,
|
||||
vendor TEXT NOT NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (cve_id, vendor) REFERENCES cves(cve_id, vendor) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_archer_tickets_cve ON archer_tickets(cve_id, vendor);
|
||||
CREATE INDEX IF NOT EXISTS idx_archer_tickets_status ON archer_tickets(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_archer_tickets_exc ON archer_tickets(exc_number);
|
||||
|
||||
-- =================================================================
|
||||
-- Knowledge base
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS knowledge_base (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
slug VARCHAR(255) UNIQUE NOT NULL,
|
||||
description TEXT,
|
||||
category VARCHAR(100),
|
||||
file_path VARCHAR(500),
|
||||
file_name VARCHAR(255),
|
||||
file_type VARCHAR(50),
|
||||
file_size INTEGER,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
created_by INTEGER,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledge_base_slug ON knowledge_base(slug);
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledge_base_category ON knowledge_base(category);
|
||||
CREATE INDEX IF NOT EXISTS idx_knowledge_base_created_at ON knowledge_base(created_at DESC);
|
||||
|
||||
-- =================================================================
|
||||
-- Ivanti findings sync and cache
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_sync_state (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
total INTEGER DEFAULT 0,
|
||||
workflows_json TEXT DEFAULT '[]',
|
||||
synced_at DATETIME,
|
||||
sync_status TEXT DEFAULT 'never',
|
||||
error_message TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_findings_cache (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
total INTEGER DEFAULT 0,
|
||||
findings_json TEXT DEFAULT '[]',
|
||||
synced_at DATETIME,
|
||||
sync_status TEXT DEFAULT 'never',
|
||||
error_message TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_finding_notes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL UNIQUE,
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_finding_notes_finding_id ON ivanti_finding_notes(finding_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_counts_cache (
|
||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
||||
open_count INTEGER DEFAULT 0,
|
||||
closed_count INTEGER DEFAULT 0,
|
||||
synced_at DATETIME,
|
||||
fp_workflow_counts_json TEXT DEFAULT '{}',
|
||||
fp_id_counts_json TEXT DEFAULT '{}'
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_finding_overrides (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL,
|
||||
field TEXT NOT NULL,
|
||||
value TEXT NOT NULL DEFAULT '',
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(finding_id, field)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_finding_overrides_finding_id ON ivanti_finding_overrides(finding_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_counts_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
open_count INTEGER NOT NULL,
|
||||
closed_count INTEGER NOT NULL,
|
||||
recorded_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- =================================================================
|
||||
-- Ivanti FP (False Positive) submissions
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_fp_submissions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
ivanti_workflow_batch_id INTEGER,
|
||||
ivanti_generated_id TEXT,
|
||||
ivanti_workflow_batch_uuid TEXT,
|
||||
workflow_name TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
description TEXT,
|
||||
expiration_date TEXT NOT NULL,
|
||||
scope_override TEXT NOT NULL DEFAULT 'Authorized',
|
||||
finding_ids_json TEXT NOT NULL,
|
||||
queue_item_ids_json TEXT NOT NULL,
|
||||
attachment_count INTEGER DEFAULT 0,
|
||||
attachment_results_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'success' CHECK(status IN ('success', 'partial', 'failed')),
|
||||
lifecycle_status TEXT NOT NULL DEFAULT 'submitted' CHECK(lifecycle_status IN ('submitted', 'approved', 'rejected', 'rework', 'resubmitted')),
|
||||
error_message TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fp_submissions_user ON ivanti_fp_submissions(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_fp_submissions_ivanti_id ON ivanti_fp_submissions(ivanti_generated_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_fp_submission_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
submission_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
change_type TEXT NOT NULL CHECK(change_type IN (
|
||||
'created', 'fields_updated', 'findings_added',
|
||||
'attachments_added', 'status_changed'
|
||||
)),
|
||||
change_details_json TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (submission_id) REFERENCES ivanti_fp_submissions(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_fp_history_submission ON ivanti_fp_submission_history(submission_id);
|
||||
|
||||
-- =================================================================
|
||||
-- Ivanti todo queue (FP, Archer, CARD, GRANITE workflows)
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_todo_queue (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
finding_id TEXT NOT NULL,
|
||||
finding_title TEXT,
|
||||
cves_json TEXT,
|
||||
ip_address TEXT,
|
||||
hostname TEXT,
|
||||
vendor TEXT NOT NULL,
|
||||
workflow_type TEXT NOT NULL CHECK(workflow_type IN ('FP', 'Archer', 'CARD', 'GRANITE')),
|
||||
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'complete')),
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_todo_queue_user ON ivanti_todo_queue(user_id, status);
|
||||
|
||||
-- =================================================================
|
||||
-- Ivanti archive detection and anomaly tracking
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_finding_archives (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL UNIQUE,
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
ip_address TEXT NOT NULL DEFAULT '',
|
||||
current_state TEXT NOT NULL CHECK(current_state IN ('ARCHIVED','RETURNED','CLOSED','CLOSED_GONE')),
|
||||
last_severity REAL NOT NULL DEFAULT 0,
|
||||
first_archived_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
last_transition_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_archive_finding_id ON ivanti_finding_archives(finding_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_archive_current_state ON ivanti_finding_archives(current_state);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_archive_transitions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
archive_id INTEGER NOT NULL,
|
||||
from_state TEXT NOT NULL,
|
||||
to_state TEXT NOT NULL,
|
||||
severity_at_transition REAL NOT NULL DEFAULT 0,
|
||||
reason TEXT NOT NULL DEFAULT '',
|
||||
transitioned_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (archive_id) REFERENCES ivanti_finding_archives(id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_transition_archive_id ON ivanti_archive_transitions(archive_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_sync_anomaly_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
sync_timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
open_count_delta INTEGER NOT NULL DEFAULT 0,
|
||||
closed_count_delta INTEGER NOT NULL DEFAULT 0,
|
||||
newly_archived_count INTEGER NOT NULL DEFAULT 0,
|
||||
returned_count INTEGER NOT NULL DEFAULT 0,
|
||||
classification_json TEXT NOT NULL DEFAULT '{}',
|
||||
return_classification_json TEXT NOT NULL DEFAULT '{}',
|
||||
is_significant INTEGER NOT NULL DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_anomaly_sync_timestamp ON ivanti_sync_anomaly_log(sync_timestamp);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ivanti_finding_bu_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
finding_id TEXT NOT NULL,
|
||||
finding_title TEXT NOT NULL DEFAULT '',
|
||||
host_name TEXT NOT NULL DEFAULT '',
|
||||
previous_bu TEXT NOT NULL,
|
||||
new_bu TEXT NOT NULL,
|
||||
detected_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_bu_history_finding_id ON ivanti_finding_bu_history(finding_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bu_history_detected_at ON ivanti_finding_bu_history(detected_at);
|
||||
|
||||
-- =================================================================
|
||||
-- Atlas action plans cache
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS atlas_action_plans_cache (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
host_id INTEGER NOT NULL UNIQUE,
|
||||
has_action_plan INTEGER NOT NULL DEFAULT 0,
|
||||
plan_count INTEGER NOT NULL DEFAULT 0,
|
||||
plans_json TEXT NOT NULL DEFAULT '[]',
|
||||
synced_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_atlas_cache_host_id ON atlas_action_plans_cache(host_id);
|
||||
|
||||
-- =================================================================
|
||||
-- Compliance (NTS AEO) tracking
|
||||
-- =================================================================
|
||||
|
||||
CREATE TABLE IF NOT EXISTS compliance_uploads (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
filename TEXT NOT NULL,
|
||||
report_date TEXT,
|
||||
uploaded_by INTEGER,
|
||||
uploaded_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
new_count INTEGER DEFAULT 0,
|
||||
resolved_count INTEGER DEFAULT 0,
|
||||
recurring_count INTEGER DEFAULT 0,
|
||||
summary_json TEXT,
|
||||
FOREIGN KEY (uploaded_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS compliance_items (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
upload_id INTEGER NOT NULL,
|
||||
hostname TEXT NOT NULL,
|
||||
ip_address TEXT,
|
||||
device_type TEXT,
|
||||
team TEXT,
|
||||
metric_id TEXT NOT NULL,
|
||||
metric_desc TEXT,
|
||||
category TEXT,
|
||||
extra_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'active' CHECK(status IN ('active', 'resolved')),
|
||||
first_seen_upload_id INTEGER,
|
||||
resolved_upload_id INTEGER,
|
||||
seen_count INTEGER DEFAULT 1,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (upload_id) REFERENCES compliance_uploads(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (first_seen_upload_id) REFERENCES compliance_uploads(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (resolved_upload_id) REFERENCES compliance_uploads(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_compliance_items_upload ON compliance_items(upload_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_compliance_items_identity ON compliance_items(hostname, metric_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_compliance_items_team_status ON compliance_items(team, status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS compliance_notes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
hostname TEXT NOT NULL,
|
||||
metric_id TEXT NOT NULL,
|
||||
note TEXT NOT NULL,
|
||||
group_id TEXT,
|
||||
created_by INTEGER,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_compliance_notes_identity ON compliance_notes(hostname, metric_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_compliance_notes_group ON compliance_notes(group_id);
|
||||
|
||||
-- =================================================================
|
||||
-- Document compliance view
|
||||
-- =================================================================
|
||||
|
||||
CREATE VIEW IF NOT EXISTS cve_document_status AS
|
||||
SELECT
|
||||
c.id as record_id,
|
||||
c.cve_id,
|
||||
c.vendor,
|
||||
c.severity,
|
||||
c.status,
|
||||
COUNT(DISTINCT d.id) as total_documents,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) as advisory_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'email' THEN d.id END) as email_count,
|
||||
COUNT(DISTINCT CASE WHEN d.type = 'screenshot' THEN d.id END) as screenshot_count,
|
||||
CASE
|
||||
WHEN COUNT(DISTINCT CASE WHEN d.type = 'advisory' THEN d.id END) > 0
|
||||
THEN 'Complete'
|
||||
ELSE 'Missing Required Docs'
|
||||
END as compliance_status
|
||||
FROM cves c
|
||||
LEFT JOIN documents d ON c.cve_id = d.cve_id AND c.vendor = d.vendor
|
||||
GROUP BY c.id, c.cve_id, c.vendor, c.severity, c.status;
|
||||
|
||||
-- =================================================================
|
||||
-- Seed data
|
||||
-- =================================================================
|
||||
|
||||
INSERT OR IGNORE INTO required_documents (vendor, document_type, is_mandatory, description) VALUES
|
||||
('Microsoft', 'advisory', 1, 'Official Microsoft Security Advisory'),
|
||||
('Microsoft', 'screenshot', 0, 'Proof of patch application'),
|
||||
('Cisco', 'advisory', 1, 'Cisco Security Advisory'),
|
||||
('Oracle', 'advisory', 1, 'Oracle Security Alert'),
|
||||
('VMware', 'advisory', 1, 'VMware Security Advisory'),
|
||||
('Adobe', 'advisory', 1, 'Adobe Security Bulletin');
|
||||
`);
|
||||
|
||||
console.log('✓ Database schema initialized');
|
||||
|
||||
// User group validation triggers (cannot be in db.exec multi-statement)
|
||||
await dbRun(db, `
|
||||
CREATE TRIGGER IF NOT EXISTS check_user_group_insert
|
||||
BEFORE INSERT ON users
|
||||
FOR EACH ROW
|
||||
WHEN NEW.user_group NOT IN ('Admin', 'Standard_User', 'Leadership', 'Read_Only')
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'Invalid user_group value. Must be Admin, Standard_User, Leadership, or Read_Only');
|
||||
END
|
||||
`);
|
||||
|
||||
await dbRun(db, `
|
||||
CREATE TRIGGER IF NOT EXISTS check_user_group_update
|
||||
BEFORE UPDATE OF user_group ON users
|
||||
FOR EACH ROW
|
||||
WHEN NEW.user_group NOT IN ('Admin', 'Standard_User', 'Leadership', 'Read_Only')
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'Invalid user_group value. Must be Admin, Standard_User, Leadership, or Read_Only');
|
||||
END
|
||||
`);
|
||||
|
||||
console.log('✓ Triggers created');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Directory setup
|
||||
// ---------------------------------------------------------------------------
|
||||
function createDirectories() {
|
||||
const dirs = [
|
||||
UPLOADS_DIR,
|
||||
path.join(UPLOADS_DIR, 'temp'),
|
||||
path.join(UPLOADS_DIR, 'knowledge_base'),
|
||||
];
|
||||
|
||||
for (const cve of sampleCVEs) {
|
||||
await new Promise((resolve, reject) => {
|
||||
db.run(
|
||||
`INSERT OR IGNORE INTO cves (cve_id, vendor, severity, description, published_date)
|
||||
VALUES (?, ?, ?, ?, ?)`,
|
||||
[cve.cve_id, cve.vendor, cve.severity, cve.description, cve.published_date],
|
||||
(err) => {
|
||||
if (err) reject(err);
|
||||
else {
|
||||
console.log(` ✓ Added sample: ${cve.cve_id} / ${cve.vendor}`);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
for (const dir of dirs) {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
console.log(`✓ Created directory: ${path.relative(__dirname, dir)}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('ℹ️ Sample data added - demonstrates multi-vendor support');
|
||||
}
|
||||
|
||||
// Verify database structure
|
||||
async function verifySetup(db) {
|
||||
return new Promise((resolve) => {
|
||||
db.get('SELECT sql FROM sqlite_master WHERE type="table" AND name="cves"', (err, row) => {
|
||||
if (err) {
|
||||
console.error('Warning: Could not verify setup:', err);
|
||||
} else {
|
||||
console.log('\n📋 CVEs table structure:');
|
||||
console.log(row.sql);
|
||||
|
||||
// Check if UNIQUE constraint is correct
|
||||
if (row.sql.includes('UNIQUE(cve_id, vendor)')) {
|
||||
console.log('\n✅ Multi-vendor support: ENABLED');
|
||||
} else {
|
||||
console.log('\n⚠️ Warning: Multi-vendor constraint may not be set correctly');
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
// ---------------------------------------------------------------------------
|
||||
// Default admin user
|
||||
// ---------------------------------------------------------------------------
|
||||
async function createDefaultAdmin(db) {
|
||||
const existing = await dbGet(db, 'SELECT id FROM users WHERE username = ?', ['admin']);
|
||||
if (existing) {
|
||||
console.log('✓ Default admin user already exists');
|
||||
return;
|
||||
}
|
||||
|
||||
const generatedPassword = crypto.randomBytes(12).toString('base64url');
|
||||
const passwordHash = await bcrypt.hash(generatedPassword, 10);
|
||||
|
||||
await dbRun(db,
|
||||
`INSERT INTO users (username, email, password_hash, role, user_group, is_active)
|
||||
VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
['admin', 'admin@localhost', passwordHash, 'admin', 'Admin', 1]
|
||||
);
|
||||
|
||||
console.log('✓ Created default admin user');
|
||||
console.log(`\n ╔══════════════════════════════════════════╗`);
|
||||
console.log(` ║ Admin credentials (save these now!) ║`);
|
||||
console.log(` ║ Username: admin ║`);
|
||||
console.log(` ║ Password: ${generatedPassword.padEnd(29)}║`);
|
||||
console.log(` ╚══════════════════════════════════════════╝\n`);
|
||||
}
|
||||
|
||||
// Display setup summary
|
||||
// ---------------------------------------------------------------------------
|
||||
// Setup summary
|
||||
// ---------------------------------------------------------------------------
|
||||
function displaySummary() {
|
||||
console.log('\n╔════════════════════════════════════════════════════════╗');
|
||||
console.log('║ CVE DATABASE SETUP COMPLETE! ║');
|
||||
console.log('║ CVE DASHBOARD v1.0.0 — SETUP COMPLETE ║');
|
||||
console.log('╚════════════════════════════════════════════════════════╝');
|
||||
console.log('\n📊 What was created:');
|
||||
console.log(' ✓ SQLite database (cve_database.db)');
|
||||
console.log(' ✓ Tables: cves, documents, required_documents, users, sessions, audit_logs');
|
||||
console.log(' ✓ Multi-vendor support with UNIQUE(cve_id, vendor)');
|
||||
console.log(' ✓ Vendor column in documents table');
|
||||
console.log(' ✓ User authentication with session-based auth');
|
||||
console.log(' ✓ Indexes for fast queries');
|
||||
console.log(' ✓ Document compliance view');
|
||||
console.log(' ✓ Uploads directory for file storage');
|
||||
console.log(' ✓ Default admin user (see credentials above)');
|
||||
console.log('\n📁 File structure will be:');
|
||||
console.log(' uploads/');
|
||||
console.log(' └── CVE-XXXX-XXXX/');
|
||||
console.log(' ├── Vendor1/');
|
||||
console.log(' │ ├── advisory.pdf');
|
||||
console.log(' │ └── screenshot.png');
|
||||
console.log(' └── Vendor2/');
|
||||
console.log(' └── advisory.pdf');
|
||||
console.log('\n📊 Tables created:');
|
||||
console.log(' Core: cves, documents, required_documents');
|
||||
console.log(' Auth: users, sessions');
|
||||
console.log(' Audit: audit_logs');
|
||||
console.log(' Jira: jira_tickets');
|
||||
console.log(' Archer: archer_tickets');
|
||||
console.log(' KB: knowledge_base');
|
||||
console.log(' Ivanti: ivanti_sync_state, ivanti_findings_cache,');
|
||||
console.log(' ivanti_finding_notes, ivanti_counts_cache,');
|
||||
console.log(' ivanti_finding_overrides, ivanti_counts_history,');
|
||||
console.log(' ivanti_fp_submissions, ivanti_fp_submission_history,');
|
||||
console.log(' ivanti_todo_queue');
|
||||
console.log(' Archives: ivanti_finding_archives, ivanti_archive_transitions,');
|
||||
console.log(' ivanti_sync_anomaly_log, ivanti_finding_bu_history');
|
||||
console.log(' Atlas: atlas_action_plans_cache');
|
||||
console.log(' Compliance: compliance_uploads, compliance_items, compliance_notes');
|
||||
console.log('\n🚀 Next steps:');
|
||||
console.log(' 1. Start the backend API:');
|
||||
console.log(' → cd backend && node server.js');
|
||||
console.log(' 2. Start the frontend:');
|
||||
console.log(' → cd frontend && npm start');
|
||||
console.log(' 3. Open http://localhost:3000');
|
||||
console.log(' 4. Start adding CVEs with multiple vendors!');
|
||||
console.log('\n💡 Key Features:');
|
||||
console.log(' • Add same CVE-ID with different vendors');
|
||||
console.log(' • Each vendor has separate document storage');
|
||||
console.log(' • Quick Check shows all vendors for a CVE');
|
||||
console.log(' • Document compliance tracking per vendor');
|
||||
console.log(' • Required docs: Advisory (mandatory for most vendors)\n');
|
||||
console.log(' 1. Copy .env.example to .env and configure API keys');
|
||||
console.log(' 2. Start the backend: node backend/server.js');
|
||||
console.log(' 3. Build the frontend: cd frontend && npm run build');
|
||||
console.log(' 4. Open the dashboard and log in with the admin credentials above\n');
|
||||
}
|
||||
|
||||
// Main execution
|
||||
// ---------------------------------------------------------------------------
|
||||
// Main
|
||||
// ---------------------------------------------------------------------------
|
||||
async function main() {
|
||||
console.log('🚀 CVE Database Setup (Multi-Vendor Support)\n');
|
||||
console.log('🚀 CVE Dashboard v1.0.0 — Database Setup\n');
|
||||
console.log('════════════════════════════════════════\n');
|
||||
|
||||
try {
|
||||
// Create uploads directory
|
||||
createUploadsDirectory();
|
||||
|
||||
// Initialize database
|
||||
const db = await initializeDatabase();
|
||||
|
||||
// Create default admin user
|
||||
try {
|
||||
createDirectories();
|
||||
|
||||
const db = new sqlite3.Database(DB_FILE);
|
||||
await initializeDatabase(db);
|
||||
await createDefaultAdmin(db);
|
||||
|
||||
// Add sample data
|
||||
await addSampleData(db);
|
||||
|
||||
// Verify setup
|
||||
await verifySetup(db);
|
||||
|
||||
// Close database connection
|
||||
db.close((err) => {
|
||||
if (err) console.error('Error closing database:', err);
|
||||
else console.log('\n✓ Database connection closed');
|
||||
|
||||
// Display summary
|
||||
else console.log('✓ Database connection closed');
|
||||
displaySummary();
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Setup Error:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the setup
|
||||
main();
|
||||
|
||||
BIN
cve_database.db
Normal file
BIN
cve_database.db
Normal file
Binary file not shown.
0
database.db
Normal file
0
database.db
Normal file
1316
docs/api/atlasinfosec-api-spec.json
Normal file
1316
docs/api/atlasinfosec-api-spec.json
Normal file
File diff suppressed because it is too large
Load Diff
194
docs/api/ivanti-api-reference.md
Normal file
194
docs/api/ivanti-api-reference.md
Normal file
@@ -0,0 +1,194 @@
|
||||
# Ivanti / RiskSense API Reference
|
||||
|
||||
Base URL: `https://platform4.risksense.com/api/v1`
|
||||
Swagger: `https://platform4.risksense.com/doc/swagger.json`
|
||||
|
||||
Auth: `x-api-key` header. Error codes: 401 bad key, 419 insufficient privileges, 429 rate limited.
|
||||
|
||||
## Endpoints Used
|
||||
|
||||
### Search Workflow Batches
|
||||
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/search
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
Standard JSON body with filters, projection, sort, page, size. Used by `ivantiWorkflows.js` for the daily sync.
|
||||
|
||||
### Create False Positive Workflow
|
||||
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/falsePositive/request
|
||||
Content-Type: multipart/form-data
|
||||
```
|
||||
|
||||
This endpoint does NOT accept JSON. It requires `multipart/form-data` with the following fields:
|
||||
|
||||
| Field | Type | Required | Notes |
|
||||
|-------|------|----------|-------|
|
||||
| `name` | string | yes | Workflow batch name (max 255) |
|
||||
| `reason` | string | yes | Reason for the FP determination |
|
||||
| `description` | string | yes | Description (can be empty string but field must be present) |
|
||||
| `expirationDate` | string | yes | ISO-8601 date, e.g. `2026-06-01` |
|
||||
| `overrideControl` | string | yes | `AUTHORIZED`, `NONE`, or `AUTOMATED`. Use `AUTHORIZED` for standard FP workflows. `NONE` with `isEmptyWorkflow=true` is rejected (400). |
|
||||
| `isEmptyWorkflow` | boolean | yes | `true` if no findings attached, `false` otherwise |
|
||||
| `subjectFilterRequest` | string | yes | Stringified JSON (see format below) |
|
||||
| `files` | file | no | Attachments sent inline in the same request |
|
||||
|
||||
#### subjectFilterRequest format
|
||||
|
||||
This is the critical field. It must be a stringified JSON object with this exact structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"subject": "hostFinding",
|
||||
"filterRequest": {
|
||||
"filters": [
|
||||
{
|
||||
"field": "id",
|
||||
"exclusive": false,
|
||||
"operator": "IN",
|
||||
"value": "2283734550,2283734551"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Key details:
|
||||
- `subject` must be `"hostFinding"` — without this, the API returns 500
|
||||
- `filters` is nested inside `filterRequest`, NOT at the top level — `{"filters":[]}` at the top level returns 500
|
||||
- `value` for multiple IDs is comma-separated as a single string, not an array
|
||||
- `operator` values: `EXACT`, `IN`, `LIKE`, `WILDCARD`, `RANGE`, `CIDR`
|
||||
- For empty workflows, use `{"subject":"hostFinding","filterRequest":{"filters":[]}}` with `isEmptyWorkflow=true`
|
||||
|
||||
#### Response (200/202)
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 33418832,
|
||||
"created": "2026-04-08T18:16:08"
|
||||
}
|
||||
```
|
||||
|
||||
Returns HTTP 200 or 202 (Accepted — async job creation). Response contains a numeric `id` (the workflow batch job ID) and `created` timestamp. No `generatedId` or `uuid` in this response.
|
||||
|
||||
### Map Findings to Existing Workflow (tested 2026-04-13)
|
||||
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/falsePositive/{workflowBatchUuid}/map
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
Maps additional host findings to an existing FP workflow batch. Used by the FP submission editing feature to add findings after initial creation.
|
||||
|
||||
**Critical: one finding per call.** The map endpoint only reliably maps one finding per request. Sending multiple finding IDs via the `IN` operator or comma-separated values results in only the first finding being mapped. The multipart/form-data format (used by the create endpoint) returns 500 on this endpoint.
|
||||
|
||||
#### Request body
|
||||
|
||||
```json
|
||||
{
|
||||
"subject": "hostFinding",
|
||||
"filterRequest": {
|
||||
"filters": [
|
||||
{
|
||||
"field": "id",
|
||||
"exclusive": false,
|
||||
"operator": "EXACT",
|
||||
"value": "2283734550"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Key details:
|
||||
- Must be `application/json` (NOT multipart/form-data — returns 500)
|
||||
- Use `EXACT` operator with a single finding ID per call
|
||||
- `IN` operator with comma-separated IDs only maps the first finding
|
||||
- Loop through findings and make one API call per finding
|
||||
- The `workflowBatchUuid` in the URL is the UUID from the search endpoint (not the numeric batch ID from create)
|
||||
|
||||
#### Response (200)
|
||||
|
||||
Returns the updated workflow batch object on success.
|
||||
|
||||
#### UUID resolution
|
||||
|
||||
The `workflowBatchUuid` required in the URL is NOT returned by the create endpoint. To obtain it:
|
||||
|
||||
1. Search via `POST /client/{clientId}/workflowBatch/search` with `{ field: 'name', operator: 'EXACT', value: '<workflow_name>' }`
|
||||
2. Use `projection: 'internal'` to get full batch objects
|
||||
3. The UUID is in the `uuid` field of the returned batch object
|
||||
4. Cache the UUID locally after first resolution (stored in `ivanti_fp_submissions.ivanti_workflow_batch_uuid`)
|
||||
|
||||
#### Implementation in dashboard
|
||||
|
||||
The `resolveWorkflowBatchUuid()` helper in `backend/routes/ivantiFpWorkflow.js` handles UUID resolution:
|
||||
- Returns cached UUID if available in the local submission record
|
||||
- Otherwise searches Ivanti by workflow name, extracts `batch.uuid`, and caches it for future use
|
||||
|
||||
The findings map loop in the `POST /submissions/:id/findings` endpoint:
|
||||
- Iterates through each finding ID individually
|
||||
- Makes one JSON POST per finding with `EXACT` operator
|
||||
- Tracks which findings succeeded vs failed
|
||||
- Only marks queue items as complete for successfully mapped findings
|
||||
- Returns both `addedFindings` and `failedFindings` arrays in the response
|
||||
|
||||
### Other Workflow Endpoints (from Swagger)
|
||||
|
||||
These are available but not all are currently used by the dashboard:
|
||||
|
||||
| Endpoint | Purpose | Status |
|
||||
|----------|---------|--------|
|
||||
| `/workflowBatch/acceptance/request` | Risk acceptance workflow | Not used |
|
||||
| `/workflowBatch/remediation/request` | Remediation workflow | Not used |
|
||||
| `/workflowBatch/severityChange/request` | Severity change workflow | Not used |
|
||||
| `/workflowBatch/{workflowType}/approve` | Approve a workflow (needs `workflowBatchUuid`) | Not used |
|
||||
| `/workflowBatch/{workflowType}/reject` | Reject a workflow | Not used |
|
||||
| `/workflowBatch/{workflowType}/rework` | Send back for rework | Not used |
|
||||
| `/workflowBatch/{workflowType}/update` | Update a workflow | Not used |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/map` | Map findings to workflow | Used (FP editing) |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/unmap` | Unmap findings | Not used |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/attach` | Attach file to existing workflow | **Broken — see note** |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/detach` | Detach file | Not used |
|
||||
| `/workflowBatch/model` | Get model/schema | Not used |
|
||||
| `/workflowBatch/filter` | Get available filter fields | Not used |
|
||||
| `/workflowBatch/suggest` | Get suggested values for a filter field | Not used |
|
||||
|
||||
### Known Limitations
|
||||
|
||||
#### Attach endpoint does not work (tested 2026-04-13)
|
||||
|
||||
The `/workflowBatch/{workflowType}/{workflowBatchUuid}/attach` endpoint is listed in the Swagger spec but returns HTTP 400 (Bad Request) for all tested request formats:
|
||||
|
||||
- `multipart/form-data` with field name `file` (singular) — 400
|
||||
- `multipart/form-data` with field name `files` (plural) — 400
|
||||
- Tested with `Content-Type: application/octet-stream` and `image/png` — both 400
|
||||
- Tested with both `ivantiMultipartPost` and `ivantiFormPost` helpers — both 400
|
||||
|
||||
The Ivanti response is a generic Spring Boot error with no detail message:
|
||||
```json
|
||||
{"timestamp":"...","status":400,"error":"Bad Request","path":"/api/v1/client/1550/workflowBatch/falsePositive/{uuid}/attach"}
|
||||
```
|
||||
|
||||
**Workaround:** File attachments can only be uploaded during the initial workflow creation (sent inline with the `/workflowBatch/falsePositive/request` endpoint). To add attachments to an existing workflow, users must upload them directly in the Ivanti platform UI.
|
||||
|
||||
#### Search by numeric batch ID does not work
|
||||
|
||||
The `/workflowBatch/search` endpoint does not support filtering by the numeric `id` returned from the create endpoint. Searching with `{ field: 'id', operator: 'EXACT', value: '33432541' }` returns 0 results. Searching by `name` field works and returns the workflow batch object including the `uuid` field needed for map/attach operations.
|
||||
|
||||
#### UUID not returned by create endpoint
|
||||
|
||||
The `/workflowBatch/falsePositive/request` create endpoint returns only `{ id: <number>, created: <timestamp> }`. The `uuid` needed for map/attach/approve/reject operations must be obtained separately via the search endpoint.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `IVANTI_API_KEY` | — | Required. API key for authentication |
|
||||
| `IVANTI_CLIENT_ID` | `1550` | Client ID in the Ivanti platform |
|
||||
| `IVANTI_SKIP_TLS` | `false` | Set `true` to skip TLS verification |
|
||||
| `IVANTI_FIRST_NAME` | — | Used for workflow search filter (sync) |
|
||||
| `IVANTI_LAST_NAME` | — | Used for workflow search filter (sync) |
|
||||
53228
docs/api/ivanti-neurons-swagger.json
Normal file
53228
docs/api/ivanti-neurons-swagger.json
Normal file
File diff suppressed because one or more lines are too long
170
docs/api/jira-api-use-cases.md
Normal file
170
docs/api/jira-api-use-cases.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# Jira REST API Use Cases — STEAM Security Dashboard
|
||||
|
||||
## Overview
|
||||
|
||||
The STEAM Security Dashboard is a self-hosted vulnerability management tool used by the NTS-AEO-STEAM and NTS-AEO-ACCESS-ENG teams. It integrates with Jira Data Center to create, track, and sync vulnerability remediation tickets linked to CVE records.
|
||||
|
||||
All API calls are made from a single Node.js backend process. The integration uses Basic Auth with a service account and enforces Charter's posted rate limits client-side.
|
||||
|
||||
---
|
||||
|
||||
## Charter Compliance Summary
|
||||
|
||||
| Requirement | Implementation |
|
||||
|---|---|
|
||||
| Authentication | Basic Auth with service account (`JIRA_API_USER` + `JIRA_API_TOKEN`) |
|
||||
| Rate limit — daily | Client-side enforced: 1 440 requests/day max |
|
||||
| Rate limit — burst | Client-side enforced: 60 requests/minute max |
|
||||
| Inter-request delay — GETs | 1 second minimum between GET requests |
|
||||
| Inter-request delay — writes | 2 seconds minimum between PUT/POST/DELETE requests |
|
||||
| Explicit field lists | Every GET includes `?fields=` parameter; `/rest/api/2/field` is blocked |
|
||||
| No bulk updates | Issues are updated one at a time; `/rest/api/2/issue/bulk` is blocked |
|
||||
| Bulk reads via JQL | Multi-ticket sync uses a single `GET /rest/api/2/search` with JQL query parameters, not per-issue GETs |
|
||||
| Single-issue fetch via JQL | `GET /rest/api/2/search?jql=key="KEY" AND project=<KEY>&fields=...&maxResults=1` |
|
||||
| JQL scoping | All recurring JQL queries include `updated >= -Xh` clause and `project = <KEY>` scoping |
|
||||
| `maxResults` cap | Search queries capped at 1 000 results per page |
|
||||
|
||||
---
|
||||
|
||||
## Use Cases
|
||||
|
||||
### 1. Connection Test
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `GET /rest/api/2/myself` |
|
||||
| **Trigger** | Admin clicks "Test Connection" on the Jira settings panel |
|
||||
| **Frequency** | Manual, infrequent (a few times per day at most) |
|
||||
| **Purpose** | Verify service account credentials and connectivity |
|
||||
| **Fields requested** | Default (myself endpoint returns user profile) |
|
||||
|
||||
### 2. Create Issue
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `POST /rest/api/2/issue` |
|
||||
| **Trigger** | User clicks "Create in Jira" from a CVE detail panel |
|
||||
| **Frequency** | Manual, estimated 5–20 per day |
|
||||
| **Purpose** | Create a vulnerability remediation ticket linked to a CVE/vendor pair |
|
||||
| **Fields sent** | `project.key`, `summary`, `issuetype.name`, `description` |
|
||||
| **Notes** | A local record is also created in the dashboard database linking the Jira key to the CVE |
|
||||
|
||||
### 3. Get Single Issue
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `GET /rest/api/2/search?jql=key="ISSUE-KEY" AND project=<KEY>&fields=summary,status,assignee,created,updated,priority,issuetype,project,resolution&maxResults=1` |
|
||||
| **Trigger** | User clicks "Sync" on a single Jira ticket row |
|
||||
| **Frequency** | Manual, estimated 10–30 per day |
|
||||
| **Purpose** | Refresh a single ticket's status and summary from Jira via JQL search |
|
||||
| **Notes** | Uses JQL-based lookup instead of single-issue GET per Charter compliance. Fields are always specified explicitly. |
|
||||
|
||||
### 4. Update Issue
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `PUT /rest/api/2/issue/{issueKey}` |
|
||||
| **Trigger** | Future feature — local edits synced back to Jira |
|
||||
| **Frequency** | Manual, estimated 5–10 per day when enabled |
|
||||
| **Purpose** | Update issue summary or other fields from the dashboard |
|
||||
| **Notes** | Issues are updated one at a time; bulk PUT is not used |
|
||||
|
||||
### 5. Add Comment
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `POST /rest/api/2/issue/{issueKey}/comment` |
|
||||
| **Trigger** | Dashboard adds audit trail comments to linked tickets |
|
||||
| **Frequency** | Automated on certain actions, estimated 5–15 per day |
|
||||
| **Purpose** | Maintain an audit trail on the Jira ticket for compliance visibility |
|
||||
|
||||
### 6. Get Transitions
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `GET /rest/api/2/issue/{issueKey}/transitions` |
|
||||
| **Trigger** | Dashboard checks available workflow transitions before moving a ticket |
|
||||
| **Frequency** | Manual, paired with transition calls, estimated 5–10 per day |
|
||||
| **Purpose** | Discover valid status transitions for the issue's current workflow state |
|
||||
|
||||
### 7. Transition Issue
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `POST /rest/api/2/issue/{issueKey}/transitions` |
|
||||
| **Trigger** | User moves a ticket to a new status from the dashboard |
|
||||
| **Frequency** | Manual, estimated 5–10 per day |
|
||||
| **Purpose** | Move ticket through workflow states (e.g., Open to In Progress to Closed) |
|
||||
|
||||
### 8. JQL Search (Bulk Sync)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `GET /rest/api/2/search?jql=...&fields=...&maxResults=...&startAt=...` |
|
||||
| **Trigger** | Admin clicks "Sync All" on the Jira tickets panel |
|
||||
| **Frequency** | Manual, estimated 1–3 times per day |
|
||||
| **Purpose** | Bulk-refresh all tracked tickets in a single request instead of per-issue GETs |
|
||||
| **JQL pattern** | `key in ("KEY-1", "KEY-2", ...) AND updated >= -24h AND project = <KEY>` |
|
||||
| **Fields requested** | `summary, status, assignee, created, updated, priority, issuetype, project, resolution` |
|
||||
| **Batch size** | 100 keys per JQL query; multiple batches if needed |
|
||||
| **Notes** | Uses GET with URL-encoded query parameters per Charter compliance. Stops early if rate limit budget is running low (burst remaining <= 5 or daily remaining <= 10) |
|
||||
|
||||
### 9. Issue Lookup
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| **Endpoint** | `GET /rest/api/2/search?jql=key="ISSUE-KEY" AND project=<KEY>&fields=...&maxResults=1` |
|
||||
| **Trigger** | User looks up a Jira issue by key from the dashboard search |
|
||||
| **Frequency** | Manual, estimated 5–15 per day |
|
||||
| **Purpose** | Quick lookup of any Jira issue to view its current state via JQL search |
|
||||
|
||||
---
|
||||
|
||||
## Estimated Daily API Usage
|
||||
|
||||
| Operation | Estimated calls/day | Method | Delay enforced |
|
||||
|---|---|---|---|
|
||||
| Connection test | 2–5 | GET | 1s |
|
||||
| Create issue | 5–20 | POST | 2s |
|
||||
| Get single issue | 10–30 | GET | 1s |
|
||||
| Update issue | 5–10 | PUT | 2s |
|
||||
| Add comment | 5–15 | POST | 2s |
|
||||
| Get transitions | 5–10 | GET | 1s |
|
||||
| Transition issue | 5–10 | POST | 2s |
|
||||
| JQL search (sync) | 1–5 | GET | 1s |
|
||||
| Issue lookup | 5–15 | GET | 1s |
|
||||
| **Total estimated** | **43–120** | | |
|
||||
|
||||
Well within the 1 440/day limit. Burst usage stays under 60/minute due to enforced inter-request delays.
|
||||
|
||||
---
|
||||
|
||||
## Blocked Endpoints
|
||||
|
||||
The integration explicitly blocks these endpoints to comply with Charter policy:
|
||||
|
||||
- `/rest/api/2/field` — field metadata is never queried; fields are specified in code
|
||||
- `/rest/api/2/issue/bulk` — bulk updates are not used; issues are updated individually
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
- **429 responses**: Surfaced to the user as "Rate limit exceeded. Try again later." No automatic retry.
|
||||
- **5xx responses**: Surfaced as "Jira API error" with the response body for debugging.
|
||||
- **Network failures**: Caught and surfaced with the error message.
|
||||
- **Timeout**: 15 second timeout per request; surfaced as a timeout error.
|
||||
|
||||
---
|
||||
|
||||
## UAT Test Evidence
|
||||
|
||||
The UAT test script (`backend/scripts/jira-uat-test.js`) exercises all use cases listed above and produces a log file at `backend/scripts/jira-uat-test.log`. This log can be attached to or referenced in the ATLSUP approval ticket.
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
cd backend
|
||||
node scripts/jira-uat-test.js
|
||||
```
|
||||
|
||||
1080
docs/guides/full-reference-manual.md
Normal file
1080
docs/guides/full-reference-manual.md
Normal file
File diff suppressed because it is too large
Load Diff
94
docs/guides/kb-compliance-guide.md
Normal file
94
docs/guides/kb-compliance-guide.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# AEO Compliance Tracking Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The Compliance page tracks AEO security posture metrics for the STEAM and ACCESS-ENG teams. It processes weekly xlsx compliance reports, shows per-metric health cards, and tracks non-compliant devices down to the individual hostname level.
|
||||
|
||||
## Teams Tracked
|
||||
|
||||
Only two teams are monitored:
|
||||
- **STEAM** (NTS-AEO-STEAM)
|
||||
- **ACCESS-ENG** (NTS-AEO-ACCESS-ENG)
|
||||
|
||||
## Uploading a Compliance Report
|
||||
|
||||
### Prerequisites
|
||||
- You must have editor or admin access
|
||||
- The report must be an `.xlsx` file (the standard NTS_AEO compliance export)
|
||||
|
||||
### Upload Process
|
||||
|
||||
1. Navigate to the **Compliance** page
|
||||
2. Click the **Upload Report** button
|
||||
3. Drag and drop the xlsx file or click to browse
|
||||
4. The system parses the spreadsheet using a Python backend script and shows a **preview**:
|
||||
- **New items**: Devices/metrics appearing for the first time
|
||||
- **Recurring items**: Devices/metrics that were already non-compliant
|
||||
- **Resolved items**: Previously non-compliant items no longer in the report
|
||||
5. Review the diff summary
|
||||
6. Click **Commit** to save the data
|
||||
|
||||
The upload is a two-step process (preview then commit) so you can verify the data before it's written to the database.
|
||||
|
||||
## Health Cards
|
||||
|
||||
After uploading, the page displays metric health cards for each team. Each card shows:
|
||||
|
||||
- **Metric ID** — the compliance metric identifier
|
||||
- **Category** — the metric category (Vulnerability Management, Access & MFA, Logging & Monitoring, etc.)
|
||||
- **Compliance %** — current compliance percentage
|
||||
- **Target** — the required target percentage
|
||||
- **Status** — color-coded:
|
||||
- Green: Meets/Exceeds Target
|
||||
- Amber: Within 15% of Target
|
||||
- Red: Below 15% of Target
|
||||
|
||||
Click a health card to filter the device list to that specific metric.
|
||||
|
||||
## Metric Categories
|
||||
|
||||
| Category | Color |
|
||||
|----------|-------|
|
||||
| Vulnerability Management | Red |
|
||||
| Access & MFA | Amber |
|
||||
| Logging & Monitoring | Purple |
|
||||
| End-of-Life OS | Orange |
|
||||
| Decommissioned Assets | Slate |
|
||||
| Asset Data Quality | Slate |
|
||||
| Application Security | Blue |
|
||||
| Disaster Recovery | Teal |
|
||||
| Endpoint Protection | Orange |
|
||||
|
||||
## Device-Level Tracking
|
||||
|
||||
Below the health cards, the device list shows non-compliant devices grouped by hostname. Each device entry shows:
|
||||
|
||||
- Hostname and IP address
|
||||
- Device type and team assignment
|
||||
- Failing metrics with first-seen and last-seen dates
|
||||
- Seen count (how many consecutive reports the device has been non-compliant)
|
||||
|
||||
### Device Detail Panel
|
||||
|
||||
Click a device to open the detail panel showing:
|
||||
- All metrics the device is failing
|
||||
- Upload history (when the device first appeared, when it was last seen)
|
||||
- Per-metric notes with timestamps
|
||||
|
||||
### Adding Notes
|
||||
|
||||
You can add notes to one or more metrics on a device at once:
|
||||
1. Open the device detail panel
|
||||
2. Select the metrics the note applies to using the chip selector — click individual metric chips to toggle them, or use **Select All** / **Deselect All** for bulk selection
|
||||
3. Type your note and click send
|
||||
4. Notes are timestamped and attributed to the logged-in user
|
||||
|
||||
When a note is submitted for multiple metrics, it appears as a single grouped entry in the notes history with all associated metric chips displayed together. Notes are useful for tracking remediation progress, vendor ticket numbers, or explaining why a device is non-compliant.
|
||||
|
||||
## Data Flow
|
||||
|
||||
1. Weekly xlsx report is uploaded through the dashboard
|
||||
2. Python parser extracts team metrics and non-compliant devices
|
||||
3. Diff is computed against existing data (new/recurring/resolved)
|
||||
4. On commit: new items are inserted, recurring items have their seen_count incremented, resolved items are marked with resolved_on date
|
||||
5. Health cards and device lists update automatically
|
||||
104
docs/guides/kb-cve-tracking-guide.md
Normal file
104
docs/guides/kb-cve-tracking-guide.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# CVE Tracking & NVD Sync Spec
|
||||
|
||||
## Overview
|
||||
|
||||
The Home page (CVE Management) is where you track individual CVEs across vendors, store supporting documentation, and link Archer risk acceptance tickets. It serves as the reference library for all vulnerability research and evidence.
|
||||
|
||||
## Adding a CVE
|
||||
|
||||
1. Click "Add CVE" on the Home page
|
||||
2. Enter the **CVE ID** (format: CVE-YYYY-NNNNN, e.g., CVE-2024-6387)
|
||||
3. Click the NVD lookup button to auto-populate fields from the National Vulnerability Database:
|
||||
- Description
|
||||
- Severity (Critical, High, Medium, Low)
|
||||
- Published date
|
||||
4. Select or type the **Vendor/Platform** (e.g., Cisco, Juniper, ADTRAN)
|
||||
5. Review and adjust any fields as needed
|
||||
6. Click Save
|
||||
|
||||
### NVD Auto-Population
|
||||
|
||||
The NVD lookup queries the NIST NVD 2.0 API and extracts:
|
||||
- English description
|
||||
- CVSS severity using a cascade: v3.1 → v3.0 → v2.0
|
||||
- Published date
|
||||
|
||||
If the NVD API is rate-limited (429 response), wait a few seconds and try again. Having an NVD API key configured in the backend `.env` file increases the rate limit.
|
||||
|
||||
## CVE Details
|
||||
|
||||
Each CVE entry tracks:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| CVE ID | The CVE identifier (e.g., CVE-2024-6387) |
|
||||
| Vendor | The affected vendor/platform |
|
||||
| Severity | Critical, High, Medium, or Low |
|
||||
| Description | Vulnerability description (from NVD or manual entry) |
|
||||
| Published Date | When the CVE was published |
|
||||
| Status | Open, In Progress, Addressed, or Resolved |
|
||||
|
||||
## Document Storage
|
||||
|
||||
Each CVE/vendor pair can have supporting documents attached. These serve as evidence for FP workflows, Archer tickets, and audit purposes.
|
||||
|
||||
### Uploading Documents
|
||||
1. Open a CVE entry
|
||||
2. Click "Upload Document"
|
||||
3. Select the file (max 10 MB)
|
||||
4. Documents are stored in `uploads/cves/{cveId}/{vendor}/` on the server
|
||||
|
||||
### Document Types
|
||||
- **Advisory** — vendor security advisories
|
||||
- **Email** — vendor communications or support ticket responses
|
||||
- **Screenshot** — device screenshots showing version info
|
||||
- **Patch** — patch notes or release documentation
|
||||
- **Other** — any other supporting evidence
|
||||
|
||||
### Why Store Documents Here?
|
||||
Documents uploaded to CVE entries can be reused across multiple FP workflows. When an FP expires and needs renewal, the evidence is already in the dashboard rather than having to track it down again.
|
||||
|
||||
## Archer Ticket Tracking
|
||||
|
||||
Archer risk acceptance tickets (EXC-XXXXX) are linked to CVE/vendor pairs.
|
||||
|
||||
### Adding an Archer Ticket
|
||||
1. Open a CVE entry
|
||||
2. Click "Add Archer Ticket"
|
||||
3. Enter the EXC number (e.g., EXC-12345)
|
||||
4. Optionally add the Archer URL and status
|
||||
|
||||
### EXC Badge Integration
|
||||
Once an EXC number is entered:
|
||||
- An EXC badge appears on the CVE card on the Home page
|
||||
- Clicking the badge navigates to the Reporting page pre-filtered to findings with that EXC number in their notes
|
||||
- The Action Coverage chart on the Reporting page classifies findings with EXC numbers as "Archer Exception"
|
||||
|
||||
## Vendor Tracking
|
||||
|
||||
CVEs can be tracked across multiple vendors. Each CVE/vendor combination is a separate entry, allowing you to:
|
||||
- Track different remediation statuses per vendor
|
||||
- Store vendor-specific documentation
|
||||
- Link different Archer tickets per vendor
|
||||
|
||||
## Editing CVEs
|
||||
|
||||
1. Click the edit icon on a CVE card
|
||||
2. Modify any fields
|
||||
3. Use the NVD lookup button to refresh data from NVD if needed
|
||||
4. Click Save
|
||||
|
||||
## Quick Check
|
||||
|
||||
The Quick Check feature on the Home page lets you look up a CVE ID without adding it to the database:
|
||||
1. Type a CVE ID in the Quick Check field
|
||||
2. Press Enter — the NVD data is fetched and displayed
|
||||
3. If you want to track it, click "Add CVE" to create an entry
|
||||
|
||||
## Tips
|
||||
|
||||
- Always upload screenshots and vendor advisories to the CVE entry before submitting an FP workflow — reviewers may ask for this evidence
|
||||
- Use the status field to track progress: Open → In Progress → Addressed → Resolved
|
||||
- Link Archer EXC numbers as soon as the ticket is created — this updates the Action Coverage chart immediately
|
||||
- The search bar on the Home page searches across CVE ID, vendor, and description
|
||||
- Filter by vendor or severity using the dropdowns to focus on specific areas
|
||||
110
docs/guides/kb-fp-submission-editing-guide.md
Normal file
110
docs/guides/kb-fp-submission-editing-guide.md
Normal file
@@ -0,0 +1,110 @@
|
||||
# FP Workflow Queue & Submission Editing Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The STEAM Security Dashboard allows you to create, track, and edit False Positive (FP) workflow submissions directly from the Reporting Page. This guide covers the full workflow from adding findings to the queue through editing and resubmitting FP workflows.
|
||||
|
||||
## Adding Findings to the Queue
|
||||
|
||||
1. On the Reporting Page, select findings by clicking the checkboxes in the findings table
|
||||
2. Use Shift+Click to select a range of findings
|
||||
3. In the selection toolbar that appears, choose the workflow type (FP, Archer, or CARD)
|
||||
4. Enter the vendor name (not required for CARD)
|
||||
5. Click "Add to Queue"
|
||||
|
||||
The findings will appear in the Ivanti Queue panel (click the "Queue" button in the top-right).
|
||||
|
||||
## Creating an FP Workflow
|
||||
|
||||
1. Open the Queue panel
|
||||
2. Select the pending FP items you want to submit using the checkboxes
|
||||
3. Click "Create FP Workflow" at the bottom of the panel
|
||||
4. Fill in the required fields:
|
||||
- **Workflow Name**: Use the format `FP — CVE-XXXX-XXXX — Vendor` (e.g., `FP — CVE-2024-6387 — Cisco_STEAM`)
|
||||
- **Reason / Justification**: Explain why these findings are false positives
|
||||
- **Description** (optional): Additional context
|
||||
- **Expiration Date**: Must be a future date
|
||||
- **Scope Override**: Leave as "Authorized" for standard FP workflows
|
||||
5. Attach supporting files (screenshots, evidence) — up to 10 files, 10 MB each
|
||||
6. Click Submit
|
||||
|
||||
The workflow is created in the Ivanti platform and the queue items are marked as complete.
|
||||
|
||||
## Viewing Submissions
|
||||
|
||||
Your FP submissions appear in the "Submissions" section at the bottom of the Queue panel. Each submission shows:
|
||||
- Workflow name
|
||||
- Ivanti batch ID
|
||||
- Lifecycle status badge (color-coded)
|
||||
- Finding count
|
||||
- Submission date
|
||||
|
||||
Click any submission to open the Edit Modal.
|
||||
|
||||
## Lifecycle Status
|
||||
|
||||
Submissions go through these states:
|
||||
|
||||
| Status | Color | Meaning |
|
||||
|--------|-------|---------|
|
||||
| Submitted | Sky Blue | Awaiting review |
|
||||
| Rework | Amber | Reviewer sent it back — action needed |
|
||||
| Rejected | Red | Reviewer denied the FP request |
|
||||
| Resubmitted | Sky Blue | Edited and sent back for review |
|
||||
| Approved | Green | FP accepted — no further action |
|
||||
|
||||
The status badge automatically syncs with the Ivanti platform state when findings data is refreshed.
|
||||
|
||||
## Editing an Existing Submission
|
||||
|
||||
Open a submission from the Queue panel to access the Edit Modal with four tabs:
|
||||
|
||||
### Details Tab
|
||||
- Edit the workflow name, reason, description, expiration date, and scope override
|
||||
- Click "Save Details" to push changes to the Ivanti platform
|
||||
- If the submission was in Rework or Rejected status, saving automatically changes it to Resubmitted
|
||||
|
||||
### Findings Tab
|
||||
- View the current list of finding IDs mapped to this workflow
|
||||
- Add more findings from your pending FP queue items
|
||||
- Select the items to add and click "Add Findings"
|
||||
- Each finding is mapped individually to the Ivanti workflow
|
||||
|
||||
### Attachments Tab
|
||||
- View files that were uploaded with the original submission
|
||||
- **Note**: Adding attachments to an existing workflow is not supported via the Ivanti API. To add more files, upload them directly in the Ivanti platform.
|
||||
|
||||
### History Tab
|
||||
- View a chronological log of all changes made to the submission
|
||||
- Shows finding additions with the actual finding IDs
|
||||
- Displays Ivanti reviewer notes (rework feedback, approval notes) pulled directly from the Ivanti platform
|
||||
|
||||
## Handling Rework Requests
|
||||
|
||||
When a submission comes back for rework:
|
||||
|
||||
1. Open the submission from the Queue panel — the status badge will show "Rework" (amber)
|
||||
2. Go to the **History** tab to read the reviewer's notes explaining what needs to change
|
||||
3. Common rework reasons:
|
||||
- Need more screenshots showing remediation
|
||||
- Need to verify specific software versions
|
||||
- Missing evidence for some findings
|
||||
4. Go to the **Findings** tab to add any additional findings if needed
|
||||
5. Upload additional screenshots directly in the Ivanti platform (Attachments tab has a link)
|
||||
6. Go to the **Details** tab to update the reason/description if needed
|
||||
7. Click "Save Details" — the status automatically changes to Resubmitted
|
||||
|
||||
## Changing Status Manually
|
||||
|
||||
Use the status dropdown in the Edit Modal to manually change the lifecycle status. This is useful when:
|
||||
- You receive notification outside the dashboard that a submission was rejected
|
||||
- You want to mark a submission as approved after confirming in Ivanti
|
||||
|
||||
**Note**: Approved submissions are locked and cannot be edited.
|
||||
|
||||
## Tips
|
||||
|
||||
- Always include enough screenshots per audit guidance (e.g., 10 screenshots for 20-50 findings)
|
||||
- Use the naming convention `FP — CVE-XXXX-XXXX — Vendor_Team` for easy identification
|
||||
- Check the FP Workflow Status donut chart on the Reporting Page for an overview of all your FP ticket states
|
||||
- The workflow column in the findings table shows the current Ivanti state for each finding
|
||||
89
docs/guides/kb-ivanti-queue-guide.md
Normal file
89
docs/guides/kb-ivanti-queue-guide.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# Ivanti Queue & Batch Operations Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The Ivanti Queue is a personal staging area for batch-processing vulnerability findings. You select findings from the Reporting Page table, assign them a workflow type and vendor, and stage them in the queue. From there you can create FP workflows, track Archer exceptions, or manage CARD dispositions.
|
||||
|
||||
## Workflow Types
|
||||
|
||||
| Type | Color | Purpose | Vendor Required? |
|
||||
|------|-------|---------|-----------------|
|
||||
| FP | Amber | False Positive — finding is not actually a vulnerability | Yes |
|
||||
| Archer | Blue | Risk Acceptance — vulnerability exists but can't be patched | Yes |
|
||||
| CARD | Green | Asset disposition — device not owned by your BU | No |
|
||||
|
||||
## Adding Findings to the Queue
|
||||
|
||||
### Single Finding
|
||||
1. In the findings table, click the checkbox area on a row (not the checkbox itself — click the cell)
|
||||
2. A popover appears with:
|
||||
- The finding ID
|
||||
- Vendor/Platform input field (required for FP and Archer)
|
||||
- Workflow type toggle (FP / Archer / CARD)
|
||||
3. Enter the vendor name and select the workflow type
|
||||
4. Click "Add to Queue"
|
||||
|
||||
### Batch Add (Multiple Findings)
|
||||
1. Select multiple findings using checkboxes (Shift+Click for range selection)
|
||||
2. The selection toolbar appears at the top of the table
|
||||
3. Choose the workflow type (FP / Archer / CARD)
|
||||
4. Enter the vendor name (not needed for CARD)
|
||||
5. Click "Add to Queue" — all selected findings are added at once (up to 200 per batch)
|
||||
|
||||
## The Queue Panel
|
||||
|
||||
Click the **Queue** button (top right of the Reporting Page) to open the slide-out panel. The badge shows the count of pending items.
|
||||
|
||||
### Layout
|
||||
- Items are grouped by vendor (alphabetically)
|
||||
- CARD items appear in their own green section at the top
|
||||
- Each item shows: finding ID, CVEs, hostname, IP address, and workflow type badge
|
||||
|
||||
### Item Actions
|
||||
|
||||
| Action | How |
|
||||
|--------|-----|
|
||||
| Mark complete | Click the green checkbox |
|
||||
| Mark pending | Uncheck the green checkbox |
|
||||
| Select for deletion | Click the red checkbox (left side) |
|
||||
| Delete selected | Click "Delete (N)" button in footer |
|
||||
| Clear all completed | Click "Clear Completed" button in footer |
|
||||
| Redirect workflow | Click the redirect arrow (↗) on completed items |
|
||||
|
||||
### Redirect Feature
|
||||
|
||||
When a finding is completed under one workflow type but needs to be processed under another:
|
||||
1. Complete the item first
|
||||
2. Click the redirect arrow (↗) icon
|
||||
3. Choose the new workflow type
|
||||
4. A new pending item is created with the same finding data but the new workflow type
|
||||
|
||||
Example: You submitted an FP but it was rejected. You now need to open an Archer ticket instead. Complete the FP item, then redirect it to Archer.
|
||||
|
||||
## Creating FP Workflows from the Queue
|
||||
|
||||
1. Open the Queue panel
|
||||
2. Select pending FP items using the checkboxes
|
||||
3. Click "Create FP Workflow" in the footer (only enabled when FP items are selected)
|
||||
4. Fill in the workflow details (name, reason, description, expiration date)
|
||||
5. Attach supporting files (screenshots, evidence)
|
||||
6. Submit — the workflow is created in Ivanti and queue items are marked complete
|
||||
|
||||
See the [FP Submission Editing Guide](kb-fp-submission-editing-guide.md) for details on editing submitted workflows.
|
||||
|
||||
## FP Submissions Section
|
||||
|
||||
Below the queue items, a "Submissions" section shows your previously submitted FP workflows with:
|
||||
- Workflow name and Ivanti batch ID
|
||||
- Lifecycle status badge (Submitted, Rework, Rejected, Resubmitted, Approved)
|
||||
- Finding count and submission date
|
||||
|
||||
Click any submission to open the Edit Modal for viewing details, adding findings, or reading reviewer notes.
|
||||
|
||||
## Tips
|
||||
|
||||
- Group related findings by vendor before adding to the queue — this makes it easier to create batch FP workflows
|
||||
- Use CARD for findings on devices that belong to another team — no vendor entry needed
|
||||
- The queue is per-user — other team members can't see or modify your queue items
|
||||
- Completed items stay in the queue until you clear them, so you have a record of what was processed
|
||||
- Use the redirect feature when a workflow type needs to change after initial processing
|
||||
92
docs/guides/kb-reporting-page-guide.md
Normal file
92
docs/guides/kb-reporting-page-guide.md
Normal file
@@ -0,0 +1,92 @@
|
||||
# Reporting Page Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The Reporting Page is the primary operational page in the STEAM Security Dashboard. It provides a live view of all open Ivanti host findings with filtering, sorting, inline editing, metric charts, and export capabilities.
|
||||
|
||||
## Getting Started
|
||||
|
||||
1. Navigate to the Reporting page from the sidebar
|
||||
2. Click **Sync** (top right) to pull the latest findings from Ivanti
|
||||
3. The sync timestamp updates when complete — findings, charts, and counts all refresh together
|
||||
|
||||
## Metric Charts
|
||||
|
||||
Four donut charts appear at the top of the page:
|
||||
|
||||
### Open vs Closed
|
||||
Shows the total count of open and closed findings across all synced data.
|
||||
|
||||
### Action Coverage
|
||||
Breaks down open findings into three categories:
|
||||
- **FP Request** (blue) — findings with an FP workflow ticket in Ivanti
|
||||
- **Archer Exception** (amber) — findings with an EXC-XXXXX number in their notes
|
||||
- **Pending** (red) — findings with no action taken yet
|
||||
|
||||
Click a chart segment to filter the table to that category. Click again or use "clear filter" to remove.
|
||||
|
||||
### FP Finding Status
|
||||
Shows the distribution of findings across FP workflow states (Requested, Reworked, Actionable, Approved, Rejected, Expired).
|
||||
|
||||
### FP Workflow Status
|
||||
Shows the count of unique FP ticket IDs per state — one FP ticket can cover many findings.
|
||||
|
||||
## Findings Table
|
||||
|
||||
### Columns
|
||||
The table has 13 columns. All are visible by default:
|
||||
|
||||
| Column | Description |
|
||||
|--------|-------------|
|
||||
| Finding ID | Ivanti host finding identifier |
|
||||
| Severity | VRR score with severity group (Critical, High, Medium) |
|
||||
| Title | Vulnerability title |
|
||||
| CVEs | Associated CVE identifiers (hover for tooltip details) |
|
||||
| Host | Hostname (inline editable) |
|
||||
| IP Address | Device IP |
|
||||
| DNS | DNS name (inline editable) |
|
||||
| Due Date | SLA deadline — red if overdue, amber if within 30 days |
|
||||
| SLA | SLA status (Overdue, At Risk, Within SLA) |
|
||||
| BU | Business unit ownership (STEAM or ACCESS-ENG) |
|
||||
| Workflow | FP workflow badge showing ticket ID and state |
|
||||
| Last Found | Date the finding was last detected by scanner |
|
||||
| Notes | Free-text notes field (inline editable) |
|
||||
|
||||
### Column Management
|
||||
Click the **Columns** button (gear icon) to:
|
||||
- Show/hide columns by clicking the eye icon
|
||||
- Drag columns to reorder them
|
||||
- Your column configuration is saved in your browser
|
||||
|
||||
### Sorting
|
||||
Click any sortable column header to sort. Click again to reverse direction. The active sort column is highlighted in blue.
|
||||
|
||||
### Filtering
|
||||
Click the filter icon on any filterable column header to open a dropdown with all unique values. Check/uncheck values to filter. Use "Select All" or "Clear" for bulk operations. A search box lets you find specific values quickly.
|
||||
|
||||
Active filters show as amber badges above the table. Click "Clear Filters" to remove all column filters at once.
|
||||
|
||||
### Inline Editing
|
||||
|
||||
Three columns support inline editing:
|
||||
|
||||
- **Host**: Click the hostname to edit. An amber dot appears when an override is active. Click the revert button (↻) to restore the original Ivanti value. Overrides survive re-syncs.
|
||||
- **DNS**: Same behavior as Host.
|
||||
- **Notes**: Click to type. Saves automatically on blur. Use notes to record EXC numbers (e.g., `EXC-12345`) — the Action Coverage chart will classify these as "Archer Exception".
|
||||
|
||||
## Selecting Findings
|
||||
|
||||
Check the checkbox on any row to select it. Use Shift+Click for range selection. The "select all" checkbox in the header selects all visible (non-queued) findings.
|
||||
|
||||
When findings are selected, a toolbar appears with:
|
||||
- Workflow type toggle (FP / Archer / CARD)
|
||||
- Vendor input field (not needed for CARD)
|
||||
- "Add to Queue" button to stage findings for batch processing
|
||||
|
||||
## Export
|
||||
|
||||
Click the **Export** dropdown to download the current filtered/sorted view as:
|
||||
- **CSV** — comma-separated values with UTF-8 BOM
|
||||
- **Excel (.xlsx)** — formatted spreadsheet with auto-fit column widths
|
||||
|
||||
Only visible columns are included in the export.
|
||||
106
docs/guides/kb-user-management-guide.md
Normal file
106
docs/guides/kb-user-management-guide.md
Normal file
@@ -0,0 +1,106 @@
|
||||
# User Management & Roles Guide
|
||||
|
||||
## Overview
|
||||
|
||||
The STEAM Security Dashboard uses role-based access control with four user groups. Only administrators can manage users. All user operations are logged in the audit trail.
|
||||
|
||||
## User Groups
|
||||
|
||||
| Group | Access Level | Description |
|
||||
|-------|-------------|-------------|
|
||||
| Admin | Full access | All operations including user management, delete, audit log |
|
||||
| Standard_User | Operational access | Create, edit, limited delete (own resources only), exports |
|
||||
| Leadership | Read-only + exports | View all data, download CSV/XLSX exports |
|
||||
| Read_Only | View only | Read-only access to all pages, no modifications |
|
||||
|
||||
## Permission Matrix
|
||||
|
||||
| Action | Admin | Standard_User | Leadership | Read_Only |
|
||||
|--------|-------|---------------|------------|-----------|
|
||||
| View findings/CVEs | Yes | Yes | Yes | Yes |
|
||||
| Sync Ivanti data | Yes | Yes | No | No |
|
||||
| Edit hostname/DNS overrides | Yes | Yes | No | No |
|
||||
| Edit notes | Yes | Yes | No | No |
|
||||
| Add to queue | Yes | Yes | No | No |
|
||||
| Create FP workflows | Yes | Yes | No | No |
|
||||
| Edit FP submissions | Yes | Yes | No | No |
|
||||
| Upload compliance reports | Yes | Yes | No | No |
|
||||
| Add CVEs | Yes | Yes | No | No |
|
||||
| Upload documents | Yes | Yes | No | No |
|
||||
| Export CSV/XLSX | Yes | Yes | Yes | No |
|
||||
| Delete CVEs/documents | Yes | Own only | No | No |
|
||||
| Manage users | Yes | No | No | No |
|
||||
| View audit log | Yes | No | No | No |
|
||||
|
||||
## Managing Users (Admin Only)
|
||||
|
||||
### Accessing User Management
|
||||
1. Click the user icon in the top navigation bar
|
||||
2. Select "User Management" from the menu
|
||||
3. The user list shows all accounts with their group, status, and last login
|
||||
|
||||
### Creating a New User
|
||||
1. Click "Add User"
|
||||
2. Fill in the required fields:
|
||||
- **Username** — must be unique
|
||||
- **Email** — user's email address
|
||||
- **Password** — initial password (user should change on first login)
|
||||
- **Group** — select from Admin, Standard_User, Leadership, or Read_Only
|
||||
3. Click Save
|
||||
|
||||
New users default to Read_Only if no group is specified.
|
||||
|
||||
### Editing a User
|
||||
1. Click the edit icon on the user row
|
||||
2. Modify username, email, or group
|
||||
3. Optionally set a new password (leave blank to keep current)
|
||||
4. Click Save
|
||||
|
||||
### Changing User Groups
|
||||
When changing a user's group, a confirmation dialog appears. Extra warnings are shown when:
|
||||
- Removing Admin privileges from a user
|
||||
- Upgrading a user to Admin
|
||||
|
||||
Group changes are logged separately in the audit trail with the previous and new group recorded.
|
||||
|
||||
### Deactivating Users
|
||||
Users can be deactivated rather than deleted. Deactivated users cannot log in but their data and audit history are preserved.
|
||||
|
||||
## Authentication
|
||||
|
||||
- Sessions use httpOnly cookies with 24-hour expiry
|
||||
- Passwords are hashed with bcryptjs
|
||||
- All API endpoints (except login) require a valid session
|
||||
- Failed login attempts are not rate-limited at the application level
|
||||
|
||||
## Audit Log
|
||||
|
||||
The audit log records all significant actions in the dashboard. Only admins can view it.
|
||||
|
||||
### What's Logged
|
||||
- User creation, updates, group changes, deletion
|
||||
- CVE creation, updates, deletion
|
||||
- Document uploads and deletions
|
||||
- Ivanti sync operations
|
||||
- FP workflow submissions and edits
|
||||
- Queue operations
|
||||
- Compliance uploads
|
||||
- Login/logout events
|
||||
|
||||
### Audit Entry Fields
|
||||
Each entry includes:
|
||||
- Timestamp
|
||||
- User who performed the action
|
||||
- Action type (e.g., user_create, ivanti_fp_workflow_created)
|
||||
- Entity type and ID
|
||||
- Details (JSON with specifics of what changed)
|
||||
- IP address
|
||||
|
||||
## Default Admin Account
|
||||
|
||||
On first setup (`node setup.js`), a default admin account is created:
|
||||
- Username: `admin`
|
||||
- Password: set during setup
|
||||
- Group: `Admin`
|
||||
|
||||
Change the default password immediately after first login.
|
||||
@@ -1,106 +0,0 @@
|
||||
# Ivanti / RiskSense API Reference
|
||||
|
||||
Base URL: `https://platform4.risksense.com/api/v1`
|
||||
Swagger: `https://platform4.risksense.com/doc/swagger.json`
|
||||
|
||||
Auth: `x-api-key` header. Error codes: 401 bad key, 419 insufficient privileges, 429 rate limited.
|
||||
|
||||
## Endpoints Used
|
||||
|
||||
### Search Workflow Batches
|
||||
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/search
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
Standard JSON body with filters, projection, sort, page, size. Used by `ivantiWorkflows.js` for the daily sync.
|
||||
|
||||
### Create False Positive Workflow
|
||||
|
||||
```
|
||||
POST /client/{clientId}/workflowBatch/falsePositive/request
|
||||
Content-Type: multipart/form-data
|
||||
```
|
||||
|
||||
This endpoint does NOT accept JSON. It requires `multipart/form-data` with the following fields:
|
||||
|
||||
| Field | Type | Required | Notes |
|
||||
|-------|------|----------|-------|
|
||||
| `name` | string | yes | Workflow batch name (max 255) |
|
||||
| `reason` | string | yes | Reason for the FP determination |
|
||||
| `description` | string | yes | Description (can be empty string but field must be present) |
|
||||
| `expirationDate` | string | yes | ISO-8601 date, e.g. `2026-06-01` |
|
||||
| `overrideControl` | string | yes | `AUTHORIZED`, `NONE`, or `AUTOMATED`. Use `AUTHORIZED` for standard FP workflows. `NONE` with `isEmptyWorkflow=true` is rejected (400). |
|
||||
| `isEmptyWorkflow` | boolean | yes | `true` if no findings attached, `false` otherwise |
|
||||
| `subjectFilterRequest` | string | yes | Stringified JSON (see format below) |
|
||||
| `files` | file | no | Attachments sent inline in the same request |
|
||||
|
||||
#### subjectFilterRequest format
|
||||
|
||||
This is the critical field. It must be a stringified JSON object with this exact structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"subject": "hostFinding",
|
||||
"filterRequest": {
|
||||
"filters": [
|
||||
{
|
||||
"field": "id",
|
||||
"exclusive": false,
|
||||
"operator": "IN",
|
||||
"value": "2283734550,2283734551"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Key details:
|
||||
- `subject` must be `"hostFinding"` — without this, the API returns 500
|
||||
- `filters` is nested inside `filterRequest`, NOT at the top level — `{"filters":[]}` at the top level returns 500
|
||||
- `value` for multiple IDs is comma-separated as a single string, not an array
|
||||
- `operator` values: `EXACT`, `IN`, `LIKE`, `WILDCARD`, `RANGE`, `CIDR`
|
||||
- For empty workflows, use `{"subject":"hostFinding","filterRequest":{"filters":[]}}` with `isEmptyWorkflow=true`
|
||||
|
||||
#### Response (200/202)
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 33418832,
|
||||
"created": "2026-04-08T18:16:08"
|
||||
}
|
||||
```
|
||||
|
||||
Returns HTTP 200 or 202 (Accepted — async job creation). Response contains a numeric `id` (the workflow batch job ID) and `created` timestamp. No `generatedId` or `uuid` in this response.
|
||||
|
||||
### Other Workflow Endpoints (from Swagger)
|
||||
|
||||
These are available but not currently used by the dashboard:
|
||||
|
||||
| Endpoint | Purpose |
|
||||
|----------|---------|
|
||||
| `/workflowBatch/acceptance/request` | Risk acceptance workflow |
|
||||
| `/workflowBatch/remediation/request` | Remediation workflow |
|
||||
| `/workflowBatch/severityChange/request` | Severity change workflow |
|
||||
| `/workflowBatch/{workflowType}/approve` | Approve a workflow (needs `workflowBatchUuid`) |
|
||||
| `/workflowBatch/{workflowType}/reject` | Reject a workflow |
|
||||
| `/workflowBatch/{workflowType}/rework` | Send back for rework |
|
||||
| `/workflowBatch/{workflowType}/update` | Update a workflow |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/map` | Map findings to workflow |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/unmap` | Unmap findings |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/attach` | Attach file to existing workflow |
|
||||
| `/workflowBatch/{workflowType}/{workflowBatchUuid}/detach` | Detach file |
|
||||
| `/workflowBatch/model` | Get model/schema |
|
||||
| `/workflowBatch/filter` | Get available filter fields |
|
||||
| `/workflowBatch/suggest` | Get suggested values for a filter field |
|
||||
|
||||
## Environment Variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|----------|---------|-------------|
|
||||
| `IVANTI_API_KEY` | — | Required. API key for authentication |
|
||||
| `IVANTI_CLIENT_ID` | `1550` | Client ID in the Ivanti platform |
|
||||
| `IVANTI_SKIP_TLS` | `false` | Set `true` to skip TLS verification |
|
||||
| `IVANTI_FIRST_NAME` | — | Used for workflow search filter (sync) |
|
||||
| `IVANTI_LAST_NAME` | — | Used for workflow search filter (sync) |
|
||||
337
docs/security/security-audit-tracker.md
Normal file
337
docs/security/security-audit-tracker.md
Normal file
@@ -0,0 +1,337 @@
|
||||
# Security Audit Tracker — STEAM Security Dashboard
|
||||
|
||||
**Last scan:** 2026-04-20
|
||||
**Scope:** Full repository — backend routes, middleware, helpers, scripts, frontend components
|
||||
**Baseline:** `docs/security-audit-2026-04-01.md` (31 findings), `docs/security-remediation-plan.md` (17 prioritised items)
|
||||
|
||||
---
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Remediation Status — April 1 Audit](#remediation-status--april-1-audit)
|
||||
- [New Findings — April 20 Scan](#new-findings--april-20-scan)
|
||||
- [Open Finding Summary](#open-finding-summary)
|
||||
- [Positive Security Observations](#positive-security-observations)
|
||||
- [Scan Metadata](#scan-metadata)
|
||||
|
||||
---
|
||||
|
||||
## Remediation Status — April 1 Audit
|
||||
|
||||
Cross-reference of the 31 original findings against the current codebase. Status: **Fixed**, **Partial**, or **Open**.
|
||||
|
||||
### Critical Findings
|
||||
|
||||
| ID | Title | Status | Evidence |
|
||||
|---|---|---|---|
|
||||
| C-1 | Missing auth on Ivanti findings endpoints | **Fixed** | `ivantiFindings.js` — router uses `requireAuth(db)` at router level, `requireGroup` on sync |
|
||||
| C-2 | `requireRole(db)` bypasses role check in KB routes | **Fixed** | `knowledgeBase.js` — uses `requireGroup('Admin', 'Standard_User')` correctly |
|
||||
| C-3 | Unauthenticated finding note writes | **Fixed** | `ivantiFindings.js` — note routes behind `requireAuth(db)` |
|
||||
| C-4 | No brute force protection on login | **Fixed** | `auth.js` — `loginLimiter` (20 attempts / 15 min) applied to POST /login |
|
||||
| C-5 | Default credentials displayed in login UI | **Fixed** | `LoginForm.js` — no hardcoded credentials in the component |
|
||||
| C-6 | Missing sandbox on KB document iframe | **Fixed** | `KnowledgeBaseViewer.js:282` — `sandbox="allow-same-origin"` applied |
|
||||
|
||||
### High Findings
|
||||
|
||||
| ID | Title | Status | Evidence |
|
||||
|---|---|---|---|
|
||||
| H-1 | `/cleanup-sessions` missing role check | **Fixed** | `auth.js` — `requireAuth(db), requireGroup('Admin')` applied |
|
||||
| H-2 | Hardcoded fallback SESSION_SECRET | **Fixed** | `server.js:34-37` — hard-fails with `process.exit(1)` if unset |
|
||||
| H-3 | Audit log parameter mismatch — silent trail gaps | **Partial** | `knowledgeBase.js` — fixed. `archerTickets.js` — `logAudit` calls missing `username` field (see N-1 below) |
|
||||
| H-4 | Viewers can write compliance notes | **Fixed** | `compliance.js` — `requireGroup('Admin', 'Standard_User')` on POST /notes |
|
||||
| H-5 | Sync endpoints accessible to all authenticated users | **Fixed** | Both `ivantiFindings.js` and `ivantiWorkflows.js` — `requireGroup('Admin', 'Standard_User')` on POST /sync |
|
||||
| H-6 | HTTP header injection via Content-Disposition filename | **Fixed** | `knowledgeBase.js` — filename sanitized with `.replace(/["\r\n\\]/g, '')` |
|
||||
| H-7 | Race condition in KB file upload | **Fixed** | `knowledgeBase.js` — file moved after DB insert succeeds |
|
||||
| H-8 | Hardcoded default admin password in setup.js | **Fixed** | `setup.js` — generates random password via `crypto.randomBytes(12)` |
|
||||
| H-9 | ReactMarkdown renders HTML without sanitization | **Fixed** | `KnowledgeBaseViewer.js` — `rehypeSanitize` plugin applied |
|
||||
|
||||
### Medium Findings
|
||||
|
||||
| ID | Title | Status | Evidence |
|
||||
|---|---|---|---|
|
||||
| M-1 | No CSRF token protection | **Open** | Cookies use `SameSite: lax` — no CSRF token implemented |
|
||||
| M-2 | CORS credentials with explicit origin list | **Open** | Acceptable for this deployment model — monitor |
|
||||
| M-3 | No rate limiting on NVD API proxy | **Open** | No server-side cache or per-user rate limit on `/api/nvd/lookup` |
|
||||
| M-4 | Admin self-demotion check uses loose equality | **Fixed** | `users.js` — uses `String(userId) === String(req.user.id)` |
|
||||
| M-5 | Missing hostname format validation | **Fixed** | `compliance.js` POST /notes — regex validation `^[a-zA-Z0-9._-]+$` |
|
||||
| M-6 | Vendor field validated before trim | **Open** | `ivantiTodoQueue.js:8` — `isValidVendor()` checks length before trim |
|
||||
| M-7 | Unsanitized original filename in temp JSON | **Open** | `compliance.js:344` — `req.file.originalname` passed directly |
|
||||
| M-8 | Hardcoded frontend IP in CSP header | **Fixed** | `knowledgeBase.js:302` — reads from `CORS_ORIGINS` env var |
|
||||
| M-9 | API error messages forwarded to UI | **Open** | Frontend still uses `alert(err.message)` in several places |
|
||||
| M-10 | User data in window.confirm dialogs | **Open** | Frontend still uses `window.confirm` with user-supplied data |
|
||||
|
||||
### Low / Info Findings
|
||||
|
||||
| ID | Title | Status | Evidence |
|
||||
|---|---|---|---|
|
||||
| L-1 | Silent ROLLBACK on transaction failure | **Open** | `compliance.js:167` — `.catch(() => {})` still swallows errors |
|
||||
| L-2 | Fire-and-forget audit logging | **Partial** | `auditLog.js` — now logs to `console.error` on failure, but no alerting |
|
||||
| L-3 | Async temp file cleanup with no error handling | **Open** | `compliance.js` — `fs.unlink(path, () => {})` still used |
|
||||
| L-4 | IVANTI_SKIP_TLS with no startup warning | **Open** | No startup warning when `IVANTI_SKIP_TLS=true` |
|
||||
| L-5 | console.error in production frontend | **Open** | No environment guard on console.error calls |
|
||||
| L-6 | localStorage column config lacks structural validation | **Open** | No change observed |
|
||||
|
||||
### Remediation Plan Items (not in original 31)
|
||||
|
||||
| ID | Title | Status | Evidence |
|
||||
|---|---|---|---|
|
||||
| RP-1 | Authenticate /uploads static file access | **Open** | `server.js:127` — `express.static('uploads')` still unauthenticated |
|
||||
| RP-2 | Sanitize Mermaid SVG output with DOMPurify | **Open** | `KnowledgeBaseViewer.js:38` — `innerHTML = svg` without DOMPurify |
|
||||
| RP-3 | Strip server file paths from compliance preview response | **Open** | `compliance.js:342` — full `tempFilePath` returned to client |
|
||||
| RP-4 | Add SESSION_SECRET to .env.example | **Open** | `.env.example` — no `SESSION_SECRET` entry |
|
||||
|
||||
---
|
||||
|
||||
## New Findings — April 20 Scan
|
||||
|
||||
Findings discovered in this scan that were not present in the April 1 audit.
|
||||
|
||||
---
|
||||
|
||||
### N-1 — Archer Ticket Audit Logs Missing `username` Field (Medium)
|
||||
|
||||
**File:** `backend/routes/archerTickets.js:89, 172, 195`
|
||||
|
||||
All three `logAudit` calls in the Archer tickets router omit the `username` field:
|
||||
|
||||
```js
|
||||
logAudit(db, {
|
||||
userId: req.user.id,
|
||||
action: 'CREATE_ARCHER_TICKET',
|
||||
// username: req.user.username ← missing
|
||||
...
|
||||
});
|
||||
```
|
||||
|
||||
The `auditLog.js` helper defaults missing username to `'unknown'`, so all Archer ticket audit entries show `username = 'unknown'` instead of the actual user.
|
||||
|
||||
**Impact:** Audit trail for Archer ticket operations cannot identify which user performed the action. Compliance reviews and incident investigations are degraded.
|
||||
|
||||
**Fix:** Add `username: req.user.username` to all three `logAudit` calls.
|
||||
|
||||
---
|
||||
|
||||
### N-2 — `migrate-to-1.1.js` Contains Hardcoded Admin Password (Medium)
|
||||
|
||||
**File:** `backend/migrate-to-1.1.js:246`
|
||||
|
||||
```js
|
||||
const passwordHash = await bcrypt.hash('admin123', 10);
|
||||
```
|
||||
|
||||
While `setup.js` was fixed to generate random passwords (H-8), the migration script still hardcodes `admin123`. If this migration is run on an existing deployment, it resets the admin password to a known value.
|
||||
|
||||
**Impact:** Running the migration on a production system resets the admin account to a publicly known password.
|
||||
|
||||
**Fix:** Either generate a random password (matching `setup.js` pattern) or skip admin creation if the user already exists.
|
||||
|
||||
---
|
||||
|
||||
### N-3 — Compliance Preview Returns Full Server Filesystem Path (Medium)
|
||||
|
||||
**File:** `backend/routes/compliance.js:342`
|
||||
|
||||
```js
|
||||
tempFile: tempFilePath,
|
||||
```
|
||||
|
||||
The preview endpoint returns the full server-side path (e.g. `/home/cve-dashboard/backend/uploads/temp/compliance_preview_...json`) to the frontend. The commit endpoint then receives this path back and reads the file. This exposes the server's directory structure to any authenticated user.
|
||||
|
||||
**Impact:** Information disclosure — authenticated users learn the server's absolute filesystem layout, which aids further exploitation.
|
||||
|
||||
**Fix:** Return only the filename. Reconstruct the full path server-side in the commit handler:
|
||||
```js
|
||||
tempFile: tempFilename, // just the basename
|
||||
// In commit handler:
|
||||
const tempFile = path.join(TEMP_DIR, path.basename(req.body.tempFile));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### N-4 — `/uploads` Static Directory Served Without Authentication (High)
|
||||
|
||||
**File:** `backend/server.js:127`
|
||||
|
||||
```js
|
||||
app.use('/uploads', express.static('uploads', {
|
||||
dotfiles: 'deny',
|
||||
index: false
|
||||
}));
|
||||
```
|
||||
|
||||
All uploaded files (CVE documents, compliance data, knowledge base articles) are served as static files without any authentication check. Anyone who knows or guesses a file URL can access sensitive vulnerability documentation, compliance reports, and internal knowledge base content.
|
||||
|
||||
**Impact:** Unauthenticated access to all uploaded documents. File paths are predictable (CVE ID + vendor + timestamp-filename pattern).
|
||||
|
||||
**Fix:** Replace with an authenticated route handler:
|
||||
```js
|
||||
app.use('/uploads', requireAuth(db), express.static('uploads', { ... }));
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### N-5 — Mermaid SVG Rendered via `innerHTML` Without Sanitization (Medium)
|
||||
|
||||
**File:** `frontend/src/components/KnowledgeBaseViewer.js:38`
|
||||
|
||||
```js
|
||||
ref.current.innerHTML = svg;
|
||||
```
|
||||
|
||||
Mermaid-generated SVG is injected directly into the DOM via `innerHTML`. While Mermaid itself sanitizes most input, a crafted diagram definition in a knowledge base article could potentially produce SVG with embedded event handlers or script elements.
|
||||
|
||||
**Impact:** Stored XSS vector if Mermaid's internal sanitization is bypassed. Any user viewing the article would execute the payload.
|
||||
|
||||
**Fix:** Sanitize the SVG string before injection:
|
||||
```js
|
||||
import DOMPurify from 'dompurify';
|
||||
ref.current.innerHTML = DOMPurify.sanitize(svg, { USE_PROFILES: { svg: true } });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### N-6 — `SESSION_SECRET` Not Documented in `.env.example` (Low)
|
||||
|
||||
**File:** `backend/.env.example`
|
||||
|
||||
The `SESSION_SECRET` environment variable is required for the server to start (hard-fail added per H-2 fix), but it is not listed in `.env.example`. Fresh deployments will fail with no guidance on what to set.
|
||||
|
||||
**Fix:** Add to `.env.example`:
|
||||
```
|
||||
# Session signing secret — generate with: openssl rand -hex 32
|
||||
SESSION_SECRET=
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### N-7 — `requireGroup` Error Response Leaks Current User Group (Low)
|
||||
|
||||
**File:** `backend/middleware/auth.js:55-60`
|
||||
|
||||
```js
|
||||
return res.status(403).json({
|
||||
error: 'Insufficient permissions',
|
||||
required: allowedGroups,
|
||||
current: req.user.group
|
||||
});
|
||||
```
|
||||
|
||||
The 403 response includes both the required groups and the user's current group. This is minor information disclosure — an attacker probing endpoints learns the exact group membership of the compromised account and which groups are needed.
|
||||
|
||||
**Fix:** Remove `required` and `current` from the response:
|
||||
```js
|
||||
return res.status(403).json({ error: 'Insufficient permissions' });
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### N-8 — No Content-Security-Policy Header on Main Application (Medium)
|
||||
|
||||
**File:** `backend/server.js:107-113`
|
||||
|
||||
Security headers include `X-Content-Type-Options`, `X-Frame-Options`, `X-XSS-Protection`, `Referrer-Policy`, and `Permissions-Policy`, but no `Content-Security-Policy` header. CSP is the primary browser-side defense against XSS.
|
||||
|
||||
**Impact:** No browser-enforced restriction on script sources. If an XSS vulnerability exists (e.g. N-5), there is no CSP to mitigate it.
|
||||
|
||||
**Fix:** Add a baseline CSP header:
|
||||
```js
|
||||
res.setHeader('Content-Security-Policy',
|
||||
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; " +
|
||||
"img-src 'self' data:; font-src 'self'; connect-src 'self'");
|
||||
```
|
||||
Start with `Content-Security-Policy-Report-Only` to avoid breaking existing functionality.
|
||||
|
||||
---
|
||||
|
||||
### N-9 — Expired Sessions Not Cleaned Up Automatically (Low)
|
||||
|
||||
**File:** `backend/server.js`, `backend/routes/auth.js`
|
||||
|
||||
The `sessions` table has no automatic cleanup. Expired sessions accumulate indefinitely. The `/cleanup-sessions` endpoint exists but must be triggered manually by an admin.
|
||||
|
||||
**Impact:** Performance degradation over time as the sessions table grows. Not directly exploitable, but expired session rows increase the surface for timing attacks on session lookups.
|
||||
|
||||
**Fix:** Add a cleanup interval on server startup:
|
||||
```js
|
||||
setInterval(() => {
|
||||
db.run("DELETE FROM sessions WHERE expires_at < datetime('now')");
|
||||
}, 6 * 60 * 60 * 1000); // every 6 hours
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Open Finding Summary
|
||||
|
||||
Prioritised list of all open findings requiring action.
|
||||
|
||||
### High Priority
|
||||
|
||||
| ID | Severity | Title | Source |
|
||||
|---|---|---|---|
|
||||
| N-4 | High | `/uploads` static directory served without authentication | New |
|
||||
|
||||
### Medium Priority
|
||||
|
||||
| ID | Severity | Title | Source |
|
||||
|---|---|---|---|
|
||||
| M-1 | Medium | No CSRF token protection | April 1 |
|
||||
| M-3 | Medium | No rate limiting on NVD API proxy | April 1 |
|
||||
| N-1 | Medium | Archer ticket audit logs missing `username` field | New |
|
||||
| N-2 | Medium | `migrate-to-1.1.js` contains hardcoded admin password | New |
|
||||
| N-3 | Medium | Compliance preview returns full server filesystem path | New |
|
||||
| N-5 | Medium | Mermaid SVG rendered via `innerHTML` without sanitization | New |
|
||||
| N-8 | Medium | No Content-Security-Policy header on main application | New |
|
||||
| M-6 | Medium | Vendor field validated before trim | April 1 |
|
||||
| M-7 | Medium | Unsanitized original filename in temp JSON | April 1 |
|
||||
| M-9 | Medium | API error messages forwarded to UI | April 1 |
|
||||
| M-10 | Medium | User data in `window.confirm` dialogs | April 1 |
|
||||
|
||||
### Low Priority
|
||||
|
||||
| ID | Severity | Title | Source |
|
||||
|---|---|---|---|
|
||||
| N-6 | Low | `SESSION_SECRET` not documented in `.env.example` | New |
|
||||
| N-7 | Low | `requireGroup` error response leaks current user group | New |
|
||||
| N-9 | Low | Expired sessions not cleaned up automatically | New |
|
||||
| L-1 | Low | Silent ROLLBACK on transaction failure | April 1 |
|
||||
| L-3 | Low | Async temp file cleanup with no error handling | April 1 |
|
||||
| L-4 | Low | IVANTI_SKIP_TLS with no startup warning | April 1 |
|
||||
| L-5 | Low | console.error in production frontend | April 1 |
|
||||
| L-6 | Low | localStorage column config lacks structural validation | April 1 |
|
||||
|
||||
---
|
||||
|
||||
## Positive Security Observations
|
||||
|
||||
Verified secure patterns that should be preserved:
|
||||
|
||||
- **SQL injection prevention** — all queries use parameterized statements throughout the entire codebase
|
||||
- **Path traversal prevention** — `sanitizePathSegment()` and `isPathWithinUploads()` consistently applied in `server.js`, `compliance.js`, and `knowledgeBase.js`
|
||||
- **Python script execution** — `spawn('python3', [SCRIPT, filePath])` with argument arrays — no shell injection
|
||||
- **File upload security** — extension allowlist + MIME prefix validation + 10 MB size limit via multer
|
||||
- **Password hashing** — bcrypt with cost factor 10 used for all password storage
|
||||
- **Session management** — 32-byte random session IDs via `crypto.randomBytes`, httpOnly cookies, 24h expiry
|
||||
- **Rate limiting** — login endpoint protected with 20 attempts per 15-minute window
|
||||
- **Audit trail** — comprehensive audit logging on all state-changing operations (with noted exceptions above)
|
||||
- **Self-modification prevention** — admin cannot demote or deactivate their own account
|
||||
- **Ownership-scoped deletion** — Standard_User can only delete resources they created
|
||||
- **Compliance linkage protection** — deletion blocked when tickets are linked to active compliance reports
|
||||
- **Temp file path validation** — `isSafeTempPath()` enforces `.json` extension and `uploads/temp/` directory
|
||||
- **Static file serving** — `dotfiles: 'deny'` and `index: false` prevent directory listing
|
||||
|
||||
---
|
||||
|
||||
## Scan Metadata
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| Scan date | 2026-04-20 |
|
||||
| Scan type | Full repository static analysis |
|
||||
| Scope | `backend/`, `frontend/src/`, config files |
|
||||
| Baseline | `docs/security-audit-2026-04-01.md` |
|
||||
| Previous findings | 31 (6 Critical, 9 High, 10 Medium, 6 Low/Info) |
|
||||
| Remediated | 20 fully fixed, 2 partially fixed |
|
||||
| Still open (from baseline) | 13 |
|
||||
| New findings | 9 |
|
||||
| Total open | 22 (1 High, 11 Medium, 10 Low) |
|
||||
| Methodology | Static analysis — code review of all route handlers, middleware, helpers, and frontend components |
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user