lilith-skill 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +134 -2
- package/THIRD_PARTY_NOTICES.md +79 -0
- package/bin/lilith.mjs +147 -0
- package/package.json +43 -4
- package/skills/lilith/SKILL.md +61 -0
- package/skills/lilith/agents/openai.yaml +4 -0
- package/skills/lilith/checks/firebase_check.md +45 -0
- package/skills/lilith/checks/supabase_check.sql +211 -0
- package/skills/lilith/guides/cleanup-code.md +56 -0
- package/skills/lilith/guides/cleanup-ui.md +54 -0
- package/skills/lilith/guides/fixes/S1.md +6 -0
- package/skills/lilith/guides/fixes/S10.md +3 -0
- package/skills/lilith/guides/fixes/S11.md +3 -0
- package/skills/lilith/guides/fixes/S12.md +3 -0
- package/skills/lilith/guides/fixes/S13.md +3 -0
- package/skills/lilith/guides/fixes/S14.md +9 -0
- package/skills/lilith/guides/fixes/S2.md +15 -0
- package/skills/lilith/guides/fixes/S3.md +25 -0
- package/skills/lilith/guides/fixes/S4.md +11 -0
- package/skills/lilith/guides/fixes/S5.md +3 -0
- package/skills/lilith/guides/fixes/S6.md +7 -0
- package/skills/lilith/guides/fixes/S7.md +16 -0
- package/skills/lilith/guides/fixes/S8.md +11 -0
- package/skills/lilith/guides/fixes/S9.md +3 -0
- package/skills/lilith/guides/fixing.md +9 -0
- package/skills/lilith/guides/security-core.md +66 -0
- package/skills/lilith/guides/server.md +73 -0
- package/skills/lilith/guides/stacks/ai.md +14 -0
- package/skills/lilith/guides/stacks/firebase.md +13 -0
- package/skills/lilith/guides/stacks/stripe.md +13 -0
- package/skills/lilith/guides/stacks/supabase.md +31 -0
- package/skills/lilith/guides/ui/charts.md +10 -0
- package/skills/lilith/guides/ui/examples.md +30 -0
- package/skills/lilith/guides/ui/surface.md +11 -0
- package/skills/lilith/scripts/count_tells.py +384 -0
- package/skills/lilith/scripts/lilith_scan.py +750 -0
- package/skills/lilith/templates/report.md +64 -0
- package/src/agents.mjs +54 -0
- package/src/install.mjs +71 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
-- Lilith: live database check for Supabase
|
|
2
|
+
-- ---------------------------------------------------------------------------
|
|
3
|
+
-- WHAT THIS DOES, IN PLAIN WORDS
|
|
4
|
+
-- This query only READS your database SETTINGS (which tables exist, which
|
|
5
|
+
-- rules protect them, who is allowed to do what). It never reads the rows
|
|
6
|
+
-- inside your tables, and it never changes anything.
|
|
7
|
+
--
|
|
8
|
+
-- HOW TO USE
|
|
9
|
+
-- Supabase dashboard -> SQL Editor -> New query -> paste all of this -> Run.
|
|
10
|
+
-- Copy the result table back into the chat with your AI.
|
|
11
|
+
--
|
|
12
|
+
-- WHAT YOU GET
|
|
13
|
+
-- One table with columns: severity, check_id, object, problem, fix_sql.
|
|
14
|
+
-- fix_sql is a ready statement where one is safe to suggest; otherwise it is
|
|
15
|
+
-- a short instruction. Do not run fix_sql blindly: read it first, or let your
|
|
16
|
+
-- AI explain it.
|
|
17
|
+
--
|
|
18
|
+
-- This is a first check, written for Lilith. For the fuller official check,
|
|
19
|
+
-- also open Supabase dashboard -> Advisors -> Security Advisor.
|
|
20
|
+
-- Works on Supabase and on plain PostgreSQL 12+ (storage checks are skipped
|
|
21
|
+
-- when there is no storage schema, role checks are skipped without anon).
|
|
22
|
+
-- ---------------------------------------------------------------------------
|
|
23
|
+
with
|
|
24
|
+
-- Roles a visitor can act as: anon (not logged in) and authenticated.
|
|
25
|
+
api_roles as (
|
|
26
|
+
select oid, rolname from pg_roles where rolname in ('anon', 'authenticated')
|
|
27
|
+
),
|
|
28
|
+
-- Tables in the public schema (normal and partitioned), not owned by extensions.
|
|
29
|
+
pub_tables as (
|
|
30
|
+
select c.oid, c.relname, c.relrowsecurity as rls_on,
|
|
31
|
+
format('public.%I', c.relname) as qname,
|
|
32
|
+
(select count(*) from pg_policy p where p.polrelid = c.oid) as n_policies
|
|
33
|
+
from pg_class c
|
|
34
|
+
join pg_namespace n on n.oid = c.relnamespace
|
|
35
|
+
where n.nspname = 'public'
|
|
36
|
+
and c.relkind in ('r', 'p')
|
|
37
|
+
and not exists (select 1 from pg_depend d
|
|
38
|
+
where d.classid = 'pg_class'::regclass and d.objid = c.oid and d.deptype = 'e')
|
|
39
|
+
),
|
|
40
|
+
-- Which API role can touch which public table (includes grants to PUBLIC).
|
|
41
|
+
table_access as (
|
|
42
|
+
select t.oid, r.rolname,
|
|
43
|
+
has_table_privilege(r.oid, t.oid, 'select') as can_select,
|
|
44
|
+
has_table_privilege(r.oid, t.oid, 'insert, update, delete') as can_write
|
|
45
|
+
from pub_tables t cross join api_roles r
|
|
46
|
+
),
|
|
47
|
+
-- Policies in public and storage, with readable expressions.
|
|
48
|
+
pols as (
|
|
49
|
+
select schemaname, tablename, policyname, permissive, roles, cmd,
|
|
50
|
+
coalesce(qual, '') as qual, coalesce(with_check, '') as with_check
|
|
51
|
+
from pg_policies
|
|
52
|
+
where schemaname in ('public', 'storage')
|
|
53
|
+
),
|
|
54
|
+
findings as (
|
|
55
|
+
|
|
56
|
+
-- a. RLS off on a table the API roles can reach: anyone with the public anon
|
|
57
|
+
-- key can read or change every row.
|
|
58
|
+
select 'critical' as severity, 'rls_disabled' as check_id, t.qname as object,
|
|
59
|
+
'Row Level Security is OFF and ' ||
|
|
60
|
+
string_agg(distinct a.rolname, ' and ') ||
|
|
61
|
+
' can ' ||
|
|
62
|
+
case when bool_or(a.can_write) then 'read and change' else 'read' end ||
|
|
63
|
+
' every row.' as problem,
|
|
64
|
+
format('alter table %s enable row level security; -- then add policies so each user only sees their own rows', t.qname) as fix_sql
|
|
65
|
+
from pub_tables t
|
|
66
|
+
join table_access a on a.oid = t.oid and (a.can_select or a.can_write)
|
|
67
|
+
where not t.rls_on and t.n_policies = 0
|
|
68
|
+
group by t.qname
|
|
69
|
+
|
|
70
|
+
union all
|
|
71
|
+
-- b. Policies exist but RLS is off: the policies do nothing.
|
|
72
|
+
select 'critical', 'policies_ignored', t.qname,
|
|
73
|
+
'This table has ' || t.n_policies || ' policies, but Row Level Security is OFF, so the policies are ignored and the table is open.',
|
|
74
|
+
format('alter table %s enable row level security;', t.qname)
|
|
75
|
+
from pub_tables t
|
|
76
|
+
where not t.rls_on and t.n_policies > 0
|
|
77
|
+
|
|
78
|
+
union all
|
|
79
|
+
-- c. Write policies that let everyone write: condition is literally true, or
|
|
80
|
+
-- an explicit anon write policy that never checks who the user is.
|
|
81
|
+
select 'critical', 'open_write_policy',
|
|
82
|
+
format('%I.%I (policy "%s")', p.schemaname, p.tablename, p.policyname),
|
|
83
|
+
case
|
|
84
|
+
when p.qual = 'true' or p.with_check = 'true'
|
|
85
|
+
then 'Policy for ' || lower(p.cmd) || ' has condition "true": anyone it applies to (' || array_to_string(p.roles, ', ') || ') can do it to any row.'
|
|
86
|
+
else 'Policy lets anon (visitors who are not logged in) ' || lower(p.cmd) || ' without checking who they are.'
|
|
87
|
+
end,
|
|
88
|
+
format('drop policy %I on %I.%I; -- then add one that checks (select auth.uid()) = user_id', p.policyname, p.schemaname, p.tablename)
|
|
89
|
+
from pols p
|
|
90
|
+
where p.permissive = 'PERMISSIVE'
|
|
91
|
+
and p.cmd in ('INSERT', 'UPDATE', 'DELETE', 'ALL')
|
|
92
|
+
and (
|
|
93
|
+
p.qual = 'true' or p.with_check = 'true'
|
|
94
|
+
or ('anon' = any (p.roles) and (p.qual || p.with_check) not like '%auth.uid()%'
|
|
95
|
+
and (p.qual || p.with_check) not like '%auth.jwt()%')
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
union all
|
|
99
|
+
-- d. Read policies with USING (true): fine only for truly public data.
|
|
100
|
+
select 'info', 'public_read_policy',
|
|
101
|
+
format('%I.%I (policy "%s")', p.schemaname, p.tablename, p.policyname),
|
|
102
|
+
'Everyone it applies to (' || array_to_string(p.roles, ', ') || ') can read every row. Fine for public data like blog posts or products, not for anything private.',
|
|
103
|
+
'If this data is private: replace the policy with one that checks (select auth.uid()) = user_id.'
|
|
104
|
+
from pols p
|
|
105
|
+
where p.schemaname = 'public' and p.permissive = 'PERMISSIVE'
|
|
106
|
+
and p.cmd = 'SELECT' and p.qual = 'true'
|
|
107
|
+
|
|
108
|
+
union all
|
|
109
|
+
-- e. RLS on but no policies: locked for everyone using the API.
|
|
110
|
+
select 'info', 'rls_no_policies', t.qname,
|
|
111
|
+
'Row Level Security is on but there are no policies, so nobody can use this table through the API. Safe, but the app may be broken if it needs this table.',
|
|
112
|
+
'If the app needs this table, add policies for the logged-in owner. If only the server uses it, leave it.'
|
|
113
|
+
from pub_tables t
|
|
114
|
+
where t.rls_on and t.n_policies = 0
|
|
115
|
+
|
|
116
|
+
union all
|
|
117
|
+
-- f. Views that run with the creator's rights skip RLS on the tables they read.
|
|
118
|
+
select 'high', 'view_bypasses_rls', format('public.%I', v.relname),
|
|
119
|
+
'This view reads ' || string_agg(distinct format('public.%I', src.relname), ', ') ||
|
|
120
|
+
' with the owner''s rights, so Row Level Security there is skipped for anyone who can read the view.',
|
|
121
|
+
format('alter view public.%I set (security_invoker = true);', v.relname)
|
|
122
|
+
from pg_class v
|
|
123
|
+
join pg_namespace n on n.oid = v.relnamespace and n.nspname = 'public'
|
|
124
|
+
join pg_rewrite rw on rw.ev_class = v.oid
|
|
125
|
+
join pg_depend d on d.classid = 'pg_rewrite'::regclass and d.objid = rw.oid
|
|
126
|
+
and d.refclassid = 'pg_class'::regclass and d.refobjid <> v.oid
|
|
127
|
+
join pg_class src on src.oid = d.refobjid and src.relrowsecurity
|
|
128
|
+
where v.relkind in ('v', 'm')
|
|
129
|
+
and coalesce(array_to_string(v.reloptions, ','), '') !~* 'security_invoker=(true|on|1|yes)'
|
|
130
|
+
and exists (select 1 from api_roles r where has_table_privilege(r.oid, v.oid, 'select'))
|
|
131
|
+
group by v.relname
|
|
132
|
+
|
|
133
|
+
union all
|
|
134
|
+
-- g. SECURITY DEFINER functions anyone can call: they run with the owner's
|
|
135
|
+
-- rights and skip RLS.
|
|
136
|
+
select 'medium', 'definer_function_anon',
|
|
137
|
+
format('public.%I(%s)', p.proname, pg_get_function_identity_arguments(p.oid)),
|
|
138
|
+
'This function runs with its owner''s rights (SECURITY DEFINER) and visitors who are not logged in can call it.',
|
|
139
|
+
format('revoke execute on function public.%I(%s) from public, anon; -- then grant execute to authenticated if logged-in users need it',
|
|
140
|
+
p.proname, pg_get_function_identity_arguments(p.oid))
|
|
141
|
+
from pg_proc p
|
|
142
|
+
join pg_namespace n on n.oid = p.pronamespace and n.nspname = 'public'
|
|
143
|
+
join api_roles r on r.rolname = 'anon'
|
|
144
|
+
where p.prosecdef
|
|
145
|
+
and has_function_privilege(r.oid, p.oid, 'execute')
|
|
146
|
+
and not exists (select 1 from pg_depend d
|
|
147
|
+
where d.classid = 'pg_proc'::regclass and d.objid = p.oid and d.deptype = 'e')
|
|
148
|
+
|
|
149
|
+
union all
|
|
150
|
+
-- h1. Public storage buckets: every file can be downloaded by anyone with the link.
|
|
151
|
+
-- Read through query_to_xml so the query still runs without a storage schema.
|
|
152
|
+
select 'medium', 'public_bucket', 'storage bucket "' || b.name || '"',
|
|
153
|
+
'This bucket is public: anyone with a file''s link can download it, no login needed. Fine for logos and product photos, not for invoices, IDs or private user files.',
|
|
154
|
+
format('update storage.buckets set public = false where id = %L; -- then serve files with signed URLs', b.id)
|
|
155
|
+
from xmltable('/table/row' passing
|
|
156
|
+
case when to_regclass('storage.buckets') is not null
|
|
157
|
+
then query_to_xml('select id::text as id, name::text as name from storage.buckets where public', true, false, '')
|
|
158
|
+
end
|
|
159
|
+
columns id text path 'id', name text path 'name') as b
|
|
160
|
+
|
|
161
|
+
union all
|
|
162
|
+
-- h2. storage.objects without RLS: every file in every bucket is open.
|
|
163
|
+
select 'high', 'storage_rls_disabled', 'storage.objects',
|
|
164
|
+
'Row Level Security is OFF on storage.objects, so file access rules are ignored for every bucket.',
|
|
165
|
+
'alter table storage.objects enable row level security; -- then add policies per bucket'
|
|
166
|
+
from pg_class c
|
|
167
|
+
join pg_namespace n on n.oid = c.relnamespace and n.nspname = 'storage'
|
|
168
|
+
where c.relname = 'objects' and not c.relrowsecurity
|
|
169
|
+
|
|
170
|
+
union all
|
|
171
|
+
-- h3. storage.objects with RLS on and no policies: uploads through the API are blocked.
|
|
172
|
+
select 'info', 'storage_no_policies', 'storage.objects',
|
|
173
|
+
'File storage has no policies, so logged-in users cannot upload or read files through the API. Safe, but uploads in the app will fail.',
|
|
174
|
+
'If the app uploads files: add policies that limit each user to their own folder, e.g. (storage.foldername(name))[1] = auth.uid()::text.'
|
|
175
|
+
from pg_class c
|
|
176
|
+
join pg_namespace n on n.oid = c.relnamespace and n.nspname = 'storage'
|
|
177
|
+
where c.relname = 'objects' and c.relrowsecurity
|
|
178
|
+
and not exists (select 1 from pg_policy p where p.polrelid = c.oid)
|
|
179
|
+
|
|
180
|
+
union all
|
|
181
|
+
-- i. Sensitive-looking columns that visitors who are not logged in can read:
|
|
182
|
+
-- anon can select the column AND rows are visible (RLS off, or a read
|
|
183
|
+
-- policy with "true" that applies to anon).
|
|
184
|
+
select 'high', 'sensitive_column_exposed', format('%s.%I', t.qname, a.attname),
|
|
185
|
+
'A column named "' || a.attname || '" can be read by visitors who are not logged in.',
|
|
186
|
+
'Move this column to a separate table with no anon access, or store a hash instead. Never send it to the browser.'
|
|
187
|
+
from pub_tables t
|
|
188
|
+
join pg_attribute a on a.attrelid = t.oid and a.attnum > 0 and not a.attisdropped
|
|
189
|
+
join api_roles r on r.rolname = 'anon'
|
|
190
|
+
where a.attname ~* '(^|_)(password|passwd|pwd|token|secret|api_?key|ssn|card|card_?number|credit_?card|cvv|cvc|iban)($|_)'
|
|
191
|
+
and has_column_privilege(r.oid, t.oid, a.attnum, 'select')
|
|
192
|
+
and (
|
|
193
|
+
not t.rls_on
|
|
194
|
+
or exists (select 1 from pols p
|
|
195
|
+
where p.schemaname = 'public' and p.tablename = t.relname
|
|
196
|
+
and p.permissive = 'PERMISSIVE' and p.cmd in ('SELECT', 'ALL')
|
|
197
|
+
and p.qual = 'true'
|
|
198
|
+
and ('anon' = any (p.roles) or 'public' = any (p.roles)))
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
select severity, check_id, object, problem, fix_sql
|
|
202
|
+
from (
|
|
203
|
+
select * from findings
|
|
204
|
+
union all
|
|
205
|
+
select 'info', 'all_checks_passed', '(whole database)',
|
|
206
|
+
'No critical, high or medium problems found. Checked: RLS on public tables, policies that do nothing, open write policies, public read policies, tables locked by RLS, views that skip RLS, SECURITY DEFINER functions, storage buckets and storage rules, sensitive columns.',
|
|
207
|
+
'Also open Supabase dashboard -> Advisors -> Security Advisor for the fuller official check.'
|
|
208
|
+
where not exists (select 1 from findings where severity in ('critical', 'high', 'medium'))
|
|
209
|
+
) result
|
|
210
|
+
order by case severity when 'critical' then 0 when 'high' then 1 when 'medium' then 2 else 3 end,
|
|
211
|
+
check_id, object;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Code cleanup
|
|
2
|
+
|
|
3
|
+
AI tools leave the same mess in every project. None of this is dangerous, but it makes the app look unfinished and harder to change. All items are ⚪ Cleanup unless noted.
|
|
4
|
+
|
|
5
|
+
**The one rule: cleanup never changes what the app does.** If removing something could change behavior, don't remove it. List it as a task for the owner.
|
|
6
|
+
|
|
7
|
+
## C1. Leftover logs and debug lines
|
|
8
|
+
|
|
9
|
+
**Spot it.** `console.log`, `console.debug`, `debugger`, `print(` in server code, `alert(` used for testing. The scanner counts them.
|
|
10
|
+
|
|
11
|
+
**Fix.** Delete them. Keep `console.error` / `console.warn` in real error handlers. 🟡 if a log prints secrets, tokens, passwords or full user objects (S1-level leak into logs).
|
|
12
|
+
|
|
13
|
+
## C2. Fake data shipped as real
|
|
14
|
+
|
|
15
|
+
**Spot it.** `mockData`, `fakeUsers`, `dummy`, `sampleProducts`, "John Doe", "Jane Smith", "Acme Inc", `test@example.com`, "Lorem ipsum", placeholder images (`placehold.co`, `via.placeholder.com`, `picsum.photos`), invented stats ("10,000+ happy customers", "99.9% uptime", fake testimonials and logos).
|
|
16
|
+
|
|
17
|
+
**Fix.** Remove fake data the UI no longer needs, or replace with an empty state. Do not delete invented numbers, testimonials or logos yourself: list them as tasks ("replace with real numbers or remove"). Showing invented customer counts or reviews can be misleading advertising.
|
|
18
|
+
|
|
19
|
+
## C3. Buttons and pages that do nothing
|
|
20
|
+
|
|
21
|
+
**Spot it.** `onClick={() => {}}`, `href="#"`, `// TODO: implement`, `FIXME`, "Coming soon" pages linked from the main nav, forms whose submit handler only `console.log`s, settings toggles not saved anywhere.
|
|
22
|
+
|
|
23
|
+
**Fix.** List each one for the owner: wire it up, hide it, or delete it. Don't guess what it should do.
|
|
24
|
+
|
|
25
|
+
## C4. Dead code
|
|
26
|
+
|
|
27
|
+
**Spot it.** Components, files and functions nothing imports; unused imports and variables; large commented-out blocks; old versions next to new ones (`Header.tsx` and `HeaderNew.tsx`, `utils-old.ts`). Unused packages in `package.json` (check with `npx depcheck` or `npx knip` if the user agrees).
|
|
28
|
+
|
|
29
|
+
**Fix.** Delete what is clearly unused (search the whole project for the name first). If unsure, list it.
|
|
30
|
+
|
|
31
|
+
## C5. The same thing written three times
|
|
32
|
+
|
|
33
|
+
**Spot it.** Several near-identical components (three button styles, two modals), the same helper (`formatDate`, `cn`, `fetcher`) copied into multiple files, three different ways to call the API or the database.
|
|
34
|
+
|
|
35
|
+
**Fix.** Pick the one that is used most, point the others to it, delete the copies. Do this only with permission when it touches more than a few files.
|
|
36
|
+
|
|
37
|
+
## C6. Giant files
|
|
38
|
+
|
|
39
|
+
**Spot it.** Files over ~400 lines, especially a single `page.tsx` or `App.tsx` holding the whole app. The scanner lists them.
|
|
40
|
+
|
|
41
|
+
**Fix.** Don't refactor without asking. Suggest a split ("move the pricing table and FAQ into their own components") and do it only if the user says yes.
|
|
42
|
+
|
|
43
|
+
## C7. Inconsistent naming and structure
|
|
44
|
+
|
|
45
|
+
**Spot it.** Mixed `camelCase` / `snake_case` / `kebab-case` file names, components in random folders, `.js` and `.ts` mixed for no reason.
|
|
46
|
+
|
|
47
|
+
**Fix.** Mention it once in the report as a "later" item. Don't mass-rename before launch.
|
|
48
|
+
|
|
49
|
+
## C8. Missing basics for launch 💡
|
|
50
|
+
|
|
51
|
+
- `README` that still says "Welcome to your Lovable project" or the framework's default text.
|
|
52
|
+
- Default `<title>`, favicon and meta description from the template.
|
|
53
|
+
- No `404` page; no error boundary, so a crash shows a white screen.
|
|
54
|
+
- `.env.example` missing, so the owner can't redeploy on a new machine.
|
|
55
|
+
|
|
56
|
+
List these in the report checklist.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# UI and copy cleanup
|
|
2
|
+
|
|
3
|
+
Make the interface stop looking AI-generated. A good interface is used, not read: keep the words a person needs to act, cut the rest.
|
|
4
|
+
|
|
5
|
+
## The rules of the cut
|
|
6
|
+
|
|
7
|
+
- **Delete first, write little.** If you rewrite, use only facts already in the code: the product's own words, real feature names, real data. Never invent a number, a speed, an integration or a benefit.
|
|
8
|
+
- **Change text and decoration only.** No logic, data, layout or colors (except the surface rules in ui/surface.md, and only if the user asked for visual cleanup).
|
|
9
|
+
- **Never touch accessibility:** keep `aria-label`, `alt`, visible form labels, screen-reader text.
|
|
10
|
+
- **Claims you can't verify** (customer counts, ratings, testimonials, logos): don't edit. List as tasks.
|
|
11
|
+
- **A clean screen is a good result.** If there is nothing to cut, say so and change nothing.
|
|
12
|
+
|
|
13
|
+
Count before and after: `python3 <this-skill-folder>/scripts/count_tells.py <folder>` (add `--surface` for visual rules). It's a rough regex count that also flags fine cases; your reading is the real check.
|
|
14
|
+
|
|
15
|
+
Load more only when needed: [ui/charts.md](ui/charts.md) if the scanner lists a chart library or the screen has charts (U12 to U16); [ui/surface.md](ui/surface.md) only if the user asks for visual cleanup (U17 to U20); [ui/examples.md](ui/examples.md) when unsure how far to cut.
|
|
16
|
+
|
|
17
|
+
## Interface copy
|
|
18
|
+
|
|
19
|
+
- **U1. Eyebrow labels.** Small uppercase text above a heading ("FEATURES", "HOW IT WORKS", "● NEW"). Delete; the heading already says it.
|
|
20
|
+
- **U2. Decorative numbering.** "01 02 03", "01 // Features". Delete unless it's a real ordered process (checkout steps).
|
|
21
|
+
- **U3. Subtitle under everything.** "Analytics / Understand your data better". Keep a subtitle only if it states a fact the heading doesn't.
|
|
22
|
+
- **U4. Explaining the obvious.** "Click the button below to get started", "This chart shows revenue over time". Delete. Error and empty states stay, rewritten as one or two plain sentences: what happened, what to do. No "Oops!".
|
|
23
|
+
- **U5. Leaked design notes.** "(updates in real time)", "(powered by AI)". Delete or move to a tooltip.
|
|
24
|
+
- **U6. Status strings.** "12 items · Updated 2m ago · Synced · v2.1". Keep the one fact the user acts on.
|
|
25
|
+
- **U7. Labeling everything twice.** Placeholder repeating the label, helper text saying what the field obviously is. Keep one cue. Keep real constraints ("At least 12 characters").
|
|
26
|
+
- **U8. Empty slogans.** "Ship faster. Think less.", "Built different.", "One. Big. Thing." Rewrite as one sentence saying what the product does, or delete.
|
|
27
|
+
|
|
28
|
+
Length: card titles and section headings inside the app: 5 words or fewer.
|
|
29
|
+
|
|
30
|
+
## Decoration
|
|
31
|
+
|
|
32
|
+
Real state means the element renders from data (`{isLive && ...}`, a prop, a query). Fixed markup that always shows is decoration.
|
|
33
|
+
|
|
34
|
+
- **U9. Badges without real state.** "LIVE", "NEW", "AI", "Beta", "🔥 Popular" for flavor. Delete unless backed by data.
|
|
35
|
+
- **U10. Fake status dots.** Pulsing green dots next to text, wired to nothing. Delete. (Loading skeletons are fine.)
|
|
36
|
+
- **U11. Decorative emojis and icons.** In headings, buttons, feature lists, and the icon-in-a-colored-square above every feature card. Delete the icon and its box. Keep icons that are the control (icon button with `aria-label`) or that carry meaning.
|
|
37
|
+
|
|
38
|
+
## Copy rules (for every sentence you keep or write)
|
|
39
|
+
|
|
40
|
+
- **AI words:** cut or replace crucial, delve, enhance, seamless, showcase, pivotal, vibrant, landscape, testament, elevate, unlock, empower, revolutionize, cutting-edge, game-changer, leverage, utilize.
|
|
41
|
+
- **Say "is" and "has":** not "serves as", "boasts", "features".
|
|
42
|
+
- **Drop the "Not just X, but Y" frame.** Say the one thing that is true.
|
|
43
|
+
- **No forced groups of three.**
|
|
44
|
+
- **One name per thing.** Not workspace / project / space for the same thing.
|
|
45
|
+
- **No false ranges:** "From startups to enterprises". Name who it's for.
|
|
46
|
+
- **No em dashes** (—) in UI copy; use a period or comma. A lone "—" for an empty value is fine.
|
|
47
|
+
- **Sentence case**, not Title Case.
|
|
48
|
+
- **Cut filler:** "In order to" → "To"; delete "It's important to note that".
|
|
49
|
+
- **Describe the job, not the mood:** "Finance, simplified" → "Send invoices and track who paid". If the sentence fits any other product's page unchanged, cut it.
|
|
50
|
+
- **Active voice, short sentences, no adverbs** (seamlessly, effortlessly), **plain words** (use, help).
|
|
51
|
+
|
|
52
|
+
## Report for this part
|
|
53
|
+
|
|
54
|
+
A small table of rule, before, after. Then **Rewritten** (every string you wrote, old → new, so the owner can check it) and **Tasks** (claims to verify, text from a CMS or translation file, decisions for the owner).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Fix S1: secret keys in the code or in git
|
|
2
|
+
|
|
3
|
+
1. Move the value to `.env.local` (or the hosting dashboard's Environment Variables) and read it with `process.env.NAME` on the server only. No hard-coded fallback: fail at startup if it's missing.
|
|
4
|
+
2. Add to `.gitignore`: `.env`, `.env.*`, and keep `!.env.example` with empty values.
|
|
5
|
+
3. Stop tracking: `git rm --cached .env`.
|
|
6
|
+
4. **Rotate the key** in the provider dashboard (only the owner can). Once a key was in git or a deploy, treat it as public; deleting it from the code is not enough, it stays in git history.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fix S10: file uploads
|
|
2
|
+
|
|
3
|
+
Private bucket + signed URLs with a short expiry; storage policies limiting each user to their own folder (`(storage.foldername(name))[1] = auth.uid()::text`); check size and MIME type (`multer({ limits: { fileSize }, fileFilter })`); generate the file name on the server (`crypto.randomUUID()`).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fix S11: AI features
|
|
2
|
+
|
|
3
|
+
No secrets, codes or logins in prompts. Give tools the smallest permissions, scoped to the current user. Ask the user to confirm before any action that changes data or sends something. Treat model output as untrusted input (S9). Spending cap and rate limit (S8).
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fix S12: leftover debug and test doors
|
|
2
|
+
|
|
3
|
+
Delete seed/debug routes, or protect them with a server-side admin check. Create the first admin with a one-off script run from your own machine, not a public route. Remove test accounts from production. Return a generic error to the browser and log details on the server.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Fix S14: headers, CORS and HTTPS
|
|
2
|
+
|
|
3
|
+
Allow only your own domains when credentials are on (an allowlist checked before reflecting the origin). Add basic headers (Next.js `headers()` in `next.config`, or the host's config):
|
|
4
|
+
```
|
|
5
|
+
Strict-Transport-Security: max-age=63072000; includeSubDomains
|
|
6
|
+
X-Content-Type-Options: nosniff
|
|
7
|
+
Referrer-Policy: strict-origin-when-cross-origin
|
|
8
|
+
X-Frame-Options: DENY
|
|
9
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Fix S2: secret keys sent to the browser
|
|
2
|
+
|
|
3
|
+
Move the call to the server: a Next.js route handler or server action, a Supabase Edge Function, a Netlify/Vercel function. The browser calls your endpoint; only the server holds the key. Then rotate the key (S1).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
// app/api/chat/route.ts (server only)
|
|
7
|
+
import OpenAI from "openai";
|
|
8
|
+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); // no NEXT_PUBLIC_
|
|
9
|
+
export async function POST(req: Request) {
|
|
10
|
+
// check the user is logged in first (S4) and limit usage (S8)
|
|
11
|
+
const { message } = await req.json();
|
|
12
|
+
const r = await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: message }] });
|
|
13
|
+
return Response.json({ reply: r.choices[0].message.content });
|
|
14
|
+
}
|
|
15
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Fix S3: database open to everyone
|
|
2
|
+
|
|
3
|
+
**Supabase.**
|
|
4
|
+
```sql
|
|
5
|
+
alter table public.notes enable row level security;
|
|
6
|
+
|
|
7
|
+
create policy "Users read own notes" on public.notes
|
|
8
|
+
for select to authenticated using ((select auth.uid()) = user_id);
|
|
9
|
+
create policy "Users insert own notes" on public.notes
|
|
10
|
+
for insert to authenticated with check ((select auth.uid()) = user_id);
|
|
11
|
+
create policy "Users update own notes" on public.notes
|
|
12
|
+
for update to authenticated using ((select auth.uid()) = user_id) with check ((select auth.uid()) = user_id);
|
|
13
|
+
create policy "Users delete own notes" on public.notes
|
|
14
|
+
for delete to authenticated using ((select auth.uid()) = user_id);
|
|
15
|
+
```
|
|
16
|
+
Public read-only data (blog posts, products) may have `for select to anon using (true)`, never a write policy for `anon`. To stop users changing their own `role`/`plan`: `revoke update on public.profiles from authenticated; grant update (full_name) on public.profiles to authenticated;`.
|
|
17
|
+
|
|
18
|
+
**Firebase.**
|
|
19
|
+
```
|
|
20
|
+
match /notes/{noteId} {
|
|
21
|
+
allow read, update, delete: if request.auth != null && request.auth.uid == resource.data.userId;
|
|
22
|
+
allow create: if request.auth != null && request.auth.uid == request.resource.data.userId;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
Then ask the owner to rerun the live check.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Fix S4: API routes with no login check
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
export async function POST(req: Request) {
|
|
5
|
+
const supabase = await createClient(); // server client with the user's cookies
|
|
6
|
+
const { data: { user } } = await supabase.auth.getUser();
|
|
7
|
+
if (!user) return new Response("Unauthorized", { status: 401 });
|
|
8
|
+
// ...work only with data that belongs to user.id
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
JWT: `jwt.verify(token, secret, { algorithms: ["HS256"] })`, never `jwt.decode` for auth. Server actions need the same check at the top.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fix S5: users can open other users' data
|
|
2
|
+
|
|
3
|
+
Always filter by owner too: `.eq('id', id).eq('user_id', user.id)`, `findFirst({ where: { id, userId: user.id } })`. With Supabase, prefer the user's own client (RLS applies) over the service-role client. Return 404, not 403, so ids can't be probed.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Fix S6: trusting what the browser says
|
|
2
|
+
|
|
3
|
+
- Look prices up on the server (Stripe Price IDs or your database); the browser sends only a plan name, checked against an allowlist.
|
|
4
|
+
- Take `userId` from the session, never the body.
|
|
5
|
+
- Write only named fields: `data: { name }`, never `data: req.body`.
|
|
6
|
+
- Check admin rights on the server for every admin endpoint, from your database, not from the request.
|
|
7
|
+
- Block users from updating their own `role`/`plan` column (see fixes/S3.md).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Fix S7: payments not verified
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
export async function POST(req: Request) {
|
|
5
|
+
const body = await req.text(); // raw body
|
|
6
|
+
const sig = req.headers.get("stripe-signature")!;
|
|
7
|
+
let event;
|
|
8
|
+
try {
|
|
9
|
+
event = stripe.webhooks.constructEvent(body, sig, process.env.STRIPE_WEBHOOK_SECRET!);
|
|
10
|
+
} catch {
|
|
11
|
+
return new Response("Bad signature", { status: 400 });
|
|
12
|
+
}
|
|
13
|
+
// only now trust event.type / event.data
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
Grant access only from the verified webhook. The success page only shows "thanks, your plan updates in a few seconds".
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Fix S8: no limits
|
|
2
|
+
|
|
3
|
+
Require login for AI endpoints, add a per-user limit, and set a monthly spending cap in the AI provider's dashboard.
|
|
4
|
+
```ts
|
|
5
|
+
import { Ratelimit } from "@upstash/ratelimit";
|
|
6
|
+
import { Redis } from "@upstash/redis";
|
|
7
|
+
const ratelimit = new Ratelimit({ redis: Redis.fromEnv(), limiter: Ratelimit.slidingWindow(20, "1 h") });
|
|
8
|
+
const { success } = await ratelimit.limit(user.id);
|
|
9
|
+
if (!success) return new Response("Too many requests", { status: 429 });
|
|
10
|
+
```
|
|
11
|
+
Express: `express-rate-limit` on login/signup routes. Supabase Edge Functions: a per-user usage table checked before the call.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Fix S9: unsafe HTML and code execution
|
|
2
|
+
|
|
3
|
+
Render as text (React does this by default). If HTML is needed, sanitize it: `DOMPurify.sanitize(html)`, or a Markdown renderer without raw HTML (`react-markdown`). Use parameterized queries (Prisma `findMany`, tagged `$queryRaw`), never `$queryRawUnsafe` with input. Never pass user input to `exec`.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Fixing (load only after the user said yes)
|
|
2
|
+
|
|
3
|
+
1. Suggest a save point first: `git add -A && git commit -m "before lilith fixes"`.
|
|
4
|
+
2. Load only `fixes/S<n>.md` for the checks being fixed. Nothing else.
|
|
5
|
+
3. **Security fixes: one at a time**, most dangerous first. After each, one line on what changed.
|
|
6
|
+
4. **Group fixes of the same kind into one step** (e.g. "add the login check to these 4 routes"), and say the group before starting.
|
|
7
|
+
5. **Mechanical cleanup** (leftover logs, unused imports, trailing debug code): prefer one command or codemod over file-by-file edits, e.g. `npx eslint --fix --rule 'no-console: [error, {allow: [warn, error]}]' src` or `npx knip --fix --fix-type exports,dependencies`. **Never apply a bulk change without first showing the diff summary** (files and line counts, `git diff --stat`) and getting a yes. Keep `console.error`/`console.warn` in real error handlers.
|
|
8
|
+
6. Run the scanner again and show before/after counts.
|
|
9
|
+
7. Things only the owner can do go in a short checklist with exact clicks. Most common: **a leaked key must be rotated (replaced) in the provider's dashboard**; deleting it from the code is not enough, it stays in git history and old deploys.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Security checks (core)
|
|
2
|
+
|
|
3
|
+
The 14 holes AI-built apps have most often. Here: how to spot each one and why it matters. Stack details live in `stacks/` (loaded only for the detected stack). Fix code lives in `fixes/S<n>.md` (loaded only when the user agrees to fix that check).
|
|
4
|
+
|
|
5
|
+
A finding counts only if you can finish **"[who] can [do what] to [whose data or money]"** from the code. If it depends on something you can't see (a dashboard setting, a deployed config), report "worth checking" with the exact thing to look at.
|
|
6
|
+
|
|
7
|
+
## S1. Secret keys in the code or in git 🔴
|
|
8
|
+
**Spot it.** Scanner hits for live keys (`sk_live_`, `sk-proj-`, `sk-ant-`, `AKIA`, `ghp_`, private keys, database URLs with a password, Supabase `service_role` JWTs), hard-coded fallbacks (`process.env.JWT_SECRET || "..."`), `.env` files tracked by git (`git ls-files | grep -i '\.env'`, also `git log --all --oneline -- .env`).
|
|
9
|
+
**Why.** Anyone who sees the repo can use the key: spend your money, read the whole database, sign their own login tokens.
|
|
10
|
+
**Not secrets:** Supabase anon key, Firebase web `apiKey`, Stripe `pk_` key, domain-restricted Maps keys. Their safety comes from S3 and dashboard restrictions.
|
|
11
|
+
|
|
12
|
+
## S2. Secret keys sent to the browser 🔴
|
|
13
|
+
**Spot it.** Env names with a public prefix (`NEXT_PUBLIC_`, `VITE_`, `REACT_APP_`, `EXPO_PUBLIC_`, `PUBLIC_`) holding a secret; secret clients created in browser code (`"use client"` files, React components, any Vite/CRA app with no server).
|
|
14
|
+
**Why.** Everything with these prefixes ships in the JavaScript every visitor downloads.
|
|
15
|
+
|
|
16
|
+
## S3. Database open to everyone 🔴
|
|
17
|
+
**Spot it.** Database rules in migrations or rules files that let anyone read or write; tables with no access rules at all. Details per stack: `stacks/supabase.md`, `stacks/firebase.md`. The live database can differ from the repo: run the live check.
|
|
18
|
+
**Why.** The public client key is in every browser. With open rules it can read, change or delete every row.
|
|
19
|
+
|
|
20
|
+
## S4. API routes with no login check 🔴/🟠
|
|
21
|
+
**Spot it.** Every server entry point (API routes, server actions, edge functions, Express routes) that reads or changes private data without a session check at the top, or with a check that doesn't verify anything (`jwt.decode` instead of `jwt.verify`). Server actions are public endpoints too. Login and signup routes are public by design (check them for S8 instead).
|
|
22
|
+
**Why.** Hiding a button doesn't protect the endpoint. Anyone can call it with curl.
|
|
23
|
+
|
|
24
|
+
## S5. Users can open other users' data 🟠
|
|
25
|
+
**Spot it.** A record loaded by an id from the URL or body with no owner filter (`findUnique({ where: { id } })`, an admin/service client with `.eq('id', params.id)`), or a read rule that lets every logged-in user read every row.
|
|
26
|
+
**Why.** User A changes `/invoices/41` to `/42` and sees user B's invoice.
|
|
27
|
+
|
|
28
|
+
## S6. Trusting what the browser says 🟠
|
|
29
|
+
**Spot it.** The server takes `price`, `amount`, `role`, `isAdmin`, `plan`, `credits`, `userId` from the request; `data: req.body` written straight to the database; admin pages protected only in a React component; users allowed to update their own `role`/`plan` column.
|
|
30
|
+
**Why.** Anyone can edit the request in DevTools and pay $0.01 or set `role: "admin"`.
|
|
31
|
+
|
|
32
|
+
## S7. Payments not verified 🔴
|
|
33
|
+
**Spot it.** Payment webhooks without a signature check; the body parsed as JSON before verifying; premium unlocked in the browser (a success page with `?success=true` that updates the plan).
|
|
34
|
+
**Why.** Anyone can send a fake "payment succeeded" event or open the success URL and get the paid plan.
|
|
35
|
+
|
|
36
|
+
## S8. No limits on expensive or sensitive actions 🟡 (🟠 for AI)
|
|
37
|
+
**Spot it.** No rate limit or per-user cap on AI endpoints, email/SMS sending, login, signup, password reset, OTP, uploads, public forms.
|
|
38
|
+
**Why.** A bot runs up your AI bill overnight, guesses passwords, or sends spam from your domain.
|
|
39
|
+
|
|
40
|
+
## S9. Unsafe HTML and code execution 🟠
|
|
41
|
+
**Spot it.** `dangerouslySetInnerHTML`, `v-html`, `{@html}`, `.innerHTML =`, `eval(`, `new Function(`, Markdown with raw HTML, `exec` with user input, SQL built from strings (`$queryRawUnsafe`, template literals). A finding needs user- or AI-controlled text reaching the sink; static HTML and JSON-LD from your own object are fine.
|
|
42
|
+
**Why.** Other users' browsers run the attacker's script (session theft), or your server runs their SQL/commands.
|
|
43
|
+
|
|
44
|
+
## S10. File uploads 🟡
|
|
45
|
+
**Spot it.** No size or type limit; the user's file name used on disk; public buckets or public folders holding private files (IDs, invoices).
|
|
46
|
+
**Why.** Private documents become downloadable by link; someone uploads a huge file or an HTML page served from your domain.
|
|
47
|
+
|
|
48
|
+
## S11. AI features 🟡/🟠
|
|
49
|
+
**Spot it.** Secrets, internal URLs or logins in system prompts; AI tools that can write data or send things, fed with user or web text; model output passed to `eval`, SQL, shell or raw HTML.
|
|
50
|
+
**Why.** Prompt injection makes the AI act for the attacker, and system prompts can always be extracted.
|
|
51
|
+
|
|
52
|
+
## S12. Leftover debug and test doors 🟡 (🔴 if it grants access)
|
|
53
|
+
**Spot it.** `/api/debug`, `/api/seed`, `/admin/setup` without a server check; routes that return `process.env`; hard-coded test accounts (`admin@admin.com`); stack traces or SQL errors sent to the browser. Test credentials inside test files are fine.
|
|
54
|
+
**Why.** Attackers scan for these paths automatically.
|
|
55
|
+
|
|
56
|
+
## S13. Vulnerable packages 🟡
|
|
57
|
+
**Spot it.** `npm audit --omit=dev` (or pnpm/yarn/pip-audit): report only critical/high in packages used at runtime. No lockfile. Package names that don't exist on npm (AI sometimes invents them).
|
|
58
|
+
**Why.** Bots exploit known holes in old packages.
|
|
59
|
+
|
|
60
|
+
## S14. Headers, CORS and HTTPS 💡 (🟠 for credentialed CORS)
|
|
61
|
+
**Spot it.** Any origin allowed (`*`, `origin: true`, the request origin reflected) **together with** credentials on an API that uses cookies. If auth uses a Bearer header and no cookies, there is no attack path: 💡 at most. Missing security headers are hardening only.
|
|
62
|
+
**Why.** Credentialed CORS that trusts any site lets another website act as the logged-in user.
|
|
63
|
+
|
|
64
|
+
## Only the owner can check (add to the report checklist when relevant)
|
|
65
|
+
- Every leaked key rotated in the provider dashboard; AI provider spending limit set.
|
|
66
|
+
- Production env vars set in the hosting dashboard, not the repo; backups on.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Securing your own server (VPS)
|
|
2
|
+
|
|
3
|
+
Use this only if the user runs the app on their own Linux server (Hetzner, DigitalOcean, OVH, Contabo, AWS EC2...). If they host on Vercel, Netlify, Lovable, Railway or Render, they don't need this: those platforms handle the server.
|
|
4
|
+
|
|
5
|
+
This guide covers the basics. Advanced hardening (Tailscale, Traefik, CrowdSec, backups) is out of scope; say so if the user asks for it.
|
|
6
|
+
|
|
7
|
+
## How to guide
|
|
8
|
+
|
|
9
|
+
- One phase at a time. Never paste the whole guide.
|
|
10
|
+
- Before every command: one line on **what it does and why**.
|
|
11
|
+
- After every phase: ask the user to confirm it worked before moving on.
|
|
12
|
+
- Assume Ubuntu LTS. Commands run on the server unless marked **(on your computer)**.
|
|
13
|
+
|
|
14
|
+
Open with: an unprotected server on the internet gets scanned by bots within minutes. They guess passwords, then use the server for crypto mining or attacks, or steal the data. We'll close the doors in 4 short steps.
|
|
15
|
+
|
|
16
|
+
## Phase 1. Updates and firewall (10 min)
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
sudo apt update && sudo apt upgrade -y
|
|
20
|
+
sudo apt install ufw unattended-upgrades -y
|
|
21
|
+
sudo dpkg-reconfigure -plow unattended-upgrades # choose "Yes": security updates install themselves
|
|
22
|
+
sudo ufw default deny incoming # close every door...
|
|
23
|
+
sudo ufw default allow outgoing
|
|
24
|
+
sudo ufw allow OpenSSH # ...except SSH, or you lock yourself out
|
|
25
|
+
sudo ufw allow 80/tcp && sudo ufw allow 443/tcp # only if this server serves a website
|
|
26
|
+
sudo ufw enable
|
|
27
|
+
```
|
|
28
|
+
Check: `sudo ufw status` shows "Status: active".
|
|
29
|
+
|
|
30
|
+
## Phase 2. Log in with a key, not a password (10 min)
|
|
31
|
+
|
|
32
|
+
A password can be guessed. A key can't.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
ssh-keygen -t ed25519 # (on your computer) skip if you already have a key
|
|
36
|
+
ssh-copy-id user@SERVER_IP # (on your computer)
|
|
37
|
+
```
|
|
38
|
+
**Test before locking:** open a new terminal and run `ssh user@SERVER_IP`. It must log in without asking for the server password. Keep this session open.
|
|
39
|
+
|
|
40
|
+
Then on the server, edit `sudo nano /etc/ssh/sshd_config` and set:
|
|
41
|
+
```
|
|
42
|
+
PermitRootLogin no
|
|
43
|
+
PasswordAuthentication no
|
|
44
|
+
```
|
|
45
|
+
(On recent Ubuntu also check `/etc/ssh/sshd_config.d/*.conf` for a `PasswordAuthentication yes` line that overrides this.)
|
|
46
|
+
```bash
|
|
47
|
+
sudo systemctl restart ssh
|
|
48
|
+
```
|
|
49
|
+
Check: from a new terminal you can still log in. Make sure you know where your provider's **web console** is, as a back door if something goes wrong.
|
|
50
|
+
|
|
51
|
+
## Phase 3. Don't expose what doesn't need to be public (10 min)
|
|
52
|
+
|
|
53
|
+
- Databases (Postgres 5432, MySQL 3306, Redis 6379, MongoDB 27017) must not be open to the internet. Check: `sudo ss -tulpn` and look for `0.0.0.0:5432` or similar. Bind them to `127.0.0.1` or keep them inside a Docker network.
|
|
54
|
+
- **Docker warning:** `ports: - "5432:5432"` in docker-compose opens the port to the world **and skips ufw**. Use `"127.0.0.1:5432:5432"` or remove the `ports` line if only other containers need it.
|
|
55
|
+
- Admin panels (Portainer, pgAdmin, Coolify dashboards): protect with a strong password and, ideally, reach them only through a VPN like Tailscale.
|
|
56
|
+
- Keep `.env` files out of the web root and readable only by the app user: `chmod 600 .env`.
|
|
57
|
+
|
|
58
|
+
## Phase 4. HTTPS and automatic bans (15 min)
|
|
59
|
+
|
|
60
|
+
- HTTPS: use a reverse proxy that gets free certificates automatically (Caddy is the simplest; Traefik or Nginx + Certbot also work).
|
|
61
|
+
- Fail2ban or CrowdSec bans IPs that keep guessing passwords: `sudo apt install fail2ban -y` works out of the box for SSH.
|
|
62
|
+
- Backups: turn on the provider's snapshot backups, and back up the database somewhere else too.
|
|
63
|
+
|
|
64
|
+
## Final check
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
sudo ufw status # active, only the ports you need
|
|
68
|
+
sudo systemctl is-active unattended-upgrades
|
|
69
|
+
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin' # both "no"
|
|
70
|
+
sudo ss -tulpn | grep -v 127.0.0.1 # nothing unexpected listening publicly
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Report what passed and what's left, using the same severity levels as the main report.
|