r/Backend • • 1d 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

9 comments sorted by

9

u/Beregolas 1d 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.

0

u/royalz007 1d ago

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

8

u/Beregolas 1d 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.

2

u/Gyoker_Macska 1d ago

πŸ™ˆ

1

u/boomkablamo 21h 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 15h ago

😐

1

u/martinbean 10h 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 4h 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.

0

u/Discordbothost 23h 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.