Skip to content

Commit eb133f5

Browse files
committed
update qhelp to focus on properly documenting potentially unsafe library functions
1 parent a9f7756 commit eb133f5

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

javascript/ql/src/Security/CWE-094/UnsafeCodeConstruction.qhelp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55

66
<overview>
77
<p>
8-
Dynamically constructing code with inputs from exported functions
9-
may inadvertently change the meaning of the code.
8+
When a library function dynamically constructs code in a potentially unsafe way, then
9+
it's important to document to clients of the library that the function should only be
10+
used with trusted inputs.
1011

11-
Clients using the functions may use characters that have special
12-
meaning, such as quotes and spaces.
13-
14-
This can result in the resulting code to misbehave, or in the worst case
15-
cause an attacker to execute arbitrary code on the system.
12+
If the function is not documented as being potentially unsafe, then a client may
13+
incorrectly use inputs containing unsafe code fragments, and thereby leave the
14+
client vulnerable to code-injection attacks.
1615
</p>
16+
1717
</overview>
1818

1919
<recommendation>
2020
<p>
21-
Avoid dynamically constructing code where possible.
21+
Properly document library functions that construct code from unsanitized
22+
inputs, or avoid constructing code in the first place.
2223
</p>
2324
</recommendation>
2425

@@ -35,8 +36,9 @@ If untrusted inputs are used with these methods,
3536
then an attacker might be able to execute arbitrary code on the system.
3637
</p>
3738
<p>
38-
To avoid this problem, use an alternative solution such as `JSON.parse`
39-
or another library that does not allow arbitrary code to be executed.
39+
To avoid this problem, either properly document that the function is potentially
40+
unsafe, or use an alternative solution such as `JSON.parse` or another library
41+
that does not allow arbitrary code to be executed.
4042
</p>
4143

4244
<sample src="examples/UnsafeCodeConstructionSafe.js" />

0 commit comments

Comments
 (0)