5
5
6
6
<overview >
7
7
<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.
10
11
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.
16
15
</p >
16
+
17
17
</overview >
18
18
19
19
<recommendation >
20
20
<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.
22
23
</p >
23
24
</recommendation >
24
25
@@ -35,8 +36,9 @@ If untrusted inputs are used with these methods,
35
36
then an attacker might be able to execute arbitrary code on the system.
36
37
</p >
37
38
<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.
40
42
</p >
41
43
42
44
<sample src =" examples/UnsafeCodeConstructionSafe.js" />
0 commit comments