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

Analyzer to warn against using Exception.Message in an exception filter #140

Open
yaakov-h opened this issue Mar 9, 2021 · 3 comments
Open

Comments

@yaakov-h
Copy link
Member

yaakov-h commented Mar 9, 2021

e.g. catch (Exception ex) when (ex.Message.Contains("some English string"))

@brian-reichle
Copy link
Contributor

I would suggest that the issue here isn't so much that Exception.Message is used in a filter, but that a decision is being made based on it. Using ex.Message.Contains(...) should probably be considered just as bad if it had appeared in the body of the catch block or in some other method.

@yaakov-h
Copy link
Member Author

Agreed, but I thought that may be trickier.

Should we perhaps blacklist certain string methods or extension methods when called on Exception.Message?

@brian-reichle
Copy link
Contributor

brian-reichle commented Mar 10, 2021

I would suggest blacklisting any string method that returns a bool or int and possibly any regex method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants