r/Backend • • 2d ago

backend source code

how does backend to front end communication work for a website , and is it even possible to obtain the backend source code from the front end website url ?

0 Upvotes

11 comments sorted by

11

u/Beregolas 2d ago

The backend usually exposes an API, most commonly a REST API specifically. The frontend can call the endpoints in that API to mutate data on the backend, and/or to receive data to display to the user.

If coded correctly, the backend code cannot be retrieved by people who have access to the frontend.

-1

u/royalz007 2d ago

hm so a weakness in my front end could expose my backend ? what needs to be strong to prevent this

12

u/Beregolas 2d ago

No... it sounds like you are trying to do something you don't understand, and I caution you to stop and learn first. Security can't be done by reddit comment, I can't possible list all the possible ways you can fuck up and be responsible for your security in this way.

Also, generally the backend is not exposed by weaknesses in the frontend, the kinds of exposure I can think of are:

  1. you acctidentally compiled your backend code into your frontend
  2. If you for some reason include keys or passwords in your frontend code that can be used to access one of your accounts (especially git)

But most of the issues with backends normally come from the backend code, not the frontend code. Basically anything that allows an attacker remote code execution can be used to exfiltrate your backend code, if it's interpreted (python, JS etc.) or your backend binary, which can be reverse engineered with modern tools pretty effectively, depending on the language/framework used.

3

u/Gyoker_Macska 2d ago

πŸ™ˆ

2

u/boomkablamo 2d ago

Frontend doesn't need backend source code they just need to know the exposed API surface... If the API cannot efficiently support the frontends needs,, then their job is to communicate their needs to the backend dev so they can meet them.

1

u/Z33PLA 1d ago

😐

1

u/martinbean 1d ago

lol, you can’t obtain backend source code from a website URL, otherwise everyone would be running around with the source code to sites like Facebook, Amazon, etc.

1

u/Glittering_Fault_353 1d ago

Reading real backend source code makes more sense when one request is traced from the route through the database and back, file by file. Bootdev could help build the fundamentals that make such code readable though steady code reading also works.

1

u/BannockHatesReddit_ 19h ago

Rest/soap API with js frontend

Server side html rendering

It is possible to configure a server to mistakenly serve your source files but it'd be a pretty big screw up

0

u/Discordbothost 2d ago

the practical leak is shipping source maps or a .env into the frontend build. the browser only sees what your api returns, so check what is actually in your dist folder.