<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Victor B Vieira</title>
    <description>The latest articles on DEV Community by Victor B Vieira (@bidu).</description>
    <link>https://dev.to/bidu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4125001%2Ff29b66c5-b49e-4ab3-a5b1-b28e1bfb4e8c.png</url>
      <title>DEV Community: Victor B Vieira</title>
      <link>https://dev.to/bidu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bidu"/>
    <language>en</language>
    <item>
      <title>Designing a Privacy-First Architecture for Sensitive Data: Zero-IP Logging, Postgres RLS, and AI Safety</title>
      <dc:creator>Victor B Vieira</dc:creator>
      <pubDate>Mon, 14 Sep 2026 18:32:41 +0000</pubDate>
      <link>https://dev.to/bidu/designing-a-privacy-first-architecture-for-sensitive-data-zero-ip-logging-postgres-rls-and-ai-3g23</link>
      <guid>https://dev.to/bidu/designing-a-privacy-first-architecture-for-sensitive-data-zero-ip-logging-postgres-rls-and-ai-3g23</guid>
      <description>&lt;p&gt;When building software that handles sensitive human data (like workplace feedback, satisfaction surveys, and compliance reports), security and privacy cannot be treated as optional features or mere legal disclaimers. They must be embedded into the core system design.&lt;/p&gt;

&lt;p&gt;At &lt;strong&gt;Sigilo Profissional&lt;/strong&gt; (&lt;a href="https://sigiloprofissional.com.br" rel="noopener noreferrer"&gt;sigiloprofissional.com.br&lt;/a&gt;), a B2B SaaS platform focused on &lt;strong&gt;Workplace Climate Surveys, eNPS, and Whistleblowing Channels&lt;/strong&gt; compliant with &lt;strong&gt;ISO 37002&lt;/strong&gt; and &lt;strong&gt;GDPR / LGPD&lt;/strong&gt;, privacy is the fundamental prerequisite for psychological safety. If employees do not trust the platform's anonymity, engagement drops to zero.&lt;/p&gt;

&lt;p&gt;Here is a breakdown of the security architecture and privacy controls we implemented in our Python (FastAPI) and PostgreSQL stack.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Dual-Layer Multi-Tenancy (Application + PostgreSQL RLS)
&lt;/h3&gt;

&lt;p&gt;To prevent cross-tenant data leakage, we enforce tenant isolation at two independent layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Application Layer:&lt;/strong&gt; Every query filters by &lt;code&gt;firm_id&lt;/code&gt; within SQLAlchemy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Engine Layer:&lt;/strong&gt; PostgreSQL &lt;strong&gt;Row Level Security (RLS)&lt;/strong&gt; is enabled on all tenant tables. The application middleware sets &lt;code&gt;SET LOCAL app.firm_id&lt;/code&gt; per database session.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Enforcing PostgreSQL Row Level Security (RLS)&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;tenant_complaints&lt;/span&gt; &lt;span class="n"&gt;ENABLE&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt; &lt;span class="k"&gt;LEVEL&lt;/span&gt; &lt;span class="k"&gt;SECURITY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="n"&gt;POLICY&lt;/span&gt; &lt;span class="n"&gt;firm_isolation&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;tenant_complaints&lt;/span&gt;
  &lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firm_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_setting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app.firm_id'&lt;/span&gt;&lt;span class="p"&gt;)::&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Why both?&lt;/em&gt; Even if a bug or missing filter occurs in application code, the database engine natively blocks access to data outside the active tenant context.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Zero-IP Logging Policy &amp;amp; Anonymous Protocol Tokens
&lt;/h3&gt;

&lt;p&gt;To ensure complete whistleblower anonymity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Proxy-Level IP Stripping:&lt;/strong&gt; NGINX and edge proxies strip &lt;code&gt;X-Forwarded-For&lt;/code&gt; and client IP headers. No IP addresses are saved in NGINX logs, application memory, or database records.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cryptographic Tokens:&lt;/strong&gt; Anonymous reports are tracked strictly through random protocol tokens (e.g., &lt;code&gt;SGL-2026-7X3K&lt;/code&gt;). Whistleblowers can check updates using their protocol token without ever creating an account or storing session cookies.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. PII Anonymization for Responsible AI Features
&lt;/h3&gt;

&lt;p&gt;We use Large Language Models (LLMs) to assist employees in structuring clear reports and to summarize qualitative eNPS sentiment for management.&lt;/p&gt;

&lt;p&gt;To prevent sensitive Personally Identifiable Information (PII) from being sent to external AI models:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requests pass through an intermediate LiteLLM proxy layer that sanitizes names, emails, phone numbers, and location metadata before dispatching prompts.&lt;/li&gt;
&lt;li&gt;AI outputs are strictly used for guidance and categorization, never for autonomous decision-making.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. Immutable Audit Trails
&lt;/h3&gt;

&lt;p&gt;Compliance frameworks (such as ISO 37002) require full auditability for compliance officers. We maintain immutable audit logs for administrative actions (e.g., status updates, report triage) using cryptographic hashing, ensuring complete transparency without compromising whistleblower anonymity.&lt;/p&gt;




&lt;h3&gt;
  
  
  💬 Community Question: What Are We Missing?
&lt;/h3&gt;

&lt;p&gt;As we continue scaling our engineering stack, we are reviewing our security roadmap.&lt;/p&gt;

&lt;p&gt;We would love feedback from the Dev.to community:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What automated query auditing or key rotation strategies do you recommend for multi-tenant Postgres RLS at scale?&lt;/li&gt;
&lt;li&gt;Have you implemented additional client-side payload encryption patterns that balance searchability with absolute zero-knowledge privacy?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking forward to your thoughts and suggestions in the comments!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Victor Vieira&lt;/strong&gt; | CTO &amp;amp; Co-founder @ &lt;a href="https://sigiloprofissional.com.br" rel="noopener noreferrer"&gt;Sigilo Profissional&lt;/a&gt;&lt;br&gt;
🔗 &lt;a href="https://www.linkedin.com/in/victorbvieira/" rel="noopener noreferrer"&gt;LinkedIn: Victor Vieira&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>privacy</category>
      <category>python</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
