Prevent mass assignment in onboarding

fix(security): prevent mass assignment in onboarding (#6171)
Prevent mass assignment in onboardinga05a16-fix-prevent-mass-assignment-in-onboarding-cve-2026-50160fixprevent mass assignment onboarding security

Committed by nahidhasan94

commit message
fix(security): prevent mass assignment in onboarding (#6171)

* fix(backend): prevent mass assignment in onboarding config endpoint
 
The unauthenticated POST /v1/onboarding/config endpoint mapped the
request body directly to InfraConfigEnum keys, allowing an attacker on
a fresh install to inject sensitive values such as JWT_SECRET and
SESSION_SECRET, enabling forged admin JWTs and full takeover.
 
Four independent weaknesses combined to make this exploit possible.
This commit addresses each in layers so the fix holds even if any
single layer regresses:
 
- main.ts: enable `whitelist: true` on the global ValidationPipe so
  properties not declared on any DTO are stripped before reaching any
  controller / service. This is the primary mitigation described in
  the advisory.
 
- onboarding.controller.ts: scope an additional ValidationPipe
  (`whitelist` + `forbidNonWhitelisted`) on the onboarding POST body
  so requests containing unknown fields are explicitly rejected with
  400 instead of silently dropped.
 
- infra-config.service.ts (updateOnboardingConfig): introduce an
  `ONBOARDING_ALLOWED_KEYS` allowlist so any `InfraConfigEnum` key
  not part of the documented onboarding surface (OAuth, SMTP) is
  dropped server-side before being persisted, even if earlier layers
  regress.
 
- infra-config.service.ts (validateEnvValues): explicitly reject
  `JWT_SECRET`, `SESSION_SECRET` and `ALLOW_SECURE_COOKIES` so these
  keys can never be written through any infra-config code path,
  replacing the prior `default: break` behaviour that silently
  accepted them.
 
Fixes GHSA-j542-4rch-8hwf
 
* fix(backend): harden onboarding config validation and add sensitive infra-config tests
 
* chore: cleanup
 
* chore: class validator implemented in dto layer
 
* fix: arguments
 
* fix: api feedback
 
---------
 
Co-authored-by: “mirarifhasan” <[email protected]>

Editor assessment

This commit patches CVE-2026-50160. The body is outstanding: it explains that the unauthenticated onboarding endpoint mapped request bodies onto InfraConfigEnum keys, letting an attacker inject JWT_SECRET and SESSION_SECRET, then documents four layered defenses with file-level specifics and notes that the fix should survive any single regression. The subject clearly names mass assignment and the onboarding area, and the PR reference is tidy. Two things hold it back: security is a category label rather than a codebase scope, and the advisory reference sits inside a bullet as Fixes GHSA-j542-4rch-8hwf instead of a proper footer line. The squash-merge history at the end is also mostly noise. The prose is excellent, but the framing limits it.

Browse categories

More fix examples · Back to search