-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Add query for missing function level access control #13094
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
C#: Add query for missing function level access control #13094
Conversation
5aed1c9
to
12bb418
Compare
Documentation is still in progress, but the technical work is ready for reveiw. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This already looks really good!
I have added some minor comments/recommendations and suggestions.
There primary concern is probably about the use of .calls*(..)
.
Have you tried running the query on some large projects?
csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/WebFormsTests/options
Outdated
Show resolved
Hide resolved
...tests/Security Features/CWE-285/MissingAccessControl/WebFormsTests/Test1/ViewProfile.aspx.cs
Show resolved
Hide resolved
...tests/Security Features/CWE-285/MissingAccessControl/WebFormsTests/Test1/ViewProfile.aspx.cs
Show resolved
Hide resolved
...tests/Security Features/CWE-285/MissingAccessControl/WebFormsTests/Test2/EditProfile.aspx.cs
Show resolved
Hide resolved
csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll
Outdated
Show resolved
Hide resolved
csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll
Outdated
Show resolved
Hide resolved
csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll
Outdated
Show resolved
Hide resolved
csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll
Show resolved
Hide resolved
predicate hasAuthViaCode(ActionMethod m) { | ||
m.needsAuth() and | ||
exists(Callable caller, AuthExpr auth | | ||
m.getAnAuthorizingCallable().calls*(caller) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this cause performance issues (the reflexive and transitive closure of this could be huge)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DCA run looks ok; besides a couple failures that look unrelated to this query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright - that sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hvitved: Do you have any concerns about using the reflexive, transitive closure of calls
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If DCA is happy, then I'm happy :-)
csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll
Show resolved
Hide resolved
It is probably a good idea to run this query against the DCA nightly suite. |
QHelp previews: csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelpMissing function level access controlSensitive actions, such as editing or deleting content, or accessing admin pages, should have authorization checks to ensure that they cannot be used by malicious actors. RecommendationEnsure that proper authorization checks are made for sensitive actions. For WebForms applications, the ExampleIn the following WebForms example, the case marked BAD has no authorization checks whereas the case marked GOOD uses class ProfilePage : System.Web.UI.Page {
// BAD: No authorization is used
protected void btn1_Edit_Click(object sender, EventArgs e) {
...
}
// GOOD: `User.IsInRole` checks the current user's role.
protected void btn2_Delete_Click(object sender, EventArgs e) {
if (!User.IsInRole("admin")) {
return;
}
...
}
} The following
In the following MVC example, the case marked BAD has no authorization checks whereas the case marked GOOD uses the public class ProfileController : Controller {
// BAD: No authorization is used.
public ActionResult Edit(int id) {
...
}
// GOOD: The `Authorize` attribute is used.
[Authorize]
public ActionResult Delete(int id) {
...
}
} References
|
Co-authored-by: Michael Nebel <michaelnebel@github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Joe!!! :-)
Looks good to me!
Great; just need the docs review then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I found two small issues.
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
I'll review this for Docs! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joefarebrother 👋🏻 - I wasn't able to see a preview of the ql file, with the examples in-situ. Have things changed, do you know how to get to the preview?
I reviewed this from an editorial point of view, and left a few comments and suggestions for your consideration. Feel free to ignore the ones you don't agree with 😃
(The punctuation is needed in the list in the References section. )
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Security Features/CWE-285/MissingAccessControl.qhelp
Outdated
Show resolved
Hide resolved
Thanks @mchammer01 - I've applied those suggestions. |
@joefarebrother - thanks for pointing me to the preview ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adds query for missing authorization checks.
Finds WebForms methods (
System.Web.UI.Page
) and MVC actions whose names indicate that they should have authorization checs (e.g.Delete
orAdmin
), but such checks could not be found; including through code, attributes, orWeb.config
xml files.