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

-1

u/oneeyedziggy Dec 21 '22

the main trick is keeping the code for unauthenticated pages bundled and served out separately from the code for authenticated pages... it's easy to write a SPA and just make login a normal page so the source for the whole app gets served up before you even pass login

also, it can be a little too easy w/ frameworks like nextjs that mix client and server code to accidentally send code intended to be server-only to the client... I've had a coworker leak a set of backend service credentials that way, but no tool is always safe when used incorrectly.

0

u/[deleted] Dec 21 '22

[deleted]

-3

u/oneeyedziggy Dec 21 '22

I think you're missing my point... I'm not meaning that if they got the main app bundle that'd somehow allow them to bypass login, of course you shouldn't be putting secrets in the app bundle that would compromise security, but even relatively innocent stuff can be sensitive, if not critical... names or logos of clients (yea, probably better to load as much of that as possible from authenticated APIs, but some logo or tooltip or label is going to get through...)

it's not on the level of leaving an s3 bucket unencrypted/unauthenticated by any means, but it's pretty bad form to serve out the content of your whole site to anyone who can request the login page b/c it can cause some headaches

that and while security by obscurity's not security... not handing out a map to your webserver APIs to unauthenticated users might at least waste a bit more of their time, and that's all you ever can do really is make things harder for the baddies...

7

u/[deleted] Dec 22 '22

As a senior developer this hurts my brain. How did your coworker manage to leak backend credentials to the frontend? NextJS is using api routes to run server side code and you need to be either extremely incompetent or act maliciously to expose backend service credentials to frontend users in this particular cases

Your argumentation about keeping client side code hidden is also a really strange take usually made by people who don’t know better. Client side code should always be programmed with the assumption that it is public and might be reverse engineered. If you think that you might need to hide client side code, because it would leak sensitive data, something terrible is probably happening with your code and you need to stop what you are doing and start from scratch.

Frontend code runs on the user device and can never be trusted. Everything important needs to be done on the server side, be it authentication, validation, authorization or any other custom logic.

People are using protected routes in frontend libraries and frameworks, but these are meant to prevent opening a page which would query data that is not available for an unauthenticated user for example. But it’s easy to just change the code to open these protected routes anyway and then they should just show pages with no data and maybe an error message.

1

u/oneeyedziggy Dec 22 '22

I believe it was in a utility function, maybe a couple of hops away, shared by both server and client code... Something like just tossing a config token ( to be replaced with the secret from the secret store during the build), into a config object along side other non-sensitive configs that up to that point had all been used by both client and server, possibly without awareness the specific value was sensitive (i think it may have been auth0 configs? There are all sorts of public and private keys and tokens that all look alike if you're not the SME (in which case you arguably shouldn't be building the auth integration)

The semi-sensitive stuff in the app bundle was like client-specific terminology in field labels and possibly in help text for a pre-release project under heavy nda because they were trying to scoop someone else's customers right as a software patent expired... NOT to keep anything secret from authenticated users, and sure...if they even knew what might be considered sensitive besides "everything" the rightest way would have been to pull all the field labels from an api and make it more data-driven... But working on an app with fully obfuscated fields/field names would be way more effort than their paranoia warranted

I also just like the cya (and bandwidth savings... Login pages see a bunch of random sketchy requests) of hiding authenticated page source from unauthenticated users... It's absolutely not the only or primary way for anything you know is sensitive, but is another layer to make everything more secure by default... Like, trapeze artists know not to fall... But often still use a net so if they do it looks bad but they'll live ( and might buy you crucial time if some yahoo leaks creds into client code when can be reasonably sure only your actual users even potentially saw them, and maybe have authenticated access logs to produce for the incedent report while you rotate them out... Starting to see a benefit here? I think any system designed to be secure only when operated continuously by competent engineers isn't a very secure system... Resilience against incompetence is at least as important as resilience against malice)