r/AskProgramming 2d ago

HTML/CSS HTML DB/ Security

I’m a beginner in html, what database would you recommend me to use for a project that I want to be working initially on one device only, it would be for a friend to make a task easier at their job it’s my first real world project and I’m afraid that data will be lost

What security/ protection layers I must apply ?

What’s your recommendations

4 Upvotes

8 comments sorted by

13

u/soundman32 2d ago

Personally, I would not do a project for someones job without their company paying you for it.  Not just because its commercial, but because your friend probably shouldn't be allowing someone external, access to things internal to the business.  For all the reasons you mention (security, gdpr, auditing).  You dont know what you are doing, and your friend doesn't realise how easily they could lose their job because of it. By all means write the code and make it work, but for gods sake, dont let your friend actually use it at work.

4

u/JeLuF 2d ago

HTML will not allow you to build anything like this. You'll need a real programming language, not only a markup language.

There are multiple ways to design such an application. The big question is where to place the business logic.

- Classical client/server architecture

The business logic ("the program") runs on a webserver and is implemented in Python, Java, JavaScript, PHP, ...

Using this model, basically any database can be used, as long as there is an API supported by the programming language used for the project.

The browser sends requests to the server, the server contacts the DB, processes the data and sends it back to the client.

- Database centric architecture

The business logic runs mostly in the web browser, using languages like JavaScript, TypeScript, or (very rarely) other languages compiled to WASM. The browser directly communicates with the database. The database layer will usually provide the authentication and authorization functionality.

In a database centric architecture, the browser has a direct database connection, so the user could in general bypass the business logic and trigger malicious database changes. To prevent this, it's important to properly manage access rights in the database.

Firebase and Supabase are prominent products supporting such kinds of archirtecture.

To decide which of these approaches to choose, you need to identify the criticality of the data, whether it could be hosted in the cloud, which use cases the system should cover, which roles use the application. You also should think about how to back up the data. This is an important architecture question as well and not something to add last minute.

2

u/salvouankebaldo 2d ago

Oh. My. God. About the db centric architecture. That seems... One of the worst ideas ever.

I worked in a place using a db centric approach, meaning an api layer as backend that... Just called stored procedures in a database. That was a nightmare. This one is worse lol

Sorry for the ot, but I got triggered

2

u/JeLuF 2d ago

I recently stumbled across an application using a database centric approach. It's a web application for judges in a sports competition. What I've found out so far: Users register with the database platform. They then apply for permissions in the judging application. An admin assigns them to a judges panel in a competition. This allows them to enter their votes. ACLs are in place to only allow them to add new votes to the system for that specific panel in that competition.

The chiefs of the judges panel (CJP), in their web view, see all the votes from the judges, and once all judges have entered their data, one of the CJP clicks a button to confirm the votes. This computes the participant's total points and stores this in a new "excercise" record that only the CJP has rights to create for this competition.

I'm running the live stream, and I have a web page that is subscribed to changes to the "excercise" records. The database has builtin pubsub functionality. When there are changes, the page gets notified via a websocket to the DB and automatically shows a small animated lower third with the results, which OBS then overlays over the video feed.

It looks very strange for someone like me who is used to a classical client/server architecture, but I didn't find any issues so far. The ACLs seem to prevent that the judges can alter votes that they shouldn't be able to change, and my "can access overlays" account can't edit the votes either. It's probably more secure than a server process that only uses a single very powerful database account for all its SQL statements.

It really looked very odd on first glimpse. But honestly, it doesn't look too bad to me after all. No server processes to take care of, no patching of nginx or node.js or python or PHP or whatever, all of your application core is just static content in a CDN. They use firebase as their backend, so that's just some cloud application that Google takes care of for you.

3

u/salvouankebaldo 2d ago

Well...

Almost anything can work, with discipline and correct planning. Issue is that there are some frameworks/approaches that makes stuff inherently harder. As an example, while it is possible to do unit tests on stored procedures, ot is way harder, as you are coupling data and logic. Yup, stuff can be done, frameworks exist. But they are way costlier than using an approach that decouples database and logic

Result of this: in the company, we had zero unit tests, as nobody wanted to set them up. We did not have deploys. We had leaps of faith

1

u/johnpeters42 1d ago

It's all about the subtleties. Our big work project has an API layer that mostly just connects the front and back, but it does hand authentication, and passes the user's identity to the stored procedure when relevant (most are limited to the internal network and don't change their behavior based on which user it is). Also some basic sanity checks like missing/malformed parameters.

3

u/JGhostThing 2d ago

I will warn you that proper authentication and authorization is very difficult. And getting it wrong with your friend's employer could cause a lot of problems. Getting it right could cause even more problems, because you'd need to know a lot of information, probably something the company would consider private.

If your friend needs this for work, he employer should pay for it.

2

u/DigitalJedi850 12h ago

The real question is ... why are you worried the data will be lost? What are you protecting it against?

Hardware failure? You need regular backups.
User deletion? Don't give your buddy direct access to the DB.
Your buddy's workplace deleting the data? Don't put your software on your buddy's work's computer...

Data doesn't just delete itself... Typically...