When to implement logic in the front-end vs the back-end?
Asked Answered
I

1

5

So I've gotten very familiar with Javascript MVC's over the past few weeks. Now I'm looking to learn the how to program a backend(specifically using asp.net MVC's implementation). I'm learning about the razor's view engine etc.

One learning block I'm running into when reading up on examples and tutorials is that I am thinking to myself "well..can't I just do that in the front-end with javascriptMVC" for most of the logic, and If I need to talk to a database I can just use a JSON call. There must be some value in back-end coding but right now I don't see it(hoping to get that solved).

Indevout answered 11/12, 2013 at 21:29 Comment(0)
F
9

The client is always exposed to attackers, hence you can never trust the code.

In other words: Any security-related things, verification and validation logic belongs to the server, all authentication and authorization stuff, … and: when you need to make sure that there is one reliable instance to decide some things, e.g. on prices, discounts, and so on.

There is a saying in web programming, and that is: All input is evil.

So whatever comes from your frontend (which basically is your JavaScript application) should be handled with care. Always black- or whitelist input, encode it, transform it, check it, and so on … and the only place where you can do this reliably, as it's the only place that is under YOUR control is the server.

Moreover: Never put secrets into the client, such as credentials (for your database, e.g.).

Hope this helps.

Fabianfabianism answered 11/12, 2013 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.