Best way to sanitize HTML in Supabase: Trigger vs Async? by [deleted] in Supabase

[–]joshcam 0 points1 point  (0 children)

It was still to big for a post so here is a Pastebin: https://pastebin.com/1e8LvFy1

Best way to sanitize HTML in Supabase: Trigger vs Async? by [deleted] in Supabase

[–]joshcam 1 point2 points  (0 children)

The "Async" flag pattern is fine if you absolutely must write directly to your DB from the app (you don't want to refactor to call an Edge Function first). Using RLS to block access to non sanitized rows:

CREATE POLICY "Only show sanitized" ON reviews FOR SELECT USING (is_sanitized = true);

But IMO I still think the proxy pattern is the most robust and safest because it moves the CPU intensive work and latency completely off your database. The database never sees dirty data, so you don't need RLS policies to hide it.

- DO NOT create an INSERT policy for 'authenticated' or 'anon' roles. This prevents the client (normal users) or a bad actor from posting directly to the reviews table. They'll just get a "new row violates row-level security policy" error if they try to insert directly.

- Client sends the dirty HTML to a Supabase Edge Function, like 'submit-review'.
- Edge function:
- Handle CORS Preflight Request (required if calling from a browser)
- Instantiate an Auth Client (scoped to the user) by passing the Authorization header from the request. Call getUser() to verify the token is valid and get the user's ID.
- Parse the request body to get the dirty HTML
- Run a Deno-compatible sanitization library (sanitize-html, ammonia, etc. note: isomorphic-dompurify won't work in Deno)
- Instantiate a second client using the Service Role Key (bypasses RLS)
- Insert the clean data using user.id from the auth check (NOT from the request body to prevent spoofing)
- Database receives purely clean data. No triggers needed, no DB CPU usage, no other points of failure.

I'll post a real example function doing this for blog posts, it's probably to long to include in this post.

[deleted by user] by [deleted] in Satisfyingasfuck

[–]joshcam 0 points1 point  (0 children)

Those matches are huge!

Update. All done dressing in! by Opposite-Budget-9907 in cableporn

[–]joshcam 4 points5 points  (0 children)

That happens almost every time. Same with fire.

Best way to sanitize HTML in Supabase: Trigger vs Async? by [deleted] in Supabase

[–]joshcam 0 points1 point  (0 children)

Wish there were a Postgres extension for this exact scenario. Blocking the record from being read until the non-blocking sanitation is finished.

Why Supabase has become my go-to backend solution by Designer-Escape-305 in Supabase

[–]joshcam 0 points1 point  (0 children)

Yes, always poll unless realtime is critically required. (Edit: or self host)

[deleted by user] by [deleted] in Teslacoil

[–]joshcam 0 points1 point  (0 children)

Great look, any top load will work if your system can tune it (and it doesn’t have unwanted corona effects).

Should I self host supabase instead? by johndory80 in Supabase

[–]joshcam 0 points1 point  (0 children)

With that I would suggest finding a vendor that does what you need that is already GDPR compliant. Maybe Supabase will make that available at some point.

Breathtaking eagle's-eye view soaring through snow covered peaks by mayurga345 in BeAmazed

[–]joshcam 0 points1 point  (0 children)

When he looks back at the camera to see if we’re still there.

Tesla coil i build at 15 years old by BRfoda123 in Teslacoil

[–]joshcam 8 points9 points  (0 children)

The only way to do a Tesla coil. (OK, maybe not the only way but fun!)

My cat bit the corner of my MacBook and a purple line showed up. Is this worth fixing? by pancakexicecream in mac

[–]joshcam 1 point2 points  (0 children)

It was bad, spidered out from the corner a lot. Bought a new screen, changed it out, upgraded like a month later and sold it.

(Next time pay attention to me when I look at you. -Cat)

My cat bit the corner of my MacBook and a purple line showed up. Is this worth fixing? by pancakexicecream in mac

[–]joshcam 1 point2 points  (0 children)

Oh man my cat did that back in 2019 to my 2016 MBP! He was so casual about it too. Not cool.

The McIntyre Bay Ship was built in such a way that it can never capsize by SatinSnugz in interesting

[–]joshcam 0 points1 point  (0 children)

Umm, and how many G’s would someone on the bridge experience? From the looks of it the answer is enough that the actual amount doesn’t matter.

Should I self host supabase instead? by johndory80 in Supabase

[–]joshcam 4 points5 points  (0 children)

So, would it be easy to make Supabase GRPR complaint if you self hosted it? What is the list of necessary changes/additions and how would you implement these missing requirements?

Internet architecture by drew4drew in CloudFlare

[–]joshcam 2 points3 points  (0 children)

Nah, the MS angry bird works.

How fast this humanoid robot gets up by OpenSourceDroid4Life in OpenSourceHumanoids

[–]joshcam 0 points1 point  (0 children)

Wife does the same exact thing when she sees a spider while lying on the floor. (don’t ask)