Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apex] ApexSOQLInjection does not recognise SObjectType or SObjectField as safe variable types #4646

Closed
m0rjc opened this issue Aug 16, 2023 · 6 comments · Fixed by #4649
Closed
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@m0rjc
Copy link

m0rjc commented Aug 16, 2023

Rule: ApexSOQLInjection

Could this also add SObjectType and SObjectField as safe types?

This contrived code example demonstrates the issue.

    public static Set<String> getDistinctValues(SObjectType type, SObjectField field, Set<Id> ids) {
        List<SObject> records = Database.query('SELECT ' + field + ' FROM ' + type + ' WHERE Id In :ids');
        Set<String> values = new Set<String>();
        for(SObject record : records) {
            values.add((String) record.get(field));
        }
        return values;
    }
@m0rjc
Copy link
Author

m0rjc commented Aug 16, 2023

If this is a quick fix I'll have a go, though I've not tried locally building and running PMD. I'll clone the repository and have a look.

@m0rjc
Copy link
Author

m0rjc commented Aug 16, 2023

@all-contributors please add @rcorfieldffdc for code
@all-contributors please add @m0rjc for code,bug

I'm struggling to get the merge in a mergeable state. I think my local build environment is upset, as it's started failing on files I've not touched and can't (should not!!) depend on the one file I have touched. I have a branch in a local fork. It looks like I can create a work in progress pull request so it is attached.

@m0rjc
Copy link
Author

m0rjc commented Aug 16, 2023

https://github.com/all-contributors please add @m0rjc for code,bug

Looks like I can only have one command in a comment, sorry.

@m0rjc
Copy link
Author

m0rjc commented Aug 16, 2023

@all-contributors please add @m0rjc for code

@allcontributors
Copy link
Contributor

@m0rjc

@m0rjc already contributed before to code

@allcontributors
Copy link
Contributor

@m0rjc

I've put up a pull request to add @rcorfieldffdc! 🎉

I've put up a pull request to add @m0rjc! 🎉

@adangel adangel changed the title APEX SoqlInjection does not recognise SObjectType or SObjectField as safe variable types [apex] SoqlInjection does not recognise SObjectType or SObjectField as safe variable types Sep 9, 2023
@adangel adangel changed the title [apex] SoqlInjection does not recognise SObjectType or SObjectField as safe variable types [apex] ApexSOQLInjection does not recognise SObjectType or SObjectField as safe variable types Sep 9, 2023
@adangel adangel added the a:false-positive PMD flags a piece of code that is not problematic label Sep 9, 2023
@adangel adangel added this to the 7.0.0 milestone Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants