{"record":{"id":"d5ab76a30ec51c10","repo":"lcobucci/jwt","slug":"no-constraint-given","errorCode":null,"errorMessage":"No constraint given.","messagePattern":"No constraint given\\.","errorType":"exception","errorClass":"Lcobucci\\JWT\\Validation\\NoConstraintsGiven","httpStatus":null,"severity":"error","filePath":"src/Validation/Validator.php","lineNumber":13,"sourceCode":"<?php\ndeclare(strict_types=1);\n\nnamespace Lcobucci\\JWT\\Validation;\n\nuse Lcobucci\\JWT\\Token;\n\nfinal readonly class Validator implements \\Lcobucci\\JWT\\Validator\n{\n    public function assert(Token $token, Constraint ...$constraints): void\n    {\n        if ($constraints === []) {\n            throw new NoConstraintsGiven('No constraint given.');\n        }\n\n        $violations = [];\n\n        foreach ($constraints as $constraint) {\n            $this->checkConstraint($constraint, $token, $violations);\n        }\n\n        if ($violations !== []) {\n            throw RequiredConstraintsViolated::fromViolations(...$violations);\n        }\n    }\n\n    /** @param ConstraintViolation[] $violations */\n    private function checkConstraint(\n        Constraint $constraint,\n        Token $token,\n        array &$violations,","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/lcobucci/jwt/blob/375813049c24c7111bda8b6884c57b071ceb2fe7/src/Validation/Validator.php#L1-L31","documentation":"Lcobucci\\JWT\\Validation\\Validator::assert() requires at least one Constraint. When called with an empty variadic constraint list it immediately throws NoConstraintsGiven('No constraint given.') instead of silently succeeding (which would falsely mean 'token is valid'). This is a guard against meaningless validation calls.","triggerScenarios":"Calling $validator->assert($token) with no Constraint arguments — e.g. building the constraint list in a loop that produced zero constraints, or forwarding an empty array via ...$constraints.","commonSituations":"Dynamically assembling constraints from configuration where all constraints were disabled or the config section was missing/empty; refactoring that dropped the constraints argument; conditional code paths that skip adding any constraint.","solutions":["Check the constraint list with count($constraints) > 0 (or !== []) before calling assert() and skip validation or fail fast in your own code.","Fix the constraint-assembly logic so at least the constraints your policy requires (e.g. SignedWith, IdentifiedBy) are always added.","If empty means 'nothing to validate', restructure to call assert() only when constraints exist."],"exampleFix":"// before\n$validator->assert($token, ...$this->constraintsFromConfig());\n// after\n$constraints = $this->constraintsFromConfig();\nif ($constraints === []) {\n    throw new \\LogicException('No validation constraints configured');\n}\n$validator->assert($token, ...$constraints);","handlingStrategy":"validation","validationCode":"if ($constraints === []) {\n    throw new \\LogicException('Refusing to validate token: no constraints configured');\n}","typeGuard":"function hasConstraints(Lcobucci\\JWT\\Validation\\Constraint ...$constraints): bool\n{\n    return $constraints !== [];\n}","tryCatchPattern":"try {\n    $validator->assert($token, ...$constraints);\n} catch (Lcobucci\\JWT\\Validation\\NoConstraintsGiven $e) {\n    // configuration bug: log and reject the request\n    throw new \\RuntimeException('JWT validation misconfigured: no constraints', 0, $e);\n}","preventionTips":["Always include mandatory constraints (e.g. SignedWith) outside of optional/config-driven lists.","Assert the constraint array is non-empty in the layer that assembles it, with a test for the empty-config case.","Treat NoConstraintsGiven as a deployment/configuration error, never as 'token is valid'."],"tags":["jwt","validation","constraints"],"backgroundTag":"missing-required-argument","analyzedSha":"375813049c24c7111bda8b6884c57b071ceb2fe7","analyzedAt":"2026-09-14T11:12:28.004Z","contentChangedAt":"2026-09-14T11:12:28.004Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}