The short answer
What this means for you
Put every private API key in Lovable Secrets, which are write-only and reach only your backend functions, never in VITE_ variables or browser code. Lovable's logs and Enterprise workspace audit logs do not give you an audit trail of what your own users changed, so add an append-only audit table that is filled by database triggers and closed to client access with Supabase Row Level Security. Never log passwords, tokens, keys, or connection strings. If a key leaks, revoke it at the provider first, then issue a new one and save it as a secret.
- Lovable Secrets are encrypted, write-only, and injected into Edge Functions. Names starting with VITE_ are build-time values exposed in the browser and are rejected in Secrets.
- Lovable's Logs view is for diagnosis. Its workspace audit logs record workspace activity on Enterprise plans, not what your app's users did to your data.
- Build the app audit trail in Postgres: a table with RLS on, no client access, a trigger on each sensitive table, and a second trigger that blocks updates and deletes.
- Supabase already records Auth events. PGAudit can add statement-level database auditing, but logging rows or parameters can expose sensitive values.
- For a leaked key, revoke first. OWASP says exposed keys should be revoked immediately and removed from code and logs.
What is the difference between Lovable's logs, workspace audit logs, and an app audit trail?
Our view: Lovable does not give you a ready-made audit trail of what the people using your app did. It gives you two other things: a Logs view for diagnosis, and workspace audit logs for Enterprise plans. An app audit trail, a record of who changed which record and when, is something you add to your own database.
Lovable's Logs view, found under More, Settings, Logs, offers log types such as Edge Function logs, authentication logs, PostgreSQL logs, and storage logs. You can search, filter, and download or copy the loaded entries as JSON. Lovable does not state how long it keeps logs, and its page says logs are not sufficient audit evidence on their own because they do not prove who made a particular database change.[3]
Lovable's workspace audit logs record activity in the workspace: who acted, when, what changed, and which resource was affected, including project creation and publishing, changes to secrets, and workspace membership. They are available only on Enterprise plans, are kept for about 90 days, and can be exported as a JSONL file. They describe what your team did in Lovable, not what your customers did in your app.[4]
Our view: So you need three layers, each for a different question. Logs answer why something broke. Workspace audit logs answer who on your team changed the project. The app audit trail answers who changed this customer's record.
| Record | Answers | Where it lives | Limit |
|---|---|---|---|
| Lovable Logs | Why did a request or function fail? | More, Settings, Logs | Retention not stated. Not enough as audit evidence. |
| Workspace audit logs | Who on the team changed the project, secrets, or members? | Workspace settings, Security, Audit logs | Enterprise plans only. About 90 days. |
| Supabase Auth audit logs | Who signed in, signed out, or changed credentials? | Supabase dashboard, optionally the auth.audit_log_entries table | Retention not stated in the docs. |
| App audit table (you build it) | Who created, changed, or deleted this record? | Your Postgres database | Only records what your triggers capture. |
Where should API keys live in a Lovable app, and are VITE_ variables secret?
Private API keys belong in Lovable Secrets, used from backend code. VITE_ variables are not secret. Lovable's docs say names starting with VITE_ are build-time values exposed in the browser, and that Lovable rejects VITE_ names in Secrets. Its security page adds that API keys and other secrets cannot be stored safely in client-side code.[1][2]
In Lovable Cloud, the built-in backend, Lovable says secrets are stored per project, encrypted, and injected into your Edge Functions automatically without reaching the browser. They are write-only: the Secrets view shows names and creation dates, and a value can never be viewed again in Lovable, only replaced or deleted. You add one from More, Settings, Secrets with Add secret, or through a secure input in the chat when a feature asks for a key.[1]
If the project connects to your own Supabase project instead of Lovable's built-in backend, secrets are managed in Supabase, not in Lovable. Lovable's Secrets page then shows a Manage secrets button that opens the Supabase dashboard, where the keys live as that project's Edge Function secrets. Check which backend your project uses before you follow the steps below.[1][10]
The pattern that follows is simple. The browser calls your own backend function. The function reads the key from its environment and calls the third-party service. On Supabase, an Edge Function reads a secret with Deno.env.get, and Supabase says functions read a new secret immediately without a redeploy. Secret names cannot start with SUPABASE_.[10]
Some keys are meant for the browser, such as Supabase's publishable key, which is safe only because Row Level Security limits what it can do. Supabase says the secret key bypasses RLS and must never reach a browser. If you are not sure which kind a key is, treat it as private.[10][5]
Supabase Vault is a separate option. It stores encrypted secrets inside Postgres for use in database functions, triggers, and webhooks. Its docs warn that anyone with access to the decrypted_secrets view has access to decrypted secrets, so protect that view. Use Vault when the database itself must call a service. Otherwise keep keys in Edge Function secrets.[9]
How do you move a hard-coded key into Secrets and rotate it?
Treat any key that was ever in browser code, the repository, a chat, or a log as exposed, because anything shipped to the browser can be read by a visitor. Moving it is not enough. You also replace it.
OWASP's secrets guidance says exposed keys should be revoked immediately, and that revoked or rotated secrets must be removed from the exposed system, including secrets found in code or logs. It also cautions that rewriting git history may introduce other problems. Revoking the old key is the real fix, so do not rely on cleaning history.[12]
Lovable's Rotate action applies to its own LOVABLE_API_KEY secret. For other keys, Lovable's docs say a replacement key comes from the service that issued it, which you then save as a secret. Replacing a value in Secrets is possible at any time, and deleting one is permanent and breaks any feature that still needs it.[1]
Lovable's Deep scan reviews application code, including for leaked secrets, and the platform says its tools cannot guarantee complete security. Run it, but do not treat a clean result as proof that no key is exposed.[2]
- 1. List every third-party key the app uses: payments, email, AI providers, maps, analytics, webhooks. Search the code and the repository for each one, including .env files and config.
- 2. At the provider, create a replacement key with the smallest permissions it needs, and note where the old key was used.
- 3. Save the new key as a secret under a clear name, then change the backend function to read it from its environment and the frontend to call that function. In Lovable Cloud, use More, Settings, Secrets. With an external Supabase project, use that project's Edge Function secrets (Lovable's Manage secrets button opens them).
- 4. Deploy and test the feature end to end with the new key.
- 5. Revoke the old key at the provider. Do this even if you deleted it from the code.
- 6. Check the provider's usage and billing dashboards for activity you do not recognize from the exposure window, and note what you find.
- 7. Remove the old key from code, config, and logs. Do not paste keys into chat, issues, or screenshots.
- 8. If a Supabase secret key may have been exposed, rotate it using Supabase's own key documentation, because that key bypasses RLS.
What events should an audit trail record?
OWASP's logging guidance says each record should capture when, where, who, and what: the time, the application or service, the user identity, and the event type with a description. It lists events to log where possible, including authentication successes and failures, authorization failures, access to sensitive data, input validation failures, and use or rotation of cryptographic keys.[11]
OWASP's 2025 list names Security Logging and Alerting Failures as a risk category, and says to log auditable events such as logins, failed logins, and high-value transactions, not only successful logins. It also says to keep logs long enough for delayed forensic analysis.[13]
For a Lovable app, start with a short list: create, update, and delete on tables that hold customer data, money, permissions, or settings; role and permission changes; exports and bulk downloads; admin actions; and failed access attempts you can detect in your own functions. Skip high-volume low-value events such as every page view, which belong in analytics.
Each audit row should hold the time, the acting user's ID, the action, the table, the record ID, and a short description or the names of changed fields. It should not hold secrets or full copies of sensitive records, which is covered below.
How do you build an append-only audit table with Supabase triggers and RLS?
The idea has three parts. A table that stores the records. Row Level Security and revoked grants so browser users cannot read or write it. Triggers that write rows automatically, and that refuse updates and deletes, so a record cannot be quietly changed. OWASP's A09 guidance recommends an audit trail with integrity controls, such as append-only tables.[13]
Supabase's RLS guide says that once RLS is enabled with no policies, no data is accessible through the API with a publishable key. It recommends revoking default grants from anon and authenticated and granting back only what each role needs. For an audit table, grant nothing, and write policies only if you later build an admin view.[5]
Test on a copy first. Triggers are Postgres functions that run when a row changes. Supabase's trigger guide describes a trigger function plus a trigger object, the OLD and NEW row variables, AFTER and BEFORE timing, and row-level or statement-level firing. The statements below are a starting point, not tested here against your project. Ask Lovable to apply them as a database migration, or run them in the SQL editor, on a copy or branch database first. Review them, test them, and only then use them in production.[6]
Supabase's RLS guide shows security definer functions placed in a private schema, outside the schemas the Data API exposes, with an empty search_path so that names cannot be redirected. The functions below follow that pattern, with every object name fully qualified.[5]
Two limits to know. Supabase says the secret key bypasses RLS, which is why the blocking trigger exists, and any highly privileged database role could still drop that trigger. The block below lets a delete through only when it runs as the postgres role, which is how the purge function in the retention section works. Treat the table as tamper-evident, not tamper-proof, and copy rows to storage you control if you need stronger guarantees. OWASP's logging guidance recommends copying log data to read-only media as soon as possible and recording all access to logs.[5][11]
The user ID comes from auth.uid(), which is null for requests that carry no user token, such as a call made with the secret key. Those rows will have an empty actor, so have your own Edge Functions write a row naming the acting user when they change data on a user's behalf.[5]
- Schema and table: create schema if not exists private; create table public.audit_log (id bigint generated always as identity primary key, occurred_at timestamptz not null default now(), actor_id uuid, action text not null, table_name text not null, record_id text, note text);
- Lock it down: alter table public.audit_log enable row level security; revoke all on table public.audit_log from anon, authenticated;
- Recording function: create function private.log_change() returns trigger language plpgsql security definer set search_path = '' as $$ begin insert into public.audit_log (actor_id, action, table_name, record_id) values ((select auth.uid()), tg_op, tg_table_schema || '.' || tg_table_name, coalesce(to_jsonb(new) ->> 'id', to_jsonb(old) ->> 'id')); return null; end; $$;
- Attach it to a sensitive table: create trigger orders_audit after insert or update or delete on public.orders for each row execute function private.log_change();
- Block function: create function private.audit_log_block() returns trigger language plpgsql set search_path = '' as $$ begin if tg_op = 'DELETE' and current_user = 'postgres' then return old; end if; raise exception 'audit_log is append-only'; end; $$;
- Attach the block: create trigger audit_log_no_change before update or delete on public.audit_log for each row execute function private.audit_log_block(); create trigger audit_log_no_truncate before truncate on public.audit_log for each statement execute function private.audit_log_block();
- Purge function, for retention: create function private.purge_audit_log(keep interval) returns bigint language plpgsql security definer set search_path = '' as $$ declare n bigint; begin delete from public.audit_log where occurred_at < now() - keep; get diagnostics n = row_count; insert into public.audit_log (action, table_name, note) values ('PURGE', 'public.audit_log', n || ' rows older than ' || keep); return n; end; $$;
- Close the purge path to app users: revoke execute on function private.purge_audit_log(interval) from public, anon, authenticated;
- Repeat the audit trigger for each table you chose in the previous section. This sketch assumes tables have an id column.
What do Supabase Auth audit logs and PGAudit already give you?
Supabase captures Auth events automatically: sign-ups, sign-ins, password changes and resets, email verification, token refresh, sign-out, and MFA and identity actions. They are viewable in the dashboard, and you can turn on Write audit logs to the database under Authentication, Configuration, Audit Logs to query them with SQL from the auth.audit_log_entries table, at the cost of extra storage. The page does not state a retention period, and the IP address is recorded only for some events.[7]
Depending on how your backend is connected, you reach these through Lovable's Logs view, which has an authentication log type, or through the Supabase dashboard. Check which applies to your project before you plan around it.
PGAudit is a Postgres extension that tracks activity in the database. You enable it from Database, Extensions, or with create extension pgaudit. Its log categories are read, write, function, role, ddl, misc, and all, and it can be set per session, user, or object. Logs appear on the dashboard's Logs page under Postgres, filtered for AUDIT.[8]
PGAudit records statements, not row-level before and after changes, so it complements triggers rather than replacing them. It is a good fit for schema and role changes, for example the ddl and role categories. Supabase warns that global logging can create a lot of log volume, that pgaudit.log_rows can expose sensitive values and reduce performance, and that it does not support pgaudit.log_parameter because it may log secrets in encrypted columns.[8]
What should you never put in logs or audit records?
OWASP lists data that should not be recorded directly in logs: session identification values, access tokens, authentication passwords, database connection strings, encryption keys and other primary secrets, application source code, and bank account or payment card holder data. The guidance is to remove, mask, sanitize, hash, or encrypt such values instead.[11]
OWASP's 2025 category also lists logging sensitive information that should not be logged, such as personal or health information, as a source of leakage, and warns against logging events in ways visible to users or attackers.[13]
For a Lovable app that means: log the user ID, not the email or name when you can avoid it. Log which fields changed, not their old and new values, unless you have decided the values are safe to keep. Never put request bodies, headers, Authorization tokens, or full error objects from payment or AI provider calls into a log without filtering them. When a debug log line prints a key, treat it as a leak and rotate the key.
Privacy rules can limit how long personal data may be kept and who may see it. Decide retention with your legal adviser, because it depends on your country and data.
How do you export logs and keep them long enough?
Lovable's Logs view lets you pick a range from the last 15 minutes up to the last 5 days, and download or copy the loaded entries as JSON. Lovable says the range the viewer offers does not tell you how long it keeps your logs, and it suggests having Lovable build logging or analytics into your app if you need longer retention.[3]
Workspace audit logs on Enterprise plans are kept for about 90 days. Lovable says to use data exports to keep them longer, and finished exports remain downloadable for 7 days.[4]
Your own audit table lives in your database, so its retention is up to you. OWASP's logging guidance says log data must not be destroyed before the required retention period and must not be kept beyond it, and that legal, regulatory, and contractual obligations may change that period. Write down a number, schedule a copy to storage outside the database, and test restoring it.[11]
To enforce the upper limit without opening the table to app users, purge through a controlled privileged path. After you have copied the old rows to storage you control, call private.purge_audit_log with your retention interval from a reviewed migration, the SQL editor, or a scheduled database job running as the postgres role. The function deletes only rows older than the interval and records the purge as its own audit row. Users of the app, and calls made with the secret key, still cannot update or delete anything. Test the purge on the same copy database as the rest of the SQL.
Also protect read access. OWASP says the privileges to read log data should be restricted and reviewed periodically, and that all access to logs should be recorded. In practice, only a small set of admins should read the audit table, through a backend function that checks the caller's role.[11]
How do you check that keys and the audit trail actually work before launch?
Test behavior, not intentions. Lovable's docs say Row Level Security misconfiguration is a common cause of data leaks, and that its scans cannot guarantee complete security. Prove each control with a test you can repeat.[2]
Run Lovable's Deep scan, then do the manual checks below. If the app handles sensitive data or critical functions, Lovable recommends a professional security review. A launch review also covers RLS, keys, webhooks, and backups together, and our sample report shows what such a review looks like.[2]
- Search the built site: open the published app, view the page source and network calls, and confirm no private key, secret key, or service role value appears.
- Search the repository for key prefixes your providers use, and for VITE_ variables that hold anything private.
- In Lovable Cloud, open More, Settings, Secrets and confirm every private key is listed there by name. For an external Supabase project, check the Edge Function secrets in Supabase instead. Confirm no secret is still needed under a VITE_ name.
- Change a record as a normal user and confirm a new audit row appears with that user's ID.
- Using a normal user's session, try to read, insert, update, and delete rows in audit_log and confirm every attempt fails.
- Try to update or delete an audit row as a normal user and with the secret key, and confirm the append-only trigger raises its error. Then run the purge function on the test copy and confirm it deletes only rows past the interval.
- Run a rotation drill on one non-critical key using the steps above, and time it.
- Confirm the log and audit retention numbers are written down, with an owner.
Sources and further reading
- SecretsLovable Docs · Checked 18 November 2026
- Security overviewLovable Docs · Checked 18 November 2026
- LogsLovable Docs · Checked 18 November 2026
- Audit logsLovable Docs · Checked 18 November 2026
- Row Level SecuritySupabase Docs · Checked 18 November 2026
- Postgres TriggersSupabase Docs · Checked 18 November 2026
- Auth Audit LogsSupabase Docs · Checked 18 November 2026
- PGAudit: Postgres AuditingSupabase Docs · Checked 18 November 2026
- VaultSupabase Docs · Checked 18 November 2026
- Environment Variables and Secrets for Edge FunctionsSupabase Docs · Checked 18 November 2026
- Logging Cheat SheetOWASP Cheat Sheet Series · Checked 18 November 2026
- Secrets Management Cheat SheetOWASP Cheat Sheet Series · Checked 18 November 2026
- A09 Security Logging and Alerting Failures - OWASP Top 10:2025OWASP Foundation · Checked 18 November 2026
