fix(aluno): reject invalid CPF before querying student search - #1198
Open
Silenttttttt wants to merge 2 commits into
Open
fix(aluno): reject invalid CPF before querying student search#1198Silenttttttt wants to merge 2 commits into
Silenttttttt wants to merge 2 commits into
Conversation
educar_aluno_lst.php stripped the CPF field down to digits with
preg_replace('/\D/', ...) and passed that straight into
LegacyStudentBuilder::whereCpf(), an exact where('cpf', $cpf) match,
without ever checking the checksum.
cadastro.fisica.cpf has no unique constraint, and a CPF-less student is
commonly stored with a placeholder value such as 00000000000. Because
that placeholder is itself an invalid CPF, an invalid/mistyped CPF
search can coincidentally equal it and match every student sharing that
placeholder, returning multiple students for a single invalid CPF
lookup.
Portabilis_Utils_Validation::validatesCpf() already implements the
checksum check and is used for this exact purpose during registration
(PessoaController::validateCpf(), atendidos_cad.php). This applies the
same validation to the search filter: an invalid CPF now short-circuits
to zero results instead of reaching the query.
Fixes portabilis#1058
Gerar()'s cognitive complexity grew past this project's SonarCloud threshold (15) after the CPF-validation branch was added in the previous commit. Extracting the search resolution (valid CPF vs. empty result set) and the per-student row-building into their own private methods removes that branching and nesting from Gerar() without changing any behavior — same queries, same output, same early-return-on-invalid-CPF logic, just moved into searchStudents() and studentRow().
|
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.



Summary
Fixes #1058.
ieducar/intranet/educar_aluno_lst.php(the student search form) strips the CPF field down to digits withpreg_replace('/\D/', '', ...)and passes that value straight intoLegacyStudentBuilder::whereCpf(), which does an exactwhere('cpf', $cpf)match. The checksum is never validated.cadastro.fisica.cpfhas no unique constraint. A student without a real CPF on file is commonly stored with a placeholder value such as00000000000. Since that placeholder is itself an invalid CPF, typing in an invalid/mistyped CPF can coincidentally match that placeholder and return every student who shares it — matching the reported behavior of an invalid CPF returning multiple students instead of zero.Portabilis_Utils_Validation::validatesCpf()already implements the CPF checksum validation and is used for this exact purpose elsewhere in the codebase during registration (PessoaController::validateCpf(),atendidos_cad.php), but it was never applied to this search filter.Fix
Validate the CPF with
Portabilis_Utils_Validation::validatesCpf()before it reaches the query. When a non-empty CPF fails validation, the search short-circuits to an empty result set (via an emptyLengthAwarePaginator) instead of running the query, so an invalid CPF can never match student records — regardless of what happens to be stored as a placeholder value.Notes
whereCpf()already does an exact match (where('cpf', $cpf)), not aLIKE, so partial digit entry never matched multiple students in the first place — it simply matched nothing (or, in the buggy case, happened to match a shared invalid placeholder).pesquisa_pessoa_lst.php(a sibling person-search screen) already validates the CPF checksum before querying and shows an explicit "Informado um CPF Inválido" message otherwise, so gating the query on CPF validity is an established pattern in this codebase, not a new behavior being introduced here.validaCPF()andPortabilis_Utils_Validation::validatesCpf()) reject the placeholder value00000000000(and other repeated-digit placeholders), consistent with the root cause above.