<?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: Ayush</title>
    <description>The latest articles on DEV Community by Ayush (@e4ayush).</description>
    <link>https://dev.to/e4ayush</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%2F4272787%2F00609a9a-c5ab-45ec-beb9-06427fa4f8b2.png</url>
      <title>DEV Community: Ayush</title>
      <link>https://dev.to/e4ayush</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/e4ayush"/>
    <language>en</language>
    <item>
      <title>The fix nobody recorded: a gap in Flagsmith's audit log I found during a hackathon</title>
      <dc:creator>Ayush</dc:creator>
      <pubDate>Sun, 29 Nov 2026 18:14:16 +0000</pubDate>
      <link>https://dev.to/e4ayush/the-fix-nobody-recorded-a-gap-in-flagsmiths-audit-log-i-found-during-a-hackathon-41n1</link>
      <guid>https://dev.to/e4ayush/the-fix-nobody-recorded-a-gap-in-flagsmiths-audit-log-i-found-during-a-hackathon-41n1</guid>
      <description>&lt;p&gt;Last week I built &lt;a href="https://github.com/Ayush-e4/flagtrail" rel="noopener noreferrer"&gt;flagtrail&lt;/a&gt; for Toggle Wars, the Flagsmith hackathon run by WeMakeDevs. It's an audit trail for self-hosted Flagsmith that the database can't quietly edit. While testing it I hit something I didn't expect: the change that &lt;em&gt;fixes&lt;/em&gt; an incident is the one Flagsmith's audit log doesn't record.&lt;/p&gt;

&lt;p&gt;Here's the 3-minute demo, then what happened, why, and how I caught it.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/LW7BcaE8MB0" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem I started with
&lt;/h2&gt;

&lt;p&gt;If you self-host Flagsmith, your flags and your audit log are both ordinary rows in Postgres. That's fine until someone with database access changes a flag directly. It could be a DBA, a bad migration script, or a leaked credential.&lt;/p&gt;

&lt;p&gt;A direct &lt;code&gt;UPDATE&lt;/code&gt; like that goes around Flagsmith completely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;customers start getting the new value right away&lt;/li&gt;
&lt;li&gt;no audit record is written&lt;/li&gt;
&lt;li&gt;no webhook fires&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And since the audit log is just a table too, the same access can edit the history of what happened.&lt;/p&gt;

&lt;p&gt;For most apps that's an edge case. For a bank or a payments company, it's the exact question an auditor asks: &lt;em&gt;show me every change, who made it, and prove nobody altered the record.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So I built flagtrail to watch Flagsmith from the outside.&lt;/p&gt;

&lt;h2&gt;
  
  
  How flagtrail watches
&lt;/h2&gt;

&lt;p&gt;It compares three sources that are hard to fake all at once:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What Flagsmith reports&lt;/strong&gt;: its signed webhooks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What Flagsmith actually serves&lt;/strong&gt;: every environment's environment document, read every few seconds through the Admin API.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What Flagsmith's audit table admits&lt;/strong&gt;: read through a read-only Postgres role.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Everything goes into an append-only Merkle log with signed checkpoints (RFC 9162, the same design Certificate Transparency uses for HTTPS certificates). If anyone edits or deletes an old entry, every later proof breaks.&lt;/p&gt;

&lt;p&gt;When the sources disagree (the served value changed but there's no webhook and no audit row), it raises a &lt;code&gt;SILENT_CHANGE&lt;/code&gt; alert within seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The demo incident
&lt;/h2&gt;

&lt;p&gt;My test case was a made-up bank. In the demo, someone raises &lt;code&gt;daily_transfer_limit&lt;/code&gt; from 50,000 to 500,000 straight in the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;features_featurestatevalue&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;integer_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500000&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;feature_state_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;flagtrail caught that, as designed. Then I fixed it the normal way, through Flagsmith:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flagsmith flag update daily_transfer_limit -e &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;env key&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --value 50000 --type integer --yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And flagtrail raised &lt;strong&gt;another&lt;/strong&gt; alert, this time about the fix.&lt;/p&gt;

&lt;p&gt;My first thought was that my code was wrong. It wasn't.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's actually going on
&lt;/h2&gt;

&lt;p&gt;I reproduced it on Flagsmith 2.294.0:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An ordinary value change through Flagsmith, by a person in the dashboard or an API key, &lt;strong&gt;is&lt;/strong&gt; audited and sends a webhook. Good.&lt;/li&gt;
&lt;li&gt;But after a direct database write, &lt;strong&gt;the change that restores the value writes no audit record and sends no webhook&lt;/strong&gt;. That holds whether you fix it in the dashboard, through the Admin API or with the CLI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cause is in how Flagsmith decides something changed. It builds the audit record from the difference between the new history row (&lt;code&gt;features_historicalfeaturestatevalue&lt;/code&gt;) and the previous one. The direct database write never created a history row. So Flagsmith sees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;previous history row: 50000
new history row:      50000   -&amp;gt; "no change", skip the audit record and the webhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's comparing with what it &lt;em&gt;last recorded&lt;/em&gt;, not with what was actually in the database a moment ago.&lt;/p&gt;

&lt;p&gt;So in a real incident, the audit log misses both the bad change (expected, it bypassed Flagsmith) &lt;strong&gt;and&lt;/strong&gt; the fix (not expected). The one moment you most need the record is the moment it's empty.&lt;/p&gt;

&lt;p&gt;I reported it upstream with a full reproduction: &lt;a href="https://github.com/Flagsmith/flagsmith/issues/9185" rel="noopener noreferrer"&gt;Flagsmith#9185&lt;/a&gt;. The suggested fix is small: compare with the value actually stored before the save, not with the last history row.&lt;/p&gt;

&lt;p&gt;flagtrail still records the fix, because it doesn't trust the audit log alone. It watches what's actually served.&lt;/p&gt;

&lt;h2&gt;
  
  
  Letting an agent handle the incident
&lt;/h2&gt;

&lt;p&gt;The other half of the project is an MCP server (14 read-only tools) and an Agent Skill that takes an incident from alert to postmortem with the Flagsmith CLI.&lt;/p&gt;

&lt;p&gt;I ran it in Claude Code against the demo incident. It found the database write and worked out who was affected (34 of 40 customers on the $500,000 limit). Then it proposed one exact CLI command to fix it and stopped until I said yes. After the fix, it checked the result in Flagsmith and in what customers were actually served.&lt;/p&gt;

&lt;p&gt;It also hit the unrecorded fix, which is why the skill now tells the agent to expect that alert and sign it with an explanation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;It's MIT licensed and installs in one line, either fresh with demo data or beside your existing Flagsmith:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -fsSL https://raw.githubusercontent.com/Ayush-e4/flagtrail/main/install.sh &lt;span class="o"&gt;|&lt;/span&gt; sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's also a read-only replay of the console you can click around without installing anything: &lt;a href="https://ayush-e4.github.io/flagtrail/console/" rel="noopener noreferrer"&gt;ayush-e4.github.io/flagtrail/console&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/Ayush-e4/flagtrail" rel="noopener noreferrer"&gt;github.com/Ayush-e4/flagtrail&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The upstream issue: &lt;a href="https://github.com/Flagsmith/flagsmith/issues/9185" rel="noopener noreferrer"&gt;Flagsmith#9185&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you self-host Flagsmith (or any flag service) and have dealt with audit requirements, I'd love to hear how you handle out-of-band changes today.&lt;/p&gt;

</description>
      <category>security</category>
      <category>opensource</category>
      <category>devops</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
