0

I currently have two ASP.NET Core projects that share some business logic classes, as well as DbContext. They are injected as dependencies in ConfigureServices, just like what Microsoft Docs usually show us.

However when it comes to deployment, my client suggests to separate database access (i.e. whatever business logic that requires database connection) to a different server and serve as web api.

I found that this idea is rarely mentioned from the Internet but somehow makes such sense to me - this makes sure even if someone hacks into the web server, they do not have direct database access and cause damage or leak to data.

Can anyone tell me if it is a good practice or it is actually uneccessary?

5
  • What types of projects? Asp.net MVC app? Console app?
    – Judy007
    Oct 16, 2018 at 3:37
  • @joey ASP.NET Core MVC, like with a web frontend Oct 16, 2018 at 3:37
  • Two websites in two separate projects?
    – Judy007
    Oct 16, 2018 at 3:38
  • @joey Yes, but they share some business logics that require the same database connection. I was directly injecting those business logics and DbContext into the project, but I am then told to wrap those things as a web api (3rd project), and whenever the frontend needs data, it fetches from web api rather than accessing DbContext directly. Oct 16, 2018 at 3:41
  • As far as security goes, why would an attacker that hacked one of your webservers not be able to hack the other? That's like having two doors in sequence in case a burglar picked the lock on the first one... one would assume that said burglar would just pick the second lock as well.
    – nvoigt
    Oct 16, 2018 at 13:22

2 Answers 2

0

It may make sense to add a web api service that the two client applications make http requests to. Somewhat like a microservice. But, web service requests that need to be a authenticated do require that to be setup. Which leads to how your auth is currently setup. If it’s cloud hosted, you can use api gateways and combine oauth. Each public cloud provider offers their own style of gateway. Ex. Azure offers api management service.

0

Your database instance should definitely be on a separate server from your web apps, for performance reasons as much as security. However, moving the database access code itself to a separate server buys you nothing security-wise. I suppose it might make it more difficult to perform SQL injection if there's a API acting as an intermediary, but that's no guarantee. Bad code is bad code, and if you code is not competent enough to prevent SQL injection in the first place, you'll likely introduce some flaw in the API that could still allow it.

Long and short, there's merit to adding an API layer, but security is not part of that. APIs in fact introduce their own separate security issues that you'll need to account for. In other words, you can secure a monolithic app that accesses the DB directly and you can secure one that access an API, but the mere act of adding an API doesn't somehow do the securing for you.

1
  • SQL injection flow through API as well if database access code will allow to do it.
    – Fabio
    Oct 16, 2018 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.