X Tutup
The Wayback Machine - https://web.archive.org/web/20260303130059/https://github.com/github/codeql/pull/5108
Skip to content

Java: detect use of deprecated Azure Active Directory Authentication Library#5108

Closed
phenggeler wants to merge 2 commits intogithub:mainfrom
phenggeler:use-of-deprecated-adal
Closed

Java: detect use of deprecated Azure Active Directory Authentication Library#5108
phenggeler wants to merge 2 commits intogithub:mainfrom
phenggeler:use-of-deprecated-adal

Conversation

@phenggeler
Copy link

@phenggeler phenggeler commented Feb 7, 2021

This CodeQL detects the dependence upon Azure Active Directory Authentication Library (ADAL). This library was deprecated by Microsoft in June 2020, and Microsoft suggests projects move to the supported Microsoft Authentication Library (MSAL).

https://techcommunity.microsoft.com/t5/azure-active-directory-identity/update-your-applications-to-use-microsoft-authentication-library/ba-p/1257363

Example of this query run against various Microsoft projects:

https://lgtm.com/query/7515233935542346311/

@phenggeler phenggeler requested a review from a team as a code owner February 7, 2021 17:33
@smowton smowton changed the title first commit Java: detect use of deprecated Azure Active Directory Authentication Library Feb 8, 2021
@smowton
Copy link
Contributor

smowton commented Feb 8, 2021

Let's definitely not have a query for every single deprecated library -- I suggest restructuring this to something like UseOfInsecureDependency.ql, where we can list libraries that have been marked do-not-use by their maintainers for security reasons, or perhaps those that are abandoned and have known security problems.

It's fine for it to only diagnose use of this one library for now, but e.g. the qhelp should be expressed in general terms, and doesn't need to give particular code examples.

@smowton
Copy link
Contributor

smowton commented Feb 8, 2021

Two other notes:

  • In the warning message, note that this isn't totally dead right now, rather security updates are slated to finish in June 2022
  • By making the query only select one example use-site per library (probably flagging an import statement not a ClassInstanceExpr), we can avoid excessive noise and produce one warning per insecure library per project. You could achieve this by first finding the names of insecure libraries that are imported (i.e., some predicate that returns string) such that imports of the same library are treated alike, then write a get-an-example-import predicate for the final select, which could rank them by their source filename / line number and select just the first one.

@smowton smowton self-assigned this Feb 8, 2021
@phenggeler
Copy link
Author

  • By making the query only select one example use-site per library (probably flagging an import statement not a ClassInstanceExpr), we can avoid excessive noise and produce one warning per insecure library per project. You could achieve this by first finding the names of insecure libraries that are imported (i.e., some predicate that returns string) such that imports of the same library are treated alike, then write a get-an-example-import predicate for the final select, which could rank them by their source filename / line number and select just the first one.

Hi @smowton - thanks for your review. I agree with your assessment. I noticed you assigned this to yourself - are you OK if I start implementing your suggested changes? Was there any other review you wanted to make?

@smowton
Copy link
Contributor

smowton commented Feb 9, 2021

No that's it, please go ahead. My assignment is intended to represent my responsibility as reviewer

@phenggeler
Copy link
Author

This CodeQL looks for a pre-defined list of deprecated Java classes being imported into a project. Currently, the scope is limited to a few, but could be expanded to include this complete list:

https://docs.oracle.com/javase/9/docs/api/deprecated-list.html#class

Example of this query run against various Microsoft and Apache projects:

https://lgtm.com/query/6342354165661913612/


predicate usesInsecureDependency(Import i) {
i.toString().splitAt(" ", 1) in [ "com.microsoft.aad.adal4j.*",
"AuthenticationContext",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this looking for particular class names? Can we just look for any import matching "com.microsoft.aad.adal4j.%"?

* @kind problem
* @problem.severity error
* @precision high
* @id java/microsoft/using-insecure-dependency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @id java/microsoft/using-insecure-dependency
* @id java/using-deprecated-dependency

@@ -0,0 +1,23 @@
/**
* @name Using Insecure Dependency
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @name Using Insecure Dependency
* @name Using Deprecated Dependency

}

from Import imp
where imp = max(Import i | usesInsecureDependency(i) | i order by i.getFile().toString())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only give one alert even if they used two different deprecated packages. How about writing a predicate that takes the max Import per dependency, so that if I have imports

import deprecated1.SomeClass1
import deprecated2.SomeClass2
import deprecated1.SomeOtherClass1
import deprecated2.SomeOtherClass2
import deprecated1.SomeOtherClass1

Then I should get two alerts: use of dependency deprecated1, use of dependency deprecated2.

@smowton
Copy link
Contributor

smowton commented Feb 15, 2021

Also regarding your list of deprecated classes, note we already have a query for use of deprecated classes or methods. This query should be restricted to deprecated libraries / packages that don't carry the @Deprecated annotation, because there is no good in-band mechanism for signalling a whole library/package shouldn't be used except adding @Deprecated to every single class / method, and sometimes maintainers don't do this.

@smowton
Copy link
Contributor

smowton commented Mar 4, 2021

@phenggeler please tag me when this is ready for re-review

@smowton
Copy link
Contributor

smowton commented Apr 14, 2021

@phenggeler do you intend to keep working on this?

@phenggeler phenggeler closed this Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup