Hello,

recently I was working on a project entirely made by AI. at first it looked plausible but as I dig deeper into the code I found out ton of security issues. we solved the security issues one by one. ( thankfully the site isn’t released yet and only have beta testing users )

my question is that is it considered a security issue if I let the client ( browser ) make the supabase api call instead of routing those requests through the backend ( vercel ) even when I have made policies that prevents unauthorized users from submitting INSERT queries however I am still not sure if this is enough.

one thing that comes in my mind is that any authorized user can just spam the database and fill it with junk data but I think I can just ban that user and delete all the junk data relatively easily using a SQL query?

the thing is that I don’t want to refactor AI code and make it “use server” instead of “use client”. since I have to make a ton of changes and I am still learning Nextjs. ( thinking about using AI to fix AI code but I don’t think it will work and don’t want more AI slop in the codebase )

any suggestions are appreciated!

  • kibiz0r@midwest.social
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    4 days ago

    As always: it depends

    My first concern with exposing a DB to an authenticated client is incomplete state transitions. Often, a user interaction requires updating multiple DB entities in order to complete properly. Clients can die at any point, but servers should (hopefully) stay alive through one entire request and ensure that the DB goes from one complete valid state to the next.

    My second would be: just because you verify that the user is allowed to modify a given record doesn’t mean that all possible DB-level modifications are valid at an application level. That’s where resource-level security is insufficient. Security gaps often consist of having legitimate access to a resource but performing unexpected actions against it.

    I don’t know anything about supabase specifically, so I can’t guide you there. But those are the big two security (and data integrity) concerns I’d never stop worrying about in a direct-to-DB scenario.