r/javascript • • Feb 08 '23

Software Security Report Finds JavaScript Applications Have Fewer Flaws Than Java and .NET

https://www.infoq.com/news/2023/02/veracode-software-security/
565 Upvotes

124 comments sorted by

View all comments

Show parent comments

1

u/arcytech77 Feb 09 '23

Can you explain which circumstances it isn't safe?

If it's your own code then it is deterministic. The only two scenarios that it wouldn't be your own code is when A) You make the huge mistake of calling it on the response of a third party request or B) Your site is suffering from some sort of middle-man attack where they have access to your bundled source code that server responds with when someone requests your page. In this scenario it's already game over. They don't need eval to run whatever code they want. Tell me what am I missing?

1

u/[deleted] Feb 09 '23 edited Jun 30 '23

[removed] — view removed comment

1

u/arcytech77 Feb 09 '23

You're missing the point of the warning, it reads like this:
Don't call eval on third party code. That's it, you're good as long as you don't do that. The rest of the warning is devoted to explaining how you can end up calling eval on third party code unintentionally after already making the blunder of allowing third party code access to your applications run time scope - why would you do that?

1

u/[deleted] Feb 09 '23 edited Jun 30 '23

[removed] — view removed comment

1

u/arcytech77 Feb 09 '23

You described the indirection mechanism for an attacker to get their code into your string local variable. When I say "why would you do that" I am speaking towards any third party code having access to your applications run time scope, particularly the one where you call eval. You don't need to do that ever.

1

u/[deleted] Feb 09 '23 edited Jun 30 '23

[removed] — view removed comment

1

u/arcytech77 Feb 09 '23

I am saying do not do this:

let juicy_target = 'console.log("hello world")'
thirdPartyFunction()
eval(juicy_target)

Invoking thirdPartyFunction could potentially have side affects on the local variable juicy_target.

→ More replies (0)

1

u/arcytech77 Feb 09 '23

Idk maybe that's not so obvious to most devs, but I think it's fairly straightforward and does not mean you should stay away from eval as a general rule of thumb. I think you should understand why and in what contexts it's dangerous.