feat(guardrails): secure-by-default rule and /guardrails scanner
Always-on rules/secure-by-default.md: hosting, a11y, Supabase RLS, SMS/email consent, cloud functions, API hygiene incl. password storage. Stdlib scanner (FAIL/WARN/MANUAL) + skill, 89-check suite, auditor gate wiring, profiles, routing row (plus Explore rows confirmed through the router dialog).
This commit is contained in:
1 parent
c5fad5ee8f
commit
558c49e1a1
45 files changed
+2473
-5
No files matched your search
@@ -0,0 +1,2 @@
|
||||
[functions.notify]
|
||||
verify_jwt = true
|
||||
@@ -0,0 +1,22 @@
|
||||
import { Resend } from "npm:resend";
|
||||
|
||||
const resend = new Resend(Deno.env.get("RESEND_API_KEY"));
|
||||
|
||||
Deno.serve(async (request) => {
|
||||
const user = await getUser(request);
|
||||
const contact = await loadContact(user.id);
|
||||
if (!contact.consent_at || contact.unsubscribed_at) {
|
||||
return new Response("skipped");
|
||||
}
|
||||
const link = unsubscribeUrl(contact.id);
|
||||
await resend.emails.send({
|
||||
to: contact.email,
|
||||
subject: "News",
|
||||
html: `<p>Hello</p><a href="${link}">Unsubscribe</a>`,
|
||||
headers: {
|
||||
"List-Unsubscribe": `<${link}>`,
|
||||
"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
|
||||
},
|
||||
});
|
||||
return new Response("sent");
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import twilio from "npm:twilio";
|
||||
|
||||
const client = twilio(Deno.env.get("TWILIO_SID"), Deno.env.get("TWILIO_TOKEN"));
|
||||
|
||||
Deno.serve(async (request) => {
|
||||
const user = await getUser(request);
|
||||
const contact = await loadContact(user.id);
|
||||
if (!contact.consent_at || contact.opt_out_at) {
|
||||
return new Response("skipped");
|
||||
}
|
||||
await client.messages.create({
|
||||
to: contact.phone,
|
||||
body: "Your offer is ready. Reply STOP to opt out.",
|
||||
});
|
||||
return new Response("sent");
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
create table public.notes (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
user_id uuid not null references auth.users (id),
|
||||
body text not null
|
||||
);
|
||||
alter table public.notes enable row level security;
|
||||
|
||||
create policy "owner read" on public.notes
|
||||
for select to authenticated
|
||||
using ((select auth.uid()) = user_id);
|
||||
|
||||
create policy "owner insert" on public.notes
|
||||
for insert to authenticated
|
||||
with check ((select auth.uid()) = user_id);
|
||||
|
||||
create table public.contacts (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
owner_id uuid not null references auth.users (id),
|
||||
email text,
|
||||
phone text,
|
||||
consent_at timestamptz not null,
|
||||
consent_source text not null,
|
||||
unsubscribed_at timestamptz,
|
||||
opt_out_at timestamptz
|
||||
);
|
||||
alter table public.contacts enable row level security;
|
||||
|
||||
create policy "owner contacts" on public.contacts
|
||||
for all to authenticated
|
||||
using ((select auth.uid()) = owner_id)
|
||||
with check ((select auth.uid()) = owner_id);
|
||||
|
||||
create view public.my_notes with (security_invoker = true) as
|
||||
select * from public.notes;
|
||||
|
||||
create function public.touch_updated() returns trigger
|
||||
language plpgsql as $$
|
||||
begin
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
|
||||
create function public.admin_count() returns bigint
|
||||
language sql security definer set search_path = '' as $$
|
||||
select count(*) from public.notes;
|
||||
$$;
|
||||
revoke execute on function public.admin_count() from public, anon;
|
||||
|
||||
create trigger notes_notify after insert on public.notes
|
||||
for each row execute function supabase_functions.http_request(
|
||||
'https://example.supabase.co/functions/v1/notify', 'POST', '{}', '{}', '5000'
|
||||
);
|
||||
|
||||
create policy "service delete" on public.notes
|
||||
for delete to service_role using (true);
|
||||
Reference in new issue
Block a user