Is there a way to better my LDAP filter security

Here is what is happening. I'm passing a value into a directorySearcher filter and it works great, but HP Fortify is complaining that the input is from an untrusted source.

It recommended that I validate it with a RegEx expression, but HP fortify is still not liking the input.  Is there a such thing as a parameterized LDAP value that I can pass, like I do with Oracle queries?

Here is the snippet...


string whitelist = "[_a-zA-Z0-9]{1,30}$";
                Regex pattern = new Regex(whitelist);
                  
                        
                        if (pattern.IsMatch(value))
                {
                              var directorySearcher = new DirectorySearcher();
                    directorySearcher.PropertiesToLoad.Add("orclnetdescstring");
                    directorySearcher.SearchRoot = directoryEntry;
                    directorySearcher.SearchScope = SearchScope.Subtree;                    
                    directorySearcher.Filter = "(&(objectclass=orclNetService)(cn=" + value + "))";
                    searchResult = directorySearcher.FindOne();
                }
silentthread2kSenior Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LearnctxEngineerCommented:
Well, your regex is not the best as you're only matching the end of the string (unless that was your goal).

string whitelist = "[_a-zA-Z0-9]{1,30}$";

Open in new window


This will match a string that ends with between 1 and 30 characters in the class [_a-zA-Z0-9]. This will also match crazy things like.

@#?@#!@#.a

You want to specify a start string character.

string whitelist = "^[_a-zA-Z0-9]{1,30}$";

Open in new window


I don't otherwise know anything about the Fortify product.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
LDAP

From novice to tech pro — start learning today.