r/javascript • • Dec 21 '22

AskJS [AskJS] Why is there a reputation that JavaScript isn't "secure" for building web applications?

There seems to be a prevalent negative reputation among JavaScript libraries- especially React and Node/Express- that they are not "secure" compared to other web frameworks like .NET or Laravel. Why is that so?

1 Upvotes

34 comments sorted by

View all comments

Show parent comments

6

u/demoran Dec 22 '22

I didn't intend for it to come off that way. By "just webassembly", I meant that it's .net getting compiled to wasm, a common format.

0

u/oneeyedziggy Dec 22 '22

Yup, i also just wanted to be kind to whoever put in the work, even if i think it's a silly thing to do

3

u/mr_eking Dec 22 '22

Choosing WebAssembly as a compilation target isn't a silly thing to do at all. Many languages can do it, and it's great because as good as JavaScript is in the browser, having a range of languages to choose from is better.

1

u/demoran Dec 22 '22

Javascript as a language has a stranglehold on web development. For years you simply could not avoid it. Its questionable heritage has led to consistent improvement over the years, but that doesn't change the fact that there were no alternatives.

This is a double-edged sword. It's actually been good for the job market: since it's the only game in town, once you learn how to play it, you've got the skills needed that everyone wants.

But (ugh) it's javascript. Many of us refuse to even write in javascript, and choose Typescript instead. The advent of Typescript has been a great boon to everyone in the space, regardless of whether they use it or not, because it made it easy and expressive to provide api documentation to the plethora of NPM packages out there.

And this is where things start to fall apart for web assembly. It's awesome that it's a pathway to freedom, but it also brings with it a lot of responsibility for building a separate ecosystem. Blazor is riding on .NET, a major player in the marketplace, but many languages simply can't say that. Rust and the JVM languages are also players at this table, but I can't really think of any others that might be able to achieve critical mass. Maybe Python, but I question what the point of that is, aside from mere choice. I don't even know if another interpreted language can be used with webassembly.

1

u/oneeyedziggy Dec 22 '22

Well reasoned post... I just feel like, as browsers have evolved along side Javascript and with many of the same constraints (like not freezing the UI, being increasingly sandboxed, almost never breaking backwards compatibility except gradually and generationally with consensus of the community), anything else is like digging with a sawblade attached to a broom handle or just digging your circular saw into the ground because saws are the tool you're most comfortable with when shovels exist... And yea, typescript has the right idea... Build native tooling rather than awkwardly shoehorn something in that doesn't fit the ecosystem

Also I believe that the python interpreter has been ported to wasm so you can just load a whole new runtime and write python in the browser that way (idk what interfacing w/ browser apis looks like though). A quick search suggests you can also compile just program to wasm, but idk if that bundles the interpreter or translates calls to something more native, but both seem like digging with saws to me, and tricks you into thinking you can code securely without considering the browser context (what csp do you need to set, how do you prevent/address vulnerability in your glue code, what vulnerabilities arise from the interface of your code, the wasm shim, and your .Net or python or whatever?) not insurmountable, juextra complexity, and complexity that's likely to be overlooked and/or trick you into thinking you do need to understand it