Skip to content

fix(backend): accept only plain integers in route params and DTOs - #4342

Merged
pYassine merged 6 commits into
masterfrom
fix/strict-int-params
Oct 27, 2026
Merged

pYassine merged 6 commits into
masterfrom
fix/strict-int-params

Conversation

@pYassine

@pYassine pYassine commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4341.

Problem

The global ValidationPipe (transform: true) converts numeric params with +value before any param pipe runs. @Param("x", new ParseIntPipe()) x: number therefore accepted "0x10" (→ 16), "1e3" (→ 1000), "007". Same for @Type(() => Number) / Number(value) in DTOs.

Changes

  • parseStrictInt(value, { min, max }): digits only, no sign, no leading zero, no exponent / hex / decimal, then bounds

  • @IntParam({ name, min, max }): custom param decorator reading the raw param (replaces ParseIntPipe on userId ×2 and procuration index)

  • UsagerRefParam / EtapeDemandeParam and the usager guards use the same parser

  • @StrictIntTransform() / toStrictInt for DTOs: "3" → 3, anything else left raw so @IsInt / @Min / @Max reject it. Replaces @Type(() => Number) (pagination, Brevo, suspicious-activity, sessions-stats) and Number(value) (newReferrerId, reset-password userId, activeUsersCount, Metabase year)

  • MetabaseStatsDto.structureId: @IsNumberString → @IsInt + @Min(1), now a real number

  • userId (rdv) and referrerId (search, create-usager): @IsNumber → @StrictIntTransform + @IsInt + @Min(1)

  • contact-support form data (userId, structureId): cleanFormDataValue uses parseStrictInt instead of Number()

  • Reset password form (frontend, portail-admins, portail-stats): drop the unused parseInt(userId); the raw route value is sent and userId is typed string in the service

Rejected: 3X3, 1e3, 0x10, 007, -1, 1.5, " 1", "".

To check

  • Metabase embed now receives structureId as a number instead of a string (structure stats screen in portail-admins)

The global ValidationPipe converts numeric params with `+value` before any
param pipe runs, so ParseIntPipe let "0x10", "1e3" or "007" through.

- parseStrictInt + IntParam decorator read the raw param (digits only, no
  leading zero, min / max bounds); usagerRef and etapeDemande use it
- StrictIntTransform for DTOs: converts "3" to 3, leaves anything else raw
  so @ISINT rejects it; replaces @type(() => Number) and Number(value)
- MetabaseStatsDto.structureId is now a validated integer

@iterion-forge-domifa iterion-forge-domifa Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revi — aucun problème détecté dans le périmètre revu.

À confirmer

  • Is the Metabase dashboard's structureid parameter defined as a numeric filter so the signed value now sent as a number (previously a string) still matches — if it is text-typed, the structure filter on the structure stats screen could silently stop applying?
  • USAGER_REF_MAX = 100_000 is a silent hard cap on the usagerRef param: refs are per-structure sequential from 1, but if any structure ever crossed 100k its records would become API-unreachable (400) — is that bound confirmed safe for all production structures?
Détails du run IA · Iterion

Run : 01a17d43-53c5-74a1-978c-12a13cf00f2a

Tokens du run au moment de publier : 112 799.

Périmètre revu : correctness: packages/backend/src/_common/decorators/parse-pipes/ParseStrictInt.pipe.ts (regex, bounds, IntParam) ; correctness: packages/backend/src/_common/decorators/parse-pipes/ParseUsagerRef.pipe.ts, ParseEtapeDemande.pipe.ts ; correctness: packages/backend/src/_common/decorators/transformers/StrictIntDecorator.ts (toStrictInt passthrough semantics) ; security: packages/backend/src/auth/guards/usager-access.guard.ts, usager-note-access.guard.ts (strict parse, throw paths, log-level change) ; correctness: usagers controllers (usagers, usager-docs, usager-notes, usager-options, usagers-decision) — param decorator swaps, next-step bounds moved into EtapeDemandeParam ; correctness: interactions.controller.ts, portail-usagers-manager.controller.ts, users-supervisor/users.public controllers (IntParam on userId, procuration index) ; data: DTOs — page-options, brevo-email-events, sessions-stats, suspicious-activity, MetabaseStats, structure-registration (activeUsersCount IsNumber→IsInt), reset-password, new-referrer-id, update-role, assign-referrers (transform + @ISINT pairing) ; integration (surrounding code): metabase-embed.helper.ts + check-territories.ts consumption of now-numeric structureId; usagersCreator.service.ts ref generation (min 1, sequential); remaining :usagerRef routes without the decorator (agenda, usager-structure-docs, enable-access, patch/delete) verified guard-covered; global ValidationPipe config (app.bootstrap.ts, transform:true, implicitConversion:false); ParseIntPipe leftovers (none); frontend padStart on refs (none) ; tests: parse-usager-ref-pipe.spec.ts, parse-etape-demande-pipe.spec.ts accept/reject matrices; usagers.controller.security-tests.ts 999999→99999

Revue mono (single model family).

Étape Modèle Harness Effort demandé Tokens
Revue GLM glm-5.3 claude_code max 78 857
Synthèse · GLM glm-5.3 claude_code medium 33 942

Tokens cumulés des appels IA, pas la taille du contexte. L’effort indiqué est le réglage demandé au modèle.

@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 77.08333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.27%. Comparing base (17c3b08) to head (1f2fb16).
⚠️ Report is 1 commits behind head on fix/usagers-search-partial-results.

Files with missing lines Patch % Lines
...usagers/controllers/usagers-decision.controller.ts 33.33% 4 Missing ⚠️
...ontrollers/national-stats/metabase-embed.helper.ts 0.00% 3 Missing ⚠️
...ckages/backend/src/util/functions/cleanFormData.ts 25.00% 3 Missing ⚠️
...ponents/reset-password/reset-password.component.ts 0.00% 3 Missing ⚠️
...c/usagers/controllers/usager-options.controller.ts 33.33% 2 Missing ⚠️
...mmon/decorators/parse-pipes/ParseStrictInt.pipe.ts 92.85% 1 Missing ⚠️
...mmon/decorators/parse-pipes/ParseUsagerRef.pipe.ts 90.90% 1 Missing ⚠️
...ackend/src/auth/guards/usager-note-access.guard.ts 75.00% 1 Missing ⚠️
...ckend/src/modules/users/dto/new-referrer-id.dto.ts 50.00% 1 Missing ⚠️
...s/backend/src/modules/users/dto/update-role.dto.ts 50.00% 1 Missing ⚠️
... and 2 more
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files

Impacted file tree graph

@@                          Coverage Diff                           @@
##           fix/usagers-search-partial-results    #4342      +/-   ##
======================================================================
+ Coverage                               64.18%   64.27%   +0.08%     
======================================================================
  Files                                    1076     1080       +4     
  Lines                                   22856    22899      +43     
  Branches                                 4534     4566      +32     
======================================================================
+ Hits                                    14670    14718      +48     
- Misses                                   7891     8100     +209     
+ Partials                                  295       81     -214     
Files with missing lines Coverage Δ
...n/decorators/parse-pipes/ParseEtapeDemande.pipe.ts 100.00% <100.00%> (ø)
...ackend/src/_common/decorators/parse-pipes/index.ts 100.00% <100.00%> (ø)
...mmon/decorators/transformers/StrictIntDecorator.ts 100.00% <100.00%> (ø)
...ckend/src/_common/decorators/transformers/index.ts 100.00% <100.00%> (ø)
...ges/backend/src/auth/guards/usager-access.guard.ts 91.30% <100.00%> (+0.39%) ⬆️
...rc/modules/interactions/interactions.controller.ts 90.24% <100.00%> (+0.24%) ⬆️
...src/modules/portail-admin/dto/MetabaseStats.dto.ts 100.00% <100.00%> (+10.00%) ⬆️
.../portail-admin/dto/brevo-email-events-query.dto.ts 100.00% <100.00%> (+27.27%) ⬆️
...rc/modules/portail-admin/dto/sessions-stats.dto.ts 100.00% <100.00%> (+16.66%) ⬆️
...portail-admin/dto/suspicious-activity-query.dto.ts 68.18% <100.00%> (+4.54%) ⬆️
... and 25 more

... and 80 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17c3b08...1f2fb16. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

Base automatically changed from fix/usagers-search-partial-results to master October 27, 2026 21:35
@pYassine
pYassine merged commit ae353b6 into master Oct 27, 2026
13 of 18 checks passed
@pYassine
pYassine deleted the fix/strict-int-params branch October 27, 2026 21:36
@tokenbureau

tokenbureau Bot commented Oct 27, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.288.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@tokenbureau tokenbureau Bot added the released label Oct 27, 2026

This branch is waiting to be deployed

1 waiting deployment
build-review — 1f2fb16d Waiting Oct 27, 2026 by pYassine via build-portail-stats #11407
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants