Skip to content

Commit 91fe935

Browse files
committed
docs: Update detect-object-injection docs
fixes #136
1 parent 1bd0170 commit 91fe935

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/rules/detect-object-injection.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,35 @@
44

55
<!-- end auto-generated rule header -->
66

7+
JavaScript allows you to use expressions to access object properties in addition to using dot notation. So instead of writing this:
8+
9+
```js
10+
object.name = 'foo';
11+
```
12+
13+
You can write this:
14+
15+
```js
16+
object['name'] = 'foo';
17+
```
18+
19+
Square bracket notation allows any expression to be used in place of an identifier, so you can also do this:
20+
21+
```js
22+
const key = 'name';
23+
object[key] = 'foo';
24+
```
25+
26+
By doing so, you've now obfuscated the property name from the reader, which makes it easy for a malicious actor to replace the value of `key` and change the behavior of the code.
27+
28+
This rule flags any expression in the form of `object[expression]` no matter where it occurs. Examples of patterns this will be flagged are:
29+
30+
```js
31+
object[key] = value;
32+
33+
value = object[key];
34+
35+
doSomething(object[key]);
36+
```
37+
738
More information: [The Dangers of Square Bracket Notation](../the-dangers-of-square-bracket-notation.md)

0 commit comments

Comments
 (0)