Skip to content

Commit b819668

Browse files
authored
Update README.md
1 parent a1ae0ab commit b819668

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,27 @@ const template = `
8484
This, along with the fact that `devalue` bails on functions and non-POJOs, stops attackers from executing arbitrary code. Strings generated by `devalue` can be safely deserialized with `eval` or `new Function`:
8585

8686
```js
87-
const value = eval('(' + str + ')');
87+
const value = (0,eval)('(' + str + ')');
8888
```
8989

9090

91+
## Other security considerations
92+
93+
While `devalue` prevents the XSS vulnerability shown above, meaning you can use it to send data from server to client, **you should not send user data from client to server** using the same method. Since it has to be evaluated, an attacker that successfully submitted data that bypassed `devalue` would have access to your system.
94+
95+
When using `eval`, ensure that you call it *indirectly* so that the evaluated code doesn't have access to the surrounding scope:
96+
97+
```js
98+
{
99+
const sensitiveData = 'Setec Astronomy';
100+
eval('sendToEvilServer(sensitiveData)'); // pwned :(
101+
(0,eval)('sendToEvilServer(sensitiveData)'); // nice try, evildoer!
102+
}
103+
```
104+
105+
Using `new Function(code)` is akin to using indirect eval.
106+
107+
91108
## See also
92109

93110
* [lave](https://github.com/jed/lave) by Jed Schmidt
@@ -98,4 +115,4 @@ const value = eval('(' + str + ')');
98115

99116
## License
100117

101-
[LIL](LICENSE)
118+
[LIL](LICENSE)

0 commit comments

Comments
 (0)