fix(admin): restrict search fields to digits and max 9 digits - #1074
Merged
Conversation
Enforce digits-only input with max length of 9 and leading zero stripping via DigitsOnlyDirective on FOM Number and FSP ID admin search fields. Add parameter bounds validation on the backend API to prevent PostgreSQL integer overflow. Closes #666
DerekRoberts
requested review from
OlgaLiber2 and
arcshiftsolutions
as code owners
August 22, 2026 02:57
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents oversized admin search IDs from causing database integer-overflow errors.
Changes:
- Restricts FOM/FSP inputs to nine digits.
- Sanitizes restored search parameters.
- Adds backend 32-bit integer validation and tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
api/src/app/modules/project/project.controller.ts |
Validates positive integer query parameters. |
api/src/app/modules/project/project.controller.spec.ts |
Tests invalid integer boundaries. |
api/src/app/modules/external/projects-by-fsp/projects-by-fsp.controller.ts |
Adds an upper bound to FSP validation. |
admin/src/core/directives/digits-only.directive.ts |
Implements digit-only input handling. |
admin/src/core/directives/digits-only.directive.spec.ts |
Tests directive behavior. |
admin/src/app/search/search.component.ts |
Sanitizes search criteria and URL parameters. |
admin/src/app/search/search.component.spec.ts |
Tests deep-link sanitization and clearing. |
admin/src/app/search/search.component.html |
Applies digit restrictions to search inputs. |
Suppressed comments (1)
admin/src/core/directives/digits-only.directive.ts:112
- The paste handler replaces the entire field instead of the selected range, and
preventDefault()suppresses the browser's nativeinputevent. Since the search fields use[(ngModel)], callingcontrol.setValue()does not update the boundfNumber/fFspIdproperty, so a pasted ID can be visible while the search still submits the previous value. Merge the pasted text at the current selection and dispatch aninputevent after assigning the sanitized value.
const sanitized = pastedText.replace(/\D/g, '').replace(/^0+/, '').slice(0, maxLen);
const inputEl = this.el.nativeElement;
inputEl.value = sanitized;
if (this.ngControl?.control) {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue where entering more than 9 digits into the admin search fields (
FOM NumberandFSP ID) caused an internal server error.Changes
DigitsOnlyDirective([appDigitsOnly]) for input fields to restrict keystrokes to numbers only, enforce a maximum length of 9 digits, and strip leading zeros on paste and input events.<input type="number">,min, and inlineoninputhandlers inSearchComponenttemplate withtype="text",maxlength="9", andappDigitsOnly, resolving CSP blocking issues in higher environments.SearchComponentto safely handle invalid or out-of-range values.1to2,147,483,647) for integer query parameters (projectId,fspId,districtId) inProjectControllerandPositiveIntPipeto prevent PostgreSQL 32-bit integer overflow exceptions.DigitsOnlyDirectivecovering keyboard interaction, input truncation, paste handling, and leading zero removal.SearchComponentdeep link sanitization andProjectControllerinteger boundary validation.Closes #666
Thanks for the PR!
Deployments, as required, will be available below:
Please create PRs in draft mode. Mark as ready to enable:
After merge, new images are deployed in: