[1.x] feat(phpstan): report misaligned extender callback parameters - #5050
Open
DavideIadeluca wants to merge 1 commit into
Open
[1.x] feat(phpstan): report misaligned extender callback parameters#5050DavideIadeluca wants to merge 1 commit into
DavideIadeluca wants to merge 1 commit into
Conversation
novacuum
approved these changes
Sep 9, 2026
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.
Fixes #0000
It's too easy to register an
ApiSerializercallback with a misaligned signature. Take the following proof of concept:The above code passes static code analysis but it serializes raw model data to API responses which means that it introduces a major security vulnerability.
Changes proposed in this pull request:
Implement a new custom PHPStan rule which checks the signature of select extender callbacks. It reports:
Reviewers should focus on:
The new rule doesn't catch absolutely all possible cases how this can be done wrong, but it provides a great deal of protection against silly unintended mistakes. I thought long if there are genuine cases this rule is undesired, however I didn't find any. Extension Developers can still use the phpstan ignore directive to work around this issue if an implementation somehow genuinely needs to do something which doesn't pass this rule.
For Flarum 2 we should consider if we want to narrow down the runtime logic to fail loudly in such scenarios where applicable. Some mitigations on this were already done if I recall correctly, like using $hidden to hide model data from being serialized to begin with. Let me know what you would like to see for Flarum 2 here.
Screenshot
Necessity
Confirmed
yarn testinjs/).composer test).Required changes: