Start experiment with 'literal-string' type#873
Merged
gabordemooij merged 1 commit intogabordemooij:masterfrom Oct 23, 2021
Merged
Start experiment with 'literal-string' type#873gabordemooij merged 1 commit intogabordemooij:masterfrom
gabordemooij merged 1 commit intogabordemooij:masterfrom
Conversation
Contributor
Author
|
Thanks Gabor :-) |
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.
Hi Gabor,
Following on from our emails in April, looking at these kinds of mistakes:
While the is_literal() RFC didn't pass (I'll try again next year, once I've addressed the concerns people had), a very similar check has now been added to Psalm 4.8 and PHPStan 0.12.97 via the
literal-stringtype.This allows RedBeanPHP to note that certain method parameters expect a string created by the developer (defined in the source code, not containing unsafe user data), so mistakes that lead to Injection Vulnerabilities can be identified by anyone using Psalm (level 3 or stricter) or PHPStan (level 7 or stricter)... this will typically help teams who use these tools to identify mistakes from junior developers making "quick edits".
As I don't want to create issues for the users of RedBeanPHP, I'd like to start with the
$sqlparameter inR::find()(all this PR does)... this will allow us to see if we get any feedback (I'm happy to help with that), and if it goes well, I can update the other methods.I appreciate this isn't as good as being able to conditionally apply this check (e.g. with the "novice" mode), and it only works for those using static analysis, but it works, and it's just as forgiving as the original RFC - in that it works with variables, and allows string concatenation (assuming both are
literal-stringvalues), so things like conditional where clauses are still fine, e.g.