Skip to content

feat(security-posture): implement Security Posture Scoring System (#153)#161

Open
iyanumajekodunmi756 wants to merge 1 commit into
MD-Creative-Production:mainfrom
iyanumajekodunmi756:feat/security-posture-scoring-system
Open

feat(security-posture): implement Security Posture Scoring System (#153)#161
iyanumajekodunmi756 wants to merge 1 commit into
MD-Creative-Production:mainfrom
iyanumajekodunmi756:feat/security-posture-scoring-system

Conversation

@iyanumajekodunmi756

Copy link
Copy Markdown

Summary

Implements the Security Posture Scoring System as specified in issue #153.

Changes

New module: src/modules/security-posture/

File Description
interfaces/security-posture.interface.ts ScoringFactor, PostureSnapshot, SecurityPostureResult types
security-posture.service.ts Weighted scoring engine, history tracking, grade + trend logic
security-posture.controller.ts GET /security-posture and GET /security-posture/history endpoints
security-posture.module.ts NestJS module declaration
security-posture.service.spec.ts 13 unit tests

Modified

  • apps/backend/src/app.module.ts — registers SecurityPostureModule

Acceptance Criteria

  • Scores calculatedSecurityPostureService.getPosture() computes a weighted 0–100 score from 5 factors
  • Trends availabletrend field returns improving | stable | degrading based on last two snapshots; GET /security-posture/history returns full history
  • Results displayedGET /security-posture returns score, grade (A–F), weighted factors, history, and trend

Scoring Model

Five weighted factors (weights sum to 1.0):

Factor Weight
unresolvedCriticalAlerts 35%
mempoolThreatDensity 25%
watchlistCoverage 20%
notificationReliability 10%
auditLogCompleteness 10%

History is capped at 30 snapshots, seeded with 7 days of synthetic data on first boot.

Tests

PASS apps/backend/src/modules/security-posture/security-posture.service.spec.ts
  SecurityPostureService
    ✓ should be defined
    getPosture
      ✓ returns a score between 0 and 100
      ✓ returns a valid grade
      ✓ returns a valid ISO timestamp in calculatedAt
      ✓ returns factors with weights that sum to 1.0
      ✓ each factor has a valid weighted score equal to value * weight
      ✓ returns a non-empty history array
      ✓ returns a valid trend value
      ✓ grade A corresponds to score >= 90
      ✓ history length does not exceed 30 snapshots
    getHistory
      ✓ returns an array of snapshots
      ✓ each snapshot has a numeric score and ISO timestamp
      ✓ returns a copy — mutations do not affect internal state

Tests: 13 passed, 13 total

Full backend suite: 22/22 passed. Lint and format checks: clean.

Closes #153

- Add SecurityPostureResult, ScoringFactor, PostureSnapshot interfaces
- Implement SecurityPostureService with weighted scoring model (5 factors),
  historical snapshot tracking (capped at 30 entries), grade computation
  (A-F), and trend detection (improving/stable/degrading)
- Expose GET /security-posture and GET /security-posture/history endpoints
  via SecurityPostureController
- Register SecurityPostureModule in AppModule
- Add 13 unit tests covering score bounds, grade mapping, factor weights,
  history immutability, and trend logic

Closes MD-Creative-Production#153
@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @iyanumajekodunmi756 , thanks for your contributions, please kindly fix the remaining ci failures, please due ensure the all ci passed successfully. Well done for this effort you have put in so far.

@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @iyanumajekodunmi756 thank you for fixing some of the errors, please resolve conflict, pull from main and update your branch, fix typescript error and commit again. Well done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🛡️ Create Security Posture Scoring System

2 participants