Patent Description:
The present invention relates generally to protecting against security vulnerabilities in computer programs, and particularly to methods, apparatus and software for evaluating application security.

Various techniques are known in the art for testing and protecting software applications against security vulnerabilities. A "vulnerability" in this context is a flaw or weakness in the application program that can be exploited by an unauthorized party (also referred to as an attacker) to gain access to secure information or otherwise modify the behavior of the program. For example, static application security testing (SAST) techniques are typically applied in order to detect security vulnerabilities in source code before the code is compiled and run.

Methods for finding vulnerabilities using SAST are described, for example, in <CIT>. This patent describes a tool that automatically analyzes source code for application-level vulnerabilities. Operation of the tool is based on static analysis, but it makes use of a variety of techniques, for example methods of dealing with obfuscated code.

The Common Vulnerabilities and Exposures (CVE) system provides a database of known vulnerabilities in publicly-available software packages. The Mitre Corporation maintains the system with funding from the United States Department of Homeland Security. The system assigns a CVE Identifier (also known as a CVE number) to serve as a unique, common identifier for each vulnerability that is reported to it.

Embodiments of the present invention that are described hereinbelow provide improved methods, apparatus and software for detection of vulnerabilities in software code.

There is therefore provided, in accordance with an embodiment of the invention, a method for software code analysis, which includes receiving, into a memory of a computer, source code of an application program, which includes one or more calls from respective entry points in the source code to at least one library program. The source code is automatically analyzed in the computer in order to generate a first data flow graph (DFG), representing a flow of data to be engendered upon running the application program. One or more vulnerabilities are identified in the at least one library program. The at least one library program is automatically analyzed to generate at least one second DFG linking at least one of the entry points in the source code to at least one of the vulnerabilities. The first DFG is combined with the at least one second DFG in order to track the flow of data from the application program to the at least one of the vulnerabilities. It is reported, responsively to the tracked flow, that the at least one of the vulnerabilities is exploitable. In a disclosed embodiment, identifying the one or more vulnerabilities includes looking up the at least one library program in a database of known vulnerabilities. Additionally or alternatively, the one or more calls from the respective entry points in the source code include invocations of methods in an application program interface (API) of the at least one library program. Further additionally or alternatively, the method includes identifying at least one of the library calls by detecting an unresolved method in the source code.

In some embodiments, identifying the one or more vulnerabilities includes identifying a parameter in the at least one library program, and wherein automatically analyzing the at least one library program includes finding a data flow path from the at least one of the entry points to the vulnerable parameter in the at least one library program. In a disclosed embodiment, combining the first DFG with the at least one second DFG includes tracking the flow of data through the first DFG and the at least one second DFG to the vulnerable parameter, and the at least one of the vulnerabilities is reported to be exploitable when the tracked flow links an input of the application program to the vulnerable parameter. Additionally or alternatively, the at least one of the vulnerabilities is reported as not being exploitable when the tracked flow indicates that the one or more calls from the application program to the at least one library program are not accessible via a data flow from inputs of the application program.

In one embodiment, the at least one library program includes a first library program, which includes a call to a second library program, and identifying the one or more vulnerabilities includes identifying a vulnerability in the second library program, and automatically analyzing the at least one library program includes generating the at least one second DFG so as to track the flow of data through the first library program to the vulnerability in the second library program.

There is also provided, in accordance with an embodiment of the invention, apparatus for software code analysis, including a memory configured to receive source code of an application program, which includes one or more calls from respective entry points in the source code to at least one library program. A processor is configured to automatically analyze the source code in the computer in order to generate a first data flow graph (DFG), representing a flow of data to be engendered upon running the application program, to identify one or more vulnerabilities in the at least one library program, to automatically analyze the at least one library program to generate at least one second DFG linking at least one of the entry points in the source code to at least one of the vulnerabilities, to combine the first DFG with the at least one second DFG in order to track the flow of data from the application program to the at least one of the vulnerabilities, and to report, responsively to the tracked flow, that the at least one of the vulnerabilities is exploitable.

There is additionally provided, in accordance with an embodiment of the invention, a computer software product, including a non-transitory computer-readable medium in which program instructions are stored, which instructions, when read by a computer, cause the computer to receive source code of an application program, which includes one or more calls from respective entry points in the source code to at least one library program, to automatically analyze the source code in the computer in order to generate a first data flow graph (DFG), representing a flow of data to be engendered upon running the application program, to identify one or more vulnerabilities in the at least one library program, to automatically analyze the at least one library program to generate at least one second DFG linking at least one of the entry points in the source code to at least one of the vulnerabilities, to combine the first DFG with the at least one second DFG in order to track the flow of data from the application program to the at least one of the vulnerabilities, and to report, responsively to the tracked flow, that the at least one of the vulnerabilities is exploitable.

Software developers make frequent use of libraries of software code written by others in order to save time and effort in application program development. Third-party open-source libraries, such as the extensive libraries available on public platforms such as GitHub®, are particularly attractive to software developers, as they offer ready-made solutions to common problems encountered in programming. Third-party library programs, however, often have vulnerabilities, which can be exploited in mounting attacks on application programs that call the library programs.

Conscientious software developers may check for known vulnerabilities in library programs that they use, for example by looking them up in the CVE system mentioned above. This sort of checking is burdensome, however, and also tends to give a large number of false positive results, i.e., warnings of potential security flaws where in fact none exist. Specifically, a vulnerability in a library program will generally be exploitable, i.e., accessible to an attacker, only if the application program has an input that is linked through the program data flow to a vulnerable parameter in the library program. An attacker who discovers this link may then be able to trigger the vulnerability in the library program by setting the input of the application program to an appropriate value. If the application program does not contain such a link -for example because it calls the vulnerable method only with a constant parameter - the vulnerability will still exist, but it will not be exploitable.

There is thus a need for software analysis tools that are able to distinguish between exploitable and non-exploitable vulnerabilities in library programs used in an application under test, in order to alert software developers to actual security risks while minimizing false positive results. Such a tool can enable developers to focus their efforts where they are required and to avoid wasting time on vulnerabilities that are not exploitable. Embodiments of the present invention that are described herein address this need by providing software composition analysis tools that are capable of efficiently analyzing library programs together with the application program that calls them, and thus assessing which vulnerabilities of the library programs are exploitable and which are not.

In the disclosed embodiments, a computer receives into its memory source code of an application program, which includes one or more calls from respective entry points in the source code to one or more library programs. (These entry points typically correspond, for example, to invocations of methods in an application program interface (API) of the library program in question. ) The computer automatically analyzes the source code in order to generate a data flow graph (DFG), which represents the flow of data engendered upon running the application program. This DFG typically represents only the application code, and not the library programs that it calls.

The computer also identifies one or more vulnerabilities in the library program or programs called by the application program, for example by looking up the library programs in a vulnerability database. It analyzes the library programs to generate DFGs linking the entry points from the application source code to the locations of the vulnerabilities that were identified in the library programs. These DFGs typically represent only the library code, and not the application program. The library DFGs may be computed on demand or, alternatively or additionally, they may be precomputed and stored in memory, for example in a database, for use when needed.

The computer then combines the DFG of the application program with the DFGs of the library programs in order to track the flow of data from the application program to the vulnerabilities in the library programs. Specifically, in the embodiments described below, the DFG of a given library program may identify a data flow path from an entry point (such as an API call) in the application source code to a vulnerable parameter in the library program. The computer tracks the flow of data through the DFGs of both the application program and the library program to the vulnerable parameter. The computer will report that a given vulnerability is exploitable when the tracked flow is found to link an input of the application program through the library program to the vulnerable parameter. Otherwise, when the tracked flow indicates that the relevant calls from the application program to the library program are not accessible through inputs of the application program (in the sense that there is no data flow from the inputs of the application program to the library program), the computer will report that the vulnerability is not exploitable and thus does not pose a security threat.

It commonly occurs that a first library program, which is called by an application program, will itself call a second library program. Thus, a vulnerability in the second library program may put the application program at risk. To deal with this sort of chained relationship (referred to herein as a "transient dependency"), the computer generates respective DFGs of both the first and second library programs. It uses both of these DFGs, together with the DFG of the application program, in order to track the flow of data from the application program through the library programs to the vulnerability in the second library program, and thus determines whether the vulnerability is exploitable.

<FIG> is a block diagram that schematically illustrates a system <NUM> for detection of vulnerabilities in software code of an application program, in accordance with an embodiment of the invention. The software code in the pictured example is stored on an application server <NUM>, such as a suitable Web server, and runs on either or both of server <NUM> and client computers <NUM>, which connect to server <NUM> via a network <NUM>, such as the Internet. The application software includes calls to library programs, which may be stored and accessed on a library server <NUM>.

Prior to deployment of the application program, a verification server <NUM> checks the application source code for security flaws. Server <NUM> comprises a memory <NUM>, which receives and stores the source code of the application program, as well as of library programs, which are called from respective entry points in the application source code. Server <NUM> also comprises a processor <NUM>, typically embodied in a general-purpose or special-purpose computer, which is programmed in software to carry out the functions that are described herein. The software may be downloaded to server <NUM> in electronic form, over a network, for example. Additionally or alternatively, the software may be provided and/or stored on tangible, non-transitory computer-readable media, such as magnetic, optical, or electronic memory. Memory <NUM> also holds the software that is run by processor <NUM> in performing the functions that are described herein.

As a part of its functionality in checking and reporting on security flaws in an application program, processor <NUM> identifies vulnerabilities in the library programs called by the application program. For this purpose, processor <NUM> typically looks up the library programs in a listing of vulnerabilities, which may be compiled as a vulnerability database <NUM>, which may be based on the above-mentioned CVE database. Database <NUM> may be stored in memory <NUM> or, additionally or alternatively, the database may be accessed on a remote server (not shown) via network <NUM>. Further additionally or alternatively, processor <NUM> may perform an independent analysis of relevant library programs in order to discover and record their vulnerabilities in memory <NUM>.

In the present embodiment, for each known vulnerability, database <NUM> identifies the vulnerable method name and metadata, as well as vulnerable parameters in the method. These particular parameters are "vulnerable" in the sense that by manipulating the values of such parameters, an attacker can exploit a corresponding vulnerability in the software package. In other words, the parameters of a vulnerable method become "vulnerable parameters" by virtue of their usage in the method.

By way of example, the following is a record maintained in database <NUM> for CVE-<NUM>-<NUM> - a vulnerability in a Python library called pyOpenSSL:.

The "CVSS number" listed above is a score between <NUM> and <NUM> indicating the relative severity of the vulnerability.

Server <NUM> applies various static application security testing (SAST) techniques in order to detect security vulnerabilities in the application source code. These functions are described in detail in the above-mentioned <CIT>, and a full description is beyond the scope of the present patent application, which relates specifically, as explained above, to the problem of analyzing vulnerabilities that arise from the use of library programs.

For this latter purpose, server <NUM> applies the techniques of data flow graph (DFG) construction that are described specifically in columns <NUM>-<NUM> of <CIT> and illustrated in Figs. <NUM>-<NUM>. To summarize briefly, processor <NUM> derives an object-based representation, known as a document object model (DOM), of the software source code under analysis (such as the application code or the relevant library code). The processor uses the DOM to extract flow graphs of the code. These flow graphs typically include the data flow graph (DFG), which represents a flow of data that will be engendered when the code is run, and they may also include a control flow graph (CFG) and a control dependence graph (CDG). Processor <NUM> stores the analysis results in memory <NUM>, for example in the form of a database to enable convenient access to the data thereafter.

<FIG> is a flow chart that schematically illustrates a method for detection of vulnerabilities in a software application program, in accordance with an embodiment of the invention. The method is described, for the sake of clarity and concreteness, with reference to the elements of system <NUM>, and particularly verification server <NUM>. Alternatively, the method can be carried out in other suitable hardware configurations, on a dedicated verification server or on any other suitable computer.

To initiate the method, server <NUM> receives source code of an application program under test into memory <NUM>, at a code reception step <NUM>. The code includes one or more calls from respective entry points in the source code to at least one library program. Processor <NUM> applies the source code analysis techniques described above in building a DFG of the application program, at an application DFG generation step <NUM>.

In addition, processor <NUM> identifies library calls in the application source code, at a call identification step <NUM>. The library calls are the entry points from the application to the library programs and typically (although not necessarily) can be identified as invocations of methods in an API of a library program. (In identifying and analyzing the library calls, processor <NUM> may use data concerning libraries and their versions stored in a packages or manifest file, for example, although other data sources and logic may alternatively be used. ) A given application program can include multiple library calls, which may be directed to the same library program or to multiple different library programs. Furthermore, at step <NUM>, server <NUM> may retrieve and analyze the source code of the libraries called by the application program, in order to identify and analyze calls from these library programs to other library programs (creating "transient dependencies," as defined above).

Alternatively or additionally, processor <NUM> may identify library calls at step <NUM> by detecting "unresolved methods," i.e., methods that do not have a declaration in application source code. Such methods can be detected, for example, by generating and querying a model of the application code using a suitable SAST tool. If a method has no declaration in the application source code, it can be inferred that the declaration is in a library, and the relevant libraries can then be searched based on the methods imported to the application.

Processor <NUM> identifies vulnerabilities in the library programs found at step <NUM>, for example by lookup in database <NUM>, at a vulnerability identification step <NUM>. For each library, the processor collects known vulnerabilities from the database, including details such as metadata of vulnerable methods in the library (including the method name, params, containing class, and relative path in the library) and the vulnerable parameter or parameters in each vulnerable method. For example, the following data can be collected and saved per vulnerability:.

For each vulnerability found at step <NUM>, processor <NUM> analyzes the corresponding library program in order to build a DFG of the library program, at a library DFG generation step <NUM>. Alternatively or additionally, the processor may retrieve a pre-computed DFG, for example, from memory <NUM>. In general, each such DFG links one of the entry points found at step <NUM> in the application source code to a vulnerability in a library program. In the case of transient dependencies, however, the DFG will track the flow of data from an entry point in one library program that calls a second library program to a vulnerable parameter in the second library program.

Processor <NUM> combines the DFG of the application program built at step <NUM> with the DFGs of vulnerable library programs built at step <NUM>, in order to track the flow of data from the application program to the vulnerable parameters in the library programs, at a DFG combination step <NUM>. Based on the combined DFG, processor <NUM> decides whether the vulnerability in the library program is exploitable, at an exploitability evaluation step <NUM>.

Generally speaking, when the data flow tracked through the combined DFGs is found to link an input of the application program to a vulnerable parameter in a library program, processor <NUM> will identify the vulnerability of the library program as exploitable and will initiate a protective action, at a protection step <NUM>. For example, if a user input to the application program is tracked to the queue of a vulnerable library program, which has an inner thread for handling the elements in the queue, the combined DFG will identify the vulnerability as exploitable. The protective action taken at step <NUM> typically comprises issuance of a report that an exploitable vulnerability has been found. Alternatively or additionally, step <NUM> may involve more proactive protection, such as halting compilation of the application program until the vulnerability is resolved, or inserting a routine to "sanitize" the problematic input before it reaches the vulnerable library program.

Alternatively, when the tracked flow indicates at step <NUM> that a given vulnerability found at step <NUM> is not exploitable, the method will terminate at a completion step <NUM>. (Server <NUM> may still report the vulnerability that was found, but will indicate that it presents little or no risk, since it is not exploitable in the existing application configuration. ) Specifically, when analysis of the DFGs indicates that the vulnerability in a certain library program is not accessible through any input of the application program that calls the library program (meaning, as noted above, that there is no data flow from the inputs of the application program to the vulnerability), the vulnerability will be considered non-exploitable. This sort of finding will arise, for example, when the application program calls the library program with a constant or other parameter that is not affected by the inputs to the application program.

In the following example, an application program calls Library A, which is a library for writing a REST web server. Library A calls Library B to handle HTTP requests. Hence, there is a transient dependency from the application code to Library B. Meanwhile, Library B is known to be vulnerable to an attack via a crafted HTTP request, making Library A, and thus the application program, vulnerable to this sort of attack, as well. By tracing an HTTP request using the DFGs, server <NUM> constructs the exploitable path from the application program to the vulnerable parameter in Library B, as illustrated below.

<FIG> is a combined DFG representing the path from a user input to the vulnerability in Library B, in accordance with an embodiment of the invention. In this example, the application code imports the class RestApiHandler from Library A, which in turn imports the class HttpHandler from Library B. The combined DFG is built across application code, Library A and Library B. The application code receives user input via the getNextPacketRawData() method. Since the data flow reaches the vulnerable method and its vulnerable parameter in Library B, server <NUM> will report that the vulnerability is exploitable.

Claim 1:
A method for software code analysis, comprising:
receiving, into a memory (<NUM>) of a computer (<NUM>), source code of an application program, which includes one or more calls from respective entry points in the source code to at least one library program;
automatically analyzing the source code in the computer in order to generate a first data flow graph (DFG), representing a flow of data to be engendered upon running the application program;
identifying one or more vulnerabilities in the at least one library program;
automatically analyzing the at least one library program to generate at least one second DFG linking at least one of the entry points in the source code to at least one of the vulnerabilities;
combining the first DFG with the at least one second DFG in order to track the flow of data from the application program to the at least one of the vulnerabilities; and
reporting, responsively to the tracked flow, that the at least one of the vulnerabilities is exploitable.