---
title: "Security best practices for RShift Sites apps"
description: "<p>This page focuses on <strong>how to write secure code for RShift Sites apps</strong> and avoid common security mistakes during development.</p>\n<p>For details on RShift Sites’s security model, security scans, and find"
---

> Documentation Index
> Fetch the complete documentation index at: https://rshift.helpcent.re/llms.txt
> Use this file to discover all available pages before exploring further.

# Security best practices for RShift Sites apps

<p>This page focuses on <strong>how to write secure code for RShift Sites apps</strong> and avoid common security mistakes during development.</p>
<p>For details on RShift Sites’s security model, security scans, and findings, see <a href="/sites/features/security/">Security overview</a>, <a href="/sites/features/security-view/">Project security view</a>, and the <a href="/sites/features/security-center/">Workspace security center</a>.</p>
<h2>How RShift Sites apps are structured</h2>
<p>RShift Sites apps are built with a clear separation of responsibilities:</p>
<ul>
<li><strong>Frontend</strong> runs in the user’s browser, is always public, and must never be trusted</li>
<li><strong>Edge Functions</strong> run server-side and handle validation, authentication, and business logic</li>
<li><strong>Database</strong> uses PostgreSQL with row-level security (RLS) to enforce data access</li>
</ul>
<p>This separation is the foundation of RShift Sites’s security model. The sections below follow this structure and highlight common security mistakes at each layer and how to avoid them.</p>
<h2>Frontend security basics</h2>
<p>All frontend code runs in the user’s browser and can be inspected, modified, or bypassed. Frontend code should never make security decisions.</p>
<h3>Do not store secrets in frontend code</h3>
<p>Store sensitive values in <a href="/sites/features/secrets/">Secrets</a> instead, which also explains what belongs in <code>.env</code> versus a secret.</p>
<p>Secrets stored in frontend code are visible to users and should be considered compromised.</p>
<pre><code class="language-typescript">// ❌ Wrong: secrets exposed to anyone
const API_KEY = "sk-1234567890abcdef";
const STRIPE_SECRET = "sk_live_...";
</code></pre>
<p><strong>Instead</strong>: Ask RShift Sites to add secrets securely. Secrets are stored in backend infrastructure and accessed only from Edge Functions.</p>
<p><strong>Example prompts</strong></p>
<pre><code class="language-text">Add an API key for Stripe payments securely without exposing it in the frontend code
</code></pre>
<pre><code class="language-text">Review frontend code for exposed secrets, API keys, or sensitive information
</code></pre>
<h3>Do not rely on frontend validation for security</h3>
<p>Frontend validation improves user experience but provides no security guarantees.</p>
<pre><code class="language-typescript">// ❌ Wrong: client-side validation can be bypassed
const validateUser = (userData) =&gt; userData.email.includes("@");
</code></pre>
<p><strong>Instead</strong>: Validate and sanitize all data in Edge Functions where checks cannot be bypassed.</p>
<p><strong>Always treat client input as untrusted.</strong> Validate formats, enforce business rules, and sanitize inputs in <strong>Edge Functions</strong> before processing or storing data.</p>
<p><strong>Example prompts</strong></p>
<pre><code class="language-text">Move validation logic from React components to Edge Functions for better security
</code></pre>
<pre><code class="language-text">Identify client-side validation that should be moved to backend Edge Functions
</code></pre>
<h2>Backend security with Edge Functions</h2>
<p>Edge Functions form the secure boundary between your public frontend and your private systems. They run in an isolated server-side environment where sensitive logic cannot be accessed or modified by users.</p>
<p>Any logic that affects security, data integrity, or external services should run in Edge Functions, not in frontend components. Centralizing validation and authorization here ensures every request is evaluated consistently and prevents critical logic from reaching the browser.</p>
<p>Edge Functions should handle:</p>
<ul>
<li><strong>Authentication and authorization</strong><br>
Verify who is making a request and whether they are allowed to perform the action.</li>
<li><strong>Data validation and sanitization</strong><br>
Treat all input as untrusted and enforce business rules consistently.</li>
<li><strong>Business logic and workflows</strong><br>
Handle multi-step processes like registrations, payments, approvals, and state transitions.</li>
<li><strong>Integration with external services</strong><br>
Call third-party APIs securely and keep credentials out of the browser.</li>
<li><strong>Sensitive data processing</strong><br>
Process personal or financial data safely, avoid exposing it unintentionally, and log important security events.</li>
</ul>
<p>Keeping this logic server-side ensures critical behavior never reaches the browser and that every request is evaluated consistently.</p>
<p><strong>Example prompts</strong></p>
<pre><code class="language-text">Create an Edge Function for user registration with proper validation and security checks
</code></pre>
<pre><code class="language-text">Move payment processing logic from frontend to a secure Edge Function
</code></pre>
<pre><code class="language-text">Build an Edge Function for file uploads with type and size validation
</code></pre>
<h2>Database security with RLS</h2>
<p>You can inspect every policy in your project under <strong>More → Cloud → Database → RLS policies</strong> (<a href="/sites/features/database/#row-level-security-rls-policies">details</a>).</p>
<p>Row-level security (RLS) controls who can read or modify individual rows in your database. It acts as a final layer of protection, enforcing access rules even if frontend or backend logic fails.</p>
<p>RShift Sites sets up basic RLS policies automatically, but you should review and adjust them early in development. RLS is much easier to change before real data exists, and policies are most effective when they stay focused on access control rather than complex business logic.</p>
<h3>Common RLS patterns</h3>
<p>Most RShift Sites apps fit into a small set of access patterns:</p>
<ul>
<li><strong>Personal data</strong>: users can access only their own data</li>
<li><strong>Team-based access</strong>: team members share access to team data</li>
<li><strong>Public content with ownership</strong>: anyone can read, only owners can modify</li>
<li><strong>Organization-based access</strong>: users access data within their organization</li>
</ul>
<p>Design your tables and policies around these patterns whenever possible.</p>
<h3>RLS checks before publishing</h3>
<p>Before going live, verify:</p>
<ul>
<li>RLS is enabled on all sensitive tables</li>
<li>Users cannot access other users’ private data</li>
<li>Shared and public data behaves as intended</li>
<li>New tables are not missing policies</li>
</ul>
<p>Review RLS related findings in <a href="/sites/features/security-view/">Project security view</a>.</p>
<p><strong>Example prompts</strong></p>
<pre><code class="language-text">Review RLS policies to ensure users can only access their own data and shared data is properly protected
</code></pre>
<pre><code class="language-text">Add RLS policies to the settings table so users can only access their own settings
</code></pre>
<pre><code class="language-text">Set up RLS for teams and projects so team members only see projects from their team
</code></pre>
<h2>Authentication security basics</h2>
<p>All authentication decisions must happen server-side, not in the browser. Client-side authentication checks can be inspected, modified, or bypassed by users and should never be relied on for access control.</p>
<p>Authentication should be enforced in <strong>Edge Functions</strong>, where sessions and tokens can be verified securely and consistently.</p>
<pre><code class="language-typescript">// ❌ Wrong: client-side authentication checks
const isAuthenticated = localStorage.getItem("authToken") !== null;
if (isAuthenticated) showAdminPanel();
</code></pre>
<pre><code class="language-typescript">// ✅ Correct: server-side validation in an Edge Function
const { user } = await supabase.auth.getUser();
if (!user) {
  return new Response("Unauthorized", { status: 401 });
}
</code></pre>
<p><strong>Authentication best practices</strong></p>
<ul>
<li>Validate authentication and session tokens in Edge Functions</li>
<li>Check roles and permissions server-side</li>
<li>Use built-in session management for secure token handling</li>
<li>Redirect users to login when sessions expire, but always validate on the server first</li>
<li>Use frontend auth state only to control UI, never to enforce access</li>
</ul>
<h2>Workspace security</h2>
<p>For applications that should not be publicly accessible:</p>
<ul>
<li>Set <a href="/sites/features/project-visibility/">project access</a> to <strong>workspace</strong></li>
<li>Verify the app is not <a href="/sites/features/publish/">published</a> publicly</li>
<li>Require authentication even for internal tools</li>
<li>Regularly audit who has access</li>
</ul>
<p>For workspace-wide monitoring, use the <a href="/sites/features/security-center/">Security center</a>.</p>
<h2>Security checklist before publishing</h2>
<p>Before publishing your app, confirm:</p>
<ul>
<li>No secrets exist in frontend code</li>
<li>All validation and critical logic runs in Edge Functions</li>
<li>Row-level security (RLS) policies are configured and tested</li>
<li>Authentication is enforced server-side</li>
<li>Internal apps have workspace visibility</li>
<li>All critical findings in the <a href="/sites/features/security-view/">Security view</a> are addressed</li>
<li>External API calls happen server-side</li>
</ul>
<blockquote>
<p><strong>Tip</strong></p>
<p><strong>Security is an ongoing process</strong>.</p>
<p>Review these practices whenever you add features, change authentication, modify data access, or introduce new external integrations.</p>
<p>Regularly reviewing Edge Functions, row-level security policies, and authentication flows helps prevent regressions over time.</p>
</blockquote>
<h2>Related topics</h2>
<ul>
<li><a href="/sites/features/security-view/">Project security view</a></li>
<li><a href="/sites/features/security/">Security overview</a></li>
<li><a href="/sites/features/security-center/">Workspace security center</a></li>
<li><a href="/sites/features/payments/">Add payments to your app</a></li>
<li><a href="/sites/features/chat-mode/">Prompting best practices</a></li>
</ul>

Source: https://rshift.helpcent.re/sites/tips-tricks/security-best-practices/index.mdx
