Skip to content

Commit ff58041

Browse files
authored
Merge pull request #20733 from asgerf/js/incremental-api-graphs
JS: Incremental API graph
2 parents e430aa9 + da9aafc commit ff58041

File tree

32 files changed

+1292
-896
lines changed

32 files changed

+1292
-896
lines changed

javascript/ql/lib/semmle/javascript/ApiGraphs.qll

Lines changed: 1003 additions & 659 deletions
Large diffs are not rendered by default.

javascript/ql/lib/semmle/javascript/DOM.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ module DOM {
192192
* A data flow node or other program element that may refer to
193193
* a DOM element.
194194
*/
195+
overlay[global]
195196
abstract class Element extends Locatable {
196197
ElementDefinition defn;
197198

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ES2015Module extends Module {
2929
override string getName() { result = this.getFile().getStem() }
3030

3131
/** Gets an export declaration in this module. */
32+
pragma[nomagic]
3233
ExportDeclaration getAnExport() { result.getTopLevel() = this }
3334

3435
overlay[global]
@@ -38,6 +39,7 @@ class ES2015Module extends Module {
3839

3940
/** Holds if this module exports variable `v` under the name `name`. */
4041
overlay[global]
42+
pragma[nomagic]
4143
predicate exportsAs(LexicalName v, string name) { this.getAnExport().exportsAs(v, name) }
4244

4345
override predicate isStrict() {
@@ -345,6 +347,7 @@ abstract class ExportDeclaration extends Stmt, @export_declaration {
345347

346348
/** Holds if this export declaration exports variable `v` under the name `name`. */
347349
overlay[global]
350+
pragma[nomagic]
348351
final predicate exportsAs(LexicalName v, string name) {
349352
this.exportsDirectlyAs(v, name)
350353
or
@@ -821,18 +824,31 @@ class SelectiveReExportDeclaration extends ReExportDeclaration, ExportNamedDecla
821824
result = ExportNamedDeclaration.super.getImportedPath()
822825
}
823826

827+
overlay[global]
828+
pragma[nomagic]
829+
private predicate reExportsFrom(ES2015Module mod, string originalName, string reExportedName) {
830+
exists(ExportSpecifier spec |
831+
spec = this.getASpecifier() and
832+
reExportedName = spec.getExportedName() and
833+
originalName = spec.getLocalName() and
834+
mod = this.getReExportedES2015Module()
835+
)
836+
}
837+
824838
overlay[global]
825839
override predicate reExportsAs(LexicalName v, string name) {
826-
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
827-
this.getReExportedES2015Module().exportsAs(v, spec.getLocalName())
840+
exists(ES2015Module mod, string originalName |
841+
this.reExportsFrom(mod, originalName, name) and
842+
mod.exportsAs(v, originalName)
828843
) and
829844
not (this.isTypeOnly() and v instanceof Variable)
830845
}
831846

832847
overlay[global]
833848
override DataFlow::Node getReExportedSourceNode(string name) {
834-
exists(ExportSpecifier spec | spec = this.getASpecifier() and name = spec.getExportedName() |
835-
result = this.getReExportedES2015Module().getAnExport().getSourceNode(spec.getLocalName())
849+
exists(ES2015Module mod, string originalName |
850+
this.reExportsFrom(mod, originalName, name) and
851+
result = mod.getAnExport().getSourceNode(originalName)
836852
)
837853
}
838854
}

javascript/ql/lib/semmle/javascript/frameworks/ClientRequests.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ module ClientRequest {
198198
private string urlPropertyName() { result = "url" or result = "uri" }
199199

200200
/** An API entry-point for the global variable `axios`. */
201+
overlay[local?]
201202
private class AxiosGlobalEntryPoint extends API::EntryPoint {
202203
AxiosGlobalEntryPoint() { this = "axiosGlobal" }
203204

javascript/ql/lib/semmle/javascript/frameworks/D3.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.javascript.security.dataflow.DomBasedXssCustomizations
66
/** Provides classes and predicates modeling aspects of the `d3` library. */
77
module D3 {
88
/** The global variable `d3` as an entry point for API graphs. */
9+
overlay[local?]
910
private class D3GlobalEntry extends API::EntryPoint {
1011
D3GlobalEntry() { this = "D3GlobalEntry" }
1112

javascript/ql/lib/semmle/javascript/frameworks/Electron.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module Electron {
4141
BrowserView() { this = DataFlow::moduleMember("electron", "BrowserView").getAnInstantiation() }
4242
}
4343

44+
overlay[local?]
4445
private class ElectronEntryPoint extends API::EntryPoint {
4546
ElectronEntryPoint() { this = "Electron.Browser" }
4647

javascript/ql/lib/semmle/javascript/frameworks/EventEmitter.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module EventRegistration {
9494
/**
9595
* A registration of an event handler on an EventEmitter.
9696
*/
97+
overlay[global]
9798
abstract class Range extends DataFlow::Node {
9899
EventEmitter::Range emitter;
99100

@@ -148,6 +149,7 @@ module EventDispatch {
148149
/**
149150
* A dispatch of an event on an EventEmitter.
150151
*/
152+
overlay[global]
151153
abstract class Range extends DataFlow::Node {
152154
EventEmitter::Range emitter;
153155

javascript/ql/lib/semmle/javascript/frameworks/History.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import javascript
55
/** Provides classes modeling the [`history`](https://npmjs.org/package/history) library. */
66
module History {
77
/** The global variable `HistoryLibrary` as an entry point for API graphs. */
8+
overlay[local?]
89
private class HistoryGlobalEntry extends API::EntryPoint {
910
HistoryGlobalEntry() { this = "HistoryLibrary" }
1011

javascript/ql/lib/semmle/javascript/frameworks/Immutable.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private module Immutable {
1313
/**
1414
* An API entrypoint for the global `Immutable` variable.
1515
*/
16+
overlay[local?]
1617
private class ImmutableGlobalEntry extends API::EntryPoint {
1718
ImmutableGlobalEntry() { this = "ImmutableGlobalEntry" }
1819

javascript/ql/lib/semmle/javascript/frameworks/Logging.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ private module Console {
3232
/**
3333
* An API entrypoint for the global `console` variable.
3434
*/
35+
overlay[local?]
3536
private class ConsoleGlobalEntry extends API::EntryPoint {
3637
ConsoleGlobalEntry() { this = "ConsoleGlobalEntry" }
3738

0 commit comments

Comments
 (0)