Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (39 loc) · 1.51 KB

File metadata and controls

42 lines (39 loc) · 1.51 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* @name Property access on null or undefined
* @description Trying to access a property of "null" or "undefined" will result
* in a runtime exception.
* @kind problem
* @problem.severity error
* @id js/property-access-on-non-object
* @tags quality
* reliability
* correctness
* external/cwe/cwe-476
* @precision high
*/
import javascript
private import semmle.javascript.dataflow.InferredTypes
/**
* Holds if `e` is a direct reference to a const enum or namespace declaration.
*
* Reference to const enum members are constant-folded by the TypeScript compiler,
* even if the surrounding namespace object would not have been initialized at that point.
*
* If the base expression of a property access is a namespace, we can't currently tell
* if it is part of a const enum access, so we conservatively silence the alert in that case.
*/
predicate namespaceOrConstEnumAccess(VarAccess e) {
exists(NamespaceDeclaration decl | e.getVariable().getADeclaration() = decl.getIdentifier())
or
exists(EnumDeclaration decl | e.getVariable().getADeclaration() = decl.getIdentifier() |
decl.isConst()
)
}
from PropAccess pacc, DataFlow::AnalyzedNode base
where
base.asExpr() = pacc.getBase() and
forex(InferredType tp | tp = base.getAType() | tp = TTNull() or tp = TTUndefined()) and
not namespaceOrConstEnumAccess(pacc.getBase()) and
not pacc.isAmbient() and
not pacc instanceof OptionalUse
select pacc, "The base expression of this property access is always " + base.ppTypes() + "."
Morty Proxy This is a proxified and sanitized view of the page, visit original site.