<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Arthur Monney on Medium]]></title>
        <description><![CDATA[Stories by Arthur Monney on Medium]]></description>
        <link>https://medium.com/@arthurmonney?source=rss-a8058a2667d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UTiyzI4iRKRqjBuPncHFew.jpeg</url>
            <title>Stories by Arthur Monney on Medium</title>
            <link>https://medium.com/@arthurmonney?source=rss-a8058a2667d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:33:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arthurmonney/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Server-Side Request Forgery: Exploiting and Fixing the SSRF Vulnerability]]></title>
            <link>https://medium.com/@arthurmonney/server-side-request-forgery-exploiting-and-fixing-the-ssrf-vulnerability-94f33eed32c3?source=rss-a8058a2667d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/94f33eed32c3</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[ssrf]]></category>
            <dc:creator><![CDATA[Arthur Monney]]></dc:creator>
            <pubDate>Tue, 14 Jul 2026 12:52:09 GMT</pubDate>
            <atom:updated>2026-07-14T12:52:09.066Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HU9jVBQP-f3WFz8tQaf2kg.png" /></figure><p><em>SSRF (Server-Side Request Forgery) makes your own server send requests you never intended, all the way into your internal network. A feature as mundane as a “URL” field is enough to open the breach. This article shows how the vulnerability works, how it’s exploited in practice, and how to fix it layer by layer.</em></p><h4><strong>The context</strong></h4><p>For the past few weeks, I’ve been building an addon for <a href="https://laravelshopper.dev/"><strong>Shopper</strong></a>, a headless e-commerce solution built on <a href="https://laravel.com/">Laravel</a>. The addon’s goal: migrate an existing store to Shopper from any e-commerce platform (Shopify, PrestaShop, Magento, WooCommerce, and so on). I designed it as <strong>multi-source</strong> from day one, with a generic connector layer where each platform provides its own implementation of a shared interface. In short: one contract, several drivers.</p><p>The first connector I shipped targets <strong>WooCommerce</strong>. On paper it’s trivial: the merchant enters their store URL, an API key and secret, and the connector queries the WooCommerce REST API to pull products, categories, variants, images and customers before recreating them on the Shopper side.</p><p>The HTTP client at the heart of that driver looked like this:</p><pre>final class WooCommerceClient<br>{<br>    public function __construct(<br>        private string $storeUrl,<br>        private string $consumerKey,<br>        private string $consumerSecret,<br>    ) {}<br><br>    public function testConnection(): Response<br>    {<br>        return Http::withBasicAuth($this-&gt;consumerKey, $this-&gt;consumerSecret)<br>            -&gt;get(&quot;{$this-&gt;storeUrl}/wp-json/wc/v3/products&quot;, [&#39;per_page&#39; =&gt; 1]);<br>    }<br>}</pre><p>On the UI side, a Livewire component that passed the merchant-supplied URL straight into the client’s constructor:</p><pre>public function testConnection(): void<br>{<br>    $client = new WooCommerceClient(<br>        storeUrl: $this-&gt;storeUrl,        // user-supplied<br>        consumerKey: $this-&gt;consumerKey,<br>        consumerSecret: $this-&gt;consumerSecret,<br>    );<br><br>    $client-&gt;testConnection();<br>}</pre><p>Nothing fancy so far. It worked, the tests were green, I was pleased with myself.</p><p>Before cutting a release, I ran an architecture and security review over the whole addon with <a href="https://claude.ai/">Claude Code</a>. Among the findings, one line caught my eye:</p><blockquote><strong>SSRF</strong><em>: the server makes an HTTP request to a URL entirely controlled by the user. An attacker can target internal services.</em></blockquote><p>My first reaction: <em>”SSRF? You mean CSRF, right?”</em></p><p>Well, no. And that’s exactly what this article is about.</p><h4><strong>CSRF vs SSRF: what’s the difference?</strong></h4><p>The two acronyms look almost identical, but they attack opposite things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1RqCWhdHFs7wgDesac5jIQ.png" /></figure><p>Laravel has covered me against CSRF forever without me thinking about it: the `<strong>VerifyCsrfToken</strong>` middleware, the `<strong>@csrf</strong>` directive, the token checked on every POST. Built in, transparent, you end up forgetting it’s even running.</p><p><strong>SSRF</strong>, on the other hand, has no middleware handling it by default, and that’s logical: the framework can’t guess that <em>this particular</em> outgoing request is hostile. It’s your business code that decides to go fetch a user-supplied URL. The safeguard is yours to write.</p><h4><strong>What an SSRF actually is</strong></h4><p>Let’s start from the definition F5 lays out in its <a href="https://www.f5.com/glossary/ssrf">SSRF glossary</a>:</p><blockquote><em>”A security flaw that occurs when an attacker manipulates a web application or API into making requests to internal resources.”</em></blockquote><p>The word that matters: <strong>server-side</strong>. Normally, when a user wants to reach a resource, it’s <em>their</em> browser that sends the request, and that browser is stuck outside, in front of your firewall. With an SSRF, the request comes from <em>your</em> server. And your server runs inside the network, with direct access to internal services.</p><p>Look at the typical infrastructure of a production app:</p><pre>Internet --[ firewall ]--&gt; Laravel app --+--&gt; 169.254.169.254   (cloud metadata)<br>                                         +--&gt; 10.0.0.5:6379     (internal Redis)<br>                                         +--&gt; 10.0.0.8:5432     (PostgreSQL)<br>                                         +--&gt; 10.0.0.9/admin    (internal dashboards)</pre><p>The firewall blocks traffic coming from the Internet toward the internal network. But your app talks to the internal side all day long, that’s its job. So if an attacker controls the URL it calls out to, they use your server as a proxy to cross that firewall. F5 puts it well:</p><blockquote><em>”The request is made from the server’s perspective, not the user’s browser, which allows bypassing the protections offered by firewalls and VPNs.”</em></blockquote><p>In security, this is the <strong>confused deputy</strong> pattern: a trusted component, here your server, performs an action on behalf of someone who had no right to do it themselves.</p><h4><strong>How my addon could be exploited</strong></h4><p>Back to that “store URL” field. Zero validation. The value went straight into an outgoing HTTP request made by the server. Here’s what an attacker could do with it.</p><h4><strong>Steal cloud credentials</strong></h4><p>The scenario that really hurts. On AWS, GCP or Azure, every instance exposes a metadata service on a fixed IP that isn’t routable from the outside: `169.254.169.254`. On AWS, that endpoint serves the instance’s temporary IAM credentials:</p><pre>http://169.254.169.254/latest/meta-data/iam/security-credentials/</pre><p>All an attacker had to do was paste this into my “store URL” field:</p><pre>http://169.254.169.254/latest/meta-data/iam/security-credentials/</pre><p>My server would query that endpoint from its privileged position and hand me back, potentially, the instance’s AWS access keys. With those keys the attacker moves on: S3 buckets, databases, anything the IAM role allows.</p><p>Not theoretical. It’s the exact mechanism behind the <a href="https://www.darktrace.com/blog/back-to-square-one-the-capital-one-breach-proved-we-must-rethink-cloud-security"><strong>Capital One breach</strong></a><strong> of 2019</strong>: an SSRF read the IMDS credentials, which opened access to more than 100 million customer records. All because of one unvalidated outgoing request.</p><h4><strong>Scan and reach internal services</strong></h4><p>Even without a cloud, the attacker targets the machine itself or the local network:</p><pre>http://localhost:6379          -&gt; talks to Redis in cleartext<br>http://127.0.0.1:9200          -&gt; internal Elasticsearch<br>http://10.0.0.9/admin          -&gt; an internal dashboard with no external auth<br>http://192.168.1.1             -&gt; the router&#39;s interface</pre><p>Each entry becomes a request my server runs <em>from the inside</em>, under the firewall that was supposed to isolate those services.</p><h4><strong>The “I don’t return the response body” trap: blind SSRF</strong></h4><p>The comforting thought: <em>”Either way I don’t display the response body, just connection succeeded or failed.”</em> I had it. False sense of security.</p><p>F5 lists three variants, and two of them work fine without the response:</p><p>- <strong>Standard SSRF.</strong> The response comes back to the attacker. The worst case.</p><p>- <strong>Blind SSRF.</strong> The response is never shown, but an error message that changes leaks the information. “Failed” on a closed port versus “unexpected response” on an open port, and the attacker maps the internal network, service by service.</p><p>- <strong>Time-based blind SSRF.</strong> Even without an exploitable message, a host that answers in 5 ms versus a 30 s timeout gives away what exists. They read the network with a stopwatch.</p><p>My little “Test connection” button, which returned nothing more than <em>success</em>, <em>failed</em> or <em>unreachable</em>, was already enough to mount a blind SSRF. The “it doesn’t return anything sensitive” argument no longer held.</p><h4><strong>How to fix it: layered validation</strong></h4><p>Good news on the implementation side: everything went through a single choke point. All my outgoing requests were built in the same client method. One place to hook the validation in. Here’s how I built it, layer by layer.</p><h4><strong>Layer 1: allow HTTPS only</strong></h4><p>An attacker won’t necessarily stick to `http://`. Depending on the HTTP client, schemes like `file://`, `gopher://`, `dict://` or `ftp://` open up other abuses: reading local files, forging requests to other protocols. We lock it down with an allowlist, here HTTPS only.</p><pre>if (! str_starts_with(strtolower($url), &#39;https://&#39;)) {<br>    throw new MigrationException(&#39;The store URL must use HTTPS.&#39;);<br>}</pre><h4><strong>Layer 2: reject private and reserved IPs</strong></h4><p>The core of the defense against direct attacks. PHP has exactly the right tool, `filter_var` with two flags:</p><pre>$host = strtolower(parse_url(https://medium.com/$url,%20PHP_URL_HOST) ?? &#39;&#39;);<br><br>if (filter_var($host, FILTER_VALIDATE_IP)) {<br>    $isPublic = filter_var(<br>        $host,<br>        FILTER_VALIDATE_IP,<br>        FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE<br>    );<br><br>    if (! $isPublic) {<br>        throw new MigrationException(&quot;Forbidden host: {$host}.&quot;);<br>    }<br>}</pre><p>`FILTER_FLAG_NO_PRIV_RANGE` clears the private ranges: `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`. `FILTER_FLAG_NO_RES_RANGE` clears the reserved ones, which includes the loopback `127.0.0.0/8` and, crucially, `169.254.0.0/16`.</p><p>That second flag is the key piece: `169.254.169.254` falls in the reserved range, so the cloud metadata endpoint is blocked outright. The most dangerous attack drops with a single line.</p><h4><strong>Layer 3: block internal hostnames</strong></h4><p>A literal IP isn’t the only way in. `localhost` and the usual internal DNS suffixes must be refused too:</p><pre>if ($host === &#39;localhost&#39;<br>    || str_ends_with($host, &#39;.localhost&#39;)<br>    || str_ends_with($host, &#39;.local&#39;)<br>    || str_ends_with($host, &#39;.internal&#39;)) {   // e.g. metadata.google.internal<br>    throw new MigrationException(&quot;Forbidden host: {$host}.&quot;);<br>}</pre><h4><strong>Layer 4: don’t follow redirects blindly</strong></h4><p>The trap that struck me the most, because it short-circuits everything above. An attacker supplies a perfectly clean URL:</p><pre>https://my-trap-store.com    &lt;- passes all validation</pre><p>Except the server behind that URL answers with:</p><pre>HTTP/1.1 302 Found<br>Location: http://169.254.169.254/latest/meta-data/...</pre><p>By default, most HTTP clients, including <a href="https://docs.guzzlephp.org/en/stable/">Guzzle</a> under the hood of Laravel’s `Http` facade, follow redirects. Your check validated the starting URL, then Guzzle followed the 302 to the internal target. Your entire initial validation just went out the window.</p><p>The fix: re-validate every redirect hop and forbid any downgrade to `http`.</p><pre>Http::baseUrl($this-&gt;storeUrl)<br>    -&gt;withOptions([<br>        &#39;allow_redirects&#39; =&gt; [<br>            &#39;max&#39; =&gt; 5,<br>            &#39;strict&#39; =&gt; true,<br>            &#39;protocols&#39; =&gt; [&#39;https&#39;],          // no downgrade to http<br>            &#39;on_redirect&#39; =&gt; function ($request, $response, $uri): void {<br>                // Re-run the exact same validation on the destination URL.<br>                $this-&gt;assertSafeUrl((string) $uri);<br>            },<br>        ],<br>    ])<br>    -&gt;get(&#39;/wp-json/wc/v3/products&#39;);</pre><p>By pulling the validation into an `assertSafeUrl()` method, I replay it in the constructor and on every hop, through Guzzle’s `on_redirect` callback. The store can no longer bounce the server toward an internal target.</p><h4><strong>The honest residual: DNS rebinding and IP pinning</strong></h4><p>Let’s be clear, otherwise it’d be dishonest. The layers above stop all direct attacks: hard-coded internal IP, `localhost`, booby-trapped redirect. That’s by far the most common case, the one in F5’s example.</p><p>One nastier vector remains: <strong>DNS rebinding</strong>. The attacker owns a domain `trap.com` which, at the moment you validate it, resolves to a public IP. So it passes validation. But between your check and the actual connection, they flip their DNS record to `169.254.169.254`. You validated a <em>name</em>, but the client connects to an <em>IP</em> resolved afterward. This is a TOCTOU, Time-Of-Check to Time-Of-Use.</p><p>The only complete fix: resolve the DNS yourself at connection time, validate the resulting IP, then pin it so the connection goes exactly there, via curl’s `CURLOPT_RESOLVE` option. Heavier, and only worth it if the feature is exposed to untrusted users.</p><p>In my case, the migration is locked behind authentication and a dedicated permission (`migrator.create`): to reach it, you already have to be a logged-in administrator. The cost-benefit ratio didn’t justify IP pinning. So I documented it in the code, with the upgrade path, for the day the threat model changes. That, to me, is proportionate security: close what’s actually reachable, and document the rest instead of pretending it doesn’t exist.</p><h4><strong>Don’t just close the app: defense in depth</strong></h4><p>Application-level validation is your first line, not your only one. F5 stresses complementary layers that hold regardless of your stack.</p><p>1. <strong>Network segmentation and egress proxy.</strong> An egress firewall that forbids your application servers from reaching `169.254.0.0/16` and the private ranges. Even if an SSRF gets past the app, it hits the network wall.</p><p>2. <strong>IMDSv2 on AWS.</strong> Version 2 of the metadata service requires a session token fetched with a `PUT` request and limits the network hop count. Most SSRFs, which can only issue a `GET`, are neutralized. Turn it on.</p><p>3. <strong>WAF.</strong> An application firewall filters known malicious URL patterns.</p><p>4. <strong>Least privilege.</strong> If the instance’s IAM role has access to nothing sensitive, stealing its credentials is barely worth anything.</p><p>An SSRF that has to get past the app, then the network, only to land on a role with no privileges at all, is worth nothing anymore. That’s the whole point of stacking layers instead of betting everything on one.</p><h4><strong>The real lesson: does my server fetch a user-supplied URL?</strong></h4><p>If there’s one question to take away from this review, it’s that one. SSRF doesn’t only concern migration connectors. The moment your server makes a network request to an address, a host or a URL that comes, even indirectly, from a user, you have a potential SSRF on your hands.</p><p>Run your projects through that filter. The features involved are far more numerous than you’d think:</p><ul><li><strong>Webhooks</strong> the user configures (“call this URL when this event happens”)</li><li><strong>Import an image or file by URL**</strong> (“paste your avatar link”).</li><li><strong>Link previews</strong>, like Slack unfurling a URL pasted in a message.</li><li><strong>PDF or screenshot generators</strong> via a headless browser. Those are particularly dangerous: a browser follows redirects and executes JavaScript.</li><li><strong>SSO or SAML metadata URLs</strong> to fetch.</li><li><strong>RSS readers, aggregators and oEmbed</strong>.</li><li>Any <strong>proxy</strong> or endpoint of the “go fetch this resource for me” kind.</li></ul><p>For each one, the same checklist:</p><ul><li>Restrict the scheme with an allowlist, HTTPS and possibly HTTP.</li><li>Reject private and reserved IPs with `FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE`.</li><li>Reject internal hostnames like `localhost`, `.local` or `.internal`.</li><li>Re-validate redirects and forbid downgrading to HTTP.</li><li>If the surface touches untrusted users, resolve then pin the IP at connection time.</li><li>Add network-level defense in depth: egress proxy, IMDSv2, least privilege.</li></ul><p>The best move is to pull that validation into a reusable component, a `SafeUrlValidator` or a dedicated Laravel validation rule, and wire it in everywhere a user URL turns into an outgoing request. Written once, reused everywhere.</p><h4><strong>Epilogue</strong></h4><p>I’ve been coding for years. CSRF, SQL injection, XSS, I had those covered. SSRF, though, was a blind spot: one of those risks you don’t know because you’ve never run into them, and never run into because you’re not looking for them.</p><p>What struck me most wasn’t the vulnerability, it was how I found it. A code review pointed at a line I’d been re-reading for weeks without seeing anything wrong. Not because a tool is “smarter” than me, but because it didn’t share my blind spot. It put a name on a risk I couldn’t name, and that name let me go read, understand, then fix it knowingly, instead of pasting a magic patch I didn’t understand.</p><p>Maybe that’s where the real value of these tools lies: not replacing your judgment, but shining a light on what your experience hasn’t taught you to see yet.</p><p>If this article introduced you to SSRF the way that review introduced it to me, do one thing. Open your project, find the next place where your server fetches a URL a user handed it, and ask yourself the question.</p><p>Further reading: <a href="https://www.f5.com/glossary/ssrf">F5, Server-Side Request Forgery</a>, <a href="https://owasp.org/www-community/attacks/Server_Side_Request_Forgery">OWASP, Server-Side Request Forgery</a>, <a href="https://www.php.net/manual/en/filter.filters.flags.php">PHP, filter_var flags</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94f33eed32c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[static $variable in PHP: a silent trap with Laravel Octane]]></title>
            <link>https://medium.com/@arthurmonney/static-variable-in-php-a-silent-trap-with-laravel-octane-3a51013a0aa9?source=rss-a8058a2667d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a51013a0aa9</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-octane]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Arthur Monney]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 12:39:56 GMT</pubDate>
            <atom:updated>2026-03-07T12:39:56.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XI3r4w-WhaDFgmXlzd9r4Q.jpeg" /></figure><p>When working with <a href="https://laravel.com/">Laravel</a> without Octane, some coding habits seem harmless. But as soon as you switch to Octane, they can cause bugs that are hard to reproduce and even harder to debug in production.</p><p>That’s exactly what happened to me with a simple static variable in a helper.</p><h3>The context</h3><p>In my application, I had a current_tax_label() helper whose job is to return the applicable tax label for the user based on their geographic zone (VAT inc. or VAT exc.).</p><p>To avoid recomputing the value multiple times within the same request, I used a classic memoization technique:</p><pre>function current_tax_label(): string  <br><br>{  <br><br> static $label = null;  <br><br> if ($label !== null) { return $label; }  <br><br> $zone = ZoneSessionManager::getSession();  <br><br> if (! $zone instanceof CountryByZoneData) { return $label = &#39;&#39;; }  <br><br> $taxZone = TaxZone::query() -&gt;whereHas(&#39;country&#39;, fn ($q) =&gt; $q-&gt;where(&#39;cca2&#39;, $zone-&gt;countryCode)) -&gt;whereNull(&#39;province_code&#39;) -&gt;first();  <br><br> return $label = $taxZone?-&gt;is_tax_inclusive ? __(&#39;VAT inc.&#39;) : __(&#39;VAT exc.&#39;);}</pre><p>In classic PHP, this code is perfectly fine. The static $label variable is initialized to null on every new request and memoized for the duration of that request.</p><h3>Why it works in classic PHP</h3><p>In standard PHP (Apache, PHP-FPM), each HTTP request starts a <strong>new PHP process</strong> from scratch. All memory is freed at the end of the request. So static $label is properly reset to null every time.</p><pre>Request 1 → new process → $label = null → computed → &#39;VAT inc.&#39; ✅  <br><br>Request 2 → new process → $label = null → computed → &#39;VAT exc.&#39; ✅</pre><h3>Why it becomes a bug with Octane</h3><p><a href="https://laravel.com/docs/octane">Laravel Octane</a> (with <a href="https://frankenphp.dev/">FrankenPHP</a> or <a href="https://github.com/swoole/swoole-src">Swoole</a>) works differently. The application is loaded <strong>once into memory</strong> and workers stay alive permanently to handle incoming requests. There is no longer a “new process” for each request.</p><p>The problem: <strong>static variables are never reset</strong> between requests in the same worker. They hold their value indefinitely.</p><pre>Worker 1 — Request A (user in France, EUR zone)<br>  → $label is null → computed → $label = &#39;VAT inc.&#39;<br><br>Worker 1 — Request B (user in Cameroon, XAF zone)<br>  → $label is already &#39;VAT inc.&#39; (from the previous user!)<br>  → returns &#39;VAT inc.&#39; without recomputing<br>  → ❌ wrong label displayed</pre><p>The Cameroonian user sees the French user’s label. And depending on the order requests arrive, it can flip the other way. The bug is <strong>random</strong>, <strong>silent</strong>, and <strong>throws no error</strong>.</p><p>It’s worth noting that this has nothing to do with sessions. The session belongs to the user each user has their own. The static variable belongs to the <strong>Octane worker</strong> it is shared across all requests handled by that worker, regardless of who sent them. The user&#39;s session can be perfectly correct while the function still returns the wrong result.</p><h3>The important distinction</h3><p>Many developers confuse the different uses of the static keyword in PHP. Here is what causes problems and what does not:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*BuG1KnGlNpM3cFTXG59i7A@2x.png" /></figure><p>The rule: it’s not the static keyword on a <strong>method</strong> that causes problems it&#39;s the static keyword on a <strong>variable</strong>, because it is mutable and persists inside the worker.</p><h3>The fix</h3><p>The solution is straightforward: remove the memoization. The cost of one extra SQL query is negligible compared to the risk of serving incorrect data in production.</p><pre>function current_tax_label(): string<br>{<br>    $zone = ZoneSessionManager::getSession();<br><br>    if (! $zone instanceof CountryByZoneData) {<br>        return &#39;&#39;;<br>    }<br><br>    $taxZone = TaxZone::query()<br>        -&gt;whereHas(&#39;country&#39;, fn ($q) =&gt; $q-&gt;where(&#39;cca2&#39;, $zone-&gt;countryCode))<br>        -&gt;whereNull(&#39;province_code&#39;)<br>        -&gt;first();<br><br>    return $taxZone?-&gt;is_tax_inclusive ? __(&#39;VAT inc.&#39;) : __(&#39;VAT exc.&#39;);<br>}</pre><p>If performance is a real concern, the right approach with Octane is to use the <strong>Laravel cache</strong> (Cache::remember(...)) keyed on a request or session identifier — not a global static variable.</p><h3>Key takeaways</h3><p>If you’re using Laravel Octane, audit your code for:</p><ul><li>static $variable inside functions or helpers</li><li>static class properties that are mutated at runtime</li><li>Singletons that store user- or request-bound state</li></ul><p>These patterns are common and work perfectly fine without Octane. With Octane, they become ticking time bombs.</p><p><em>This bug was discovered during an architectural review of a </em><a href="https://demo.laravelshopper.dev/"><em>multi-zone e-commerce</em></a><em> application built on </em><a href="https://laravelshopper.dev/"><em>Laravel Shopper</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a51013a0aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Route Model Binding and Multi-Tenancy in Laravel: Resolving the Conflict with forgetParameter()]]></title>
            <link>https://medium.com/@arthurmonney/route-model-binding-and-multi-tenancy-in-laravel-resolving-the-conflict-with-forgetparameter-cb0176d12f02?source=rss-a8058a2667d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb0176d12f02</guid>
            <category><![CDATA[multitenancy]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[routing]]></category>
            <dc:creator><![CDATA[Arthur Monney]]></dc:creator>
            <pubDate>Wed, 11 Feb 2026 21:12:16 GMT</pubDate>
            <atom:updated>2026-02-11T21:23:27.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MnypSYFZ9VttTlcMkXtgZw.jpeg" /></figure><p>While working on a multi-tenant SaaS application, I ran into a bug I had never seen in years of working with Laravel. A `TypeError` appeared out of nowhere after what seemed like a harmless refactoring. Digging into the cause, I discovered a method I had never used before: `forgetParameter()`.</p><p>Here’s the context, the problem, and most importantly the Laravel internals that explain everything.</p><p>## The context</p><p>The application is a SaaS where each merchant has a store accessible via a slug in the URL:</p><pre>https://store.mydomain.com/store/{url}/products<br>https://store.mydomain.com/store/{url}/settings<br>https://store.mydomain.com/store/{url}/settings/payout-connections/{payoutConnection}</pre><p>The <strong>{url}</strong> parameter identifies the tenant. A middleware <strong>InitializeTenancyByUrl</strong> intercepts every request, resolves the store, and makes it available through a <strong>store()</strong> helper:</p><pre>class InitializeTenancyByUrl<br>{<br>    public function handle(Request $request, Closure $next): Response<br>    {<br>        $storeUrl = $request-&gt;url;<br><br>        $tenant = $this-&gt;resolve($storeUrl);<br><br>        $this-&gt;registerTenant($tenant);<br><br>        URL::defaults([&#39;url&#39; =&gt; $tenant-&gt;url]);<br><br>        // Share the store with Inertia, Ziggy, etc.<br><br>        return $next($request);<br>    }<br>}</pre><p><strong>URL::defaults([‘url’ =&gt; $tenant-&gt;url])</strong> ensures that <strong>route()</strong> and <strong>to_route()</strong> automatically fill in the <strong>{url}</strong> parameter without having to pass it manually. On the frontend side, Ziggy receives the same default.</p><p>## The code before refactoring</p><p>Every controller received `<strong>string $url</strong>` as its first parameter, even though none of them ever used it:</p><pre>final class StorePayoutConnectionController<br>{<br>    public function destroy(string $url, StorePayoutConnection $payoutConnection): RedirectResponse<br>    {<br>        // $url is never used here<br>        // The store is resolved via store()<br><br>        $payoutConnection-&gt;delete();<br><br>        return to_route(&#39;store.sellers.settings&#39;, [&#39;url&#39; =&gt; $url]);<br>    }<br>}</pre><p>Two unnecessary things here:</p><p>- <strong>string $url</strong> is never read, the store is already resolved by the middleware</p><p>- `<strong>[‘url’ =&gt; $url]</strong>` in `to_route()` is redundant thanks to `<strong>URL::defaults()</strong>`</p><p>The code worked, but it was noise. So I decided to clean this up across all controllers.</p><p>## The refactoring</p><p>Simple on the surface. Remove <strong>string $url</strong> from the signature and `<strong>[‘url’ =&gt; $url]</strong>` from redirects:</p><pre>public function destroy(StorePayoutConnection $payoutConnection): RedirectResponse<br>{<br>    $payoutConnection-&gt;delete();<br><br>    return to_route(&#39;store.sellers.settings&#39;);<br>}</pre><p>Clean. Tests pass on most controllers.</p><p>Except one.</p><p>## The bug</p><pre>TypeError: StorePayoutConnectionController::destroy():<br>Argument #1 ($payoutConnection) must be of type StorePayoutConnection, string given</pre><p>Laravel is passing a string (the store slug) where it should pass an Eloquent model. Route model binding no longer works.</p><p>Yet I didn’t touch the route, the middleware, or the model. I just removed an unused parameter.</p><p>## What happens inside Laravel</p><p>To understand this, you need to look at how Laravel dispatches controllers. The key file is `<strong>Illuminate\Routing\ControllerDispatcher</strong>`:</p><pre>// vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php<br><br>public function dispatch(Route $route, $controller, $method)<br>{<br>    $parameters = $this-&gt;resolveClassMethodDependencies(<br>        $route-&gt;parametersWithoutNulls(),<br>        $controller,<br>        $method<br>    );<br><br>    return $controller-&gt;{$method}(...array_values($parameters));<br>}</pre><p>The important line is `array_values($parameters)`. This method <strong>**strips the associative keys**</strong> and converts the array to numeric indices. The parameters are then passed to the controller <strong>**by position, not by name**</strong>.</p><p>Concretely, for the route `<strong>/{url}/store/settings/payout-connections/{payoutConnection}</strong>`, the route parameters after the `<strong>SubstituteBindings</strong>` middleware are:</p><pre>[<br>    &#39;url&#39; =&gt; &#39;my-store&#39;,                          // string (the slug)<br>    &#39;payoutConnection&#39; =&gt; StorePayoutConnection#1  // model resolved by binding<br>]</pre><p>After `array_values()`:</p><pre>[<br>    0 =&gt; &#39;my-store&#39;,<br>    1 =&gt; StorePayoutConnection#1<br>]</pre><p>### Before (with `string $url`)</p><pre>public function destroy(string $url, StorePayoutConnection $payoutConnection)<br>//                      position 0 ✓   position 1 ✓<br>//                      &#39;my-store&#39;      StorePayoutConnection#1</pre><p>Each parameter receives the right value. `string $url` absorbs position 0, the model lands at position 1.</p><p>### After (without `string $url`)</p><pre>public function destroy(StorePayoutConnection $payoutConnection)<br>//                      position 0 ✗<br>//                      &#39;my-store&#39; ← string instead of the model</pre><p>The model does exist at position 1, but there’s no one to receive it. Position 0 sends the store slug to the `<strong>$payoutConnection</strong>` parameter. Hence the `<strong>TypeError</strong>`.</p><p>## The solution: `<strong>forgetParameter()</strong>`</p><p>The `<strong>Route::forgetParameter()</strong>` method removes a parameter from the route’s parameter bag. If you call it in the middleware after resolving the tenant, the `url` parameter no longer exists at dispatch time:</p><pre>class InitializeTenancyByUrl<br>{<br>    public function handle(Request $request, Closure $next): Response<br>    {<br>        $storeUrl = $request-&gt;url;<br>        $tenant = $this-&gt;resolve($storeUrl);<br><br>        $this-&gt;registerTenant($tenant);<br><br>        URL::defaults([&#39;url&#39; =&gt; $tenant-&gt;url]);<br><br>        $request-&gt;route()?-&gt;forgetParameter(&#39;url&#39;);<br><br>        // ...<br><br>        return $next($request);<br>    }<br>}</pre><p>Now, when the controller is dispatched:</p><pre>$route-&gt;parametersWithoutNulls()<br>// [&#39;payoutConnection&#39; =&gt; StorePayoutConnection#1]<br><br>array_values($parameters)<br>// [0 =&gt; StorePayoutConnection#1]</pre><p>The model is at position 0. The controller receives it correctly.</p><p>## Why it’s safe</p><p>At this point you might wonder: aren’t we breaking something by removing this parameter?</p><p>No, because the `{url}` parameter has already served its purpose at three levels:</p><p>1. <strong>**Routing**</strong> — Laravel matched the incoming URL to the correct route. Done.</p><p>2. <strong>**Tenant resolution**</strong> — The middleware resolved the store and registered it via `<strong>tenant()-&gt;setTenant()</strong>`. The `<strong>store()</strong>` helper works.</p><p>3. <strong>**URL generation**</strong> — `URL::defaults()` and Ziggy defaults ensure that `route()` (both PHP and JS) automatically fill in `{url}`.</p><p>The parameter has no use once the middleware has run.</p><p>## When this problem occurs</p><p>This bug doesn’t appear on every controller. Two conditions must be met:</p><p>1. The route contains a <strong>**prefix parameter not used**</strong> by the controller (here `{url}`)</p><p>2. The route contains <strong>**another parameter**</strong> with route model binding (here `{payoutConnection}`, `{product:public_id}`, etc.)</p><p>If the controller has no route model binding (for example `__invoke(StoreProductRequest $request)`), there’s no conflict. The `FormRequest` is resolved via the service container, not from route parameters.</p><p>## What I take away from this</p><p>After years of working with Laravel and even after getting certified, I had never needed `forgetParameter()`. It’s the kind of method that lives in the framework, well documented in the source code, but that you only encounter in specific scenarios like multi-tenancy.</p><p>What this experience reminded me: when a bug seems irrational, the answer is often in the framework’s source code. Here, a single line in `ControllerDispatcher.php` — `array_values($parameters)` — explains the entire behavior.</p><p>If you’re building a multi-tenant application with a URL prefix resolved by middleware, consider `forgetParameter()`. It will save you from keeping dead parameters in your controllers just to make positional dispatch work.</p><p>Shalom.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb0176d12f02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Send Transactional Emails and SMS using Brevo with Laravel ?]]></title>
            <link>https://medium.com/yield-studio/how-to-send-transactional-emails-and-sms-using-brevo-with-laravel-f0fcf14a26f5?source=rss-a8058a2667d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0fcf14a26f5</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Arthur Monney]]></dc:creator>
            <pubDate>Tue, 03 Sep 2024 13:14:46 GMT</pubDate>
            <atom:updated>2024-09-03T13:23:30.335Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Send Transactional Emails and SMS using Brevo with Laravel ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qpvxO8PBGTjx-M0Kb5NCBw.jpeg" /></figure><p>If you’re developing a SaaS application, a social network, a marketplace, or a business application, you’ll probably want to send transactional emails or SMS to your users.</p><p>A transactional message is an automated message that provides users with useful information designed to help them improve their experience. Common examples include order confirmations, meeting reminders and two-factor authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIg5X4G8MomExAHYtXP7ig.jpeg" /><figcaption>Example of an email and a transactional SMS</figcaption></figure><p>Sending transactional emails and SMS with <a href="https://laravel.com/">Laravel</a> is very easy, thanks to the <a href="https://laravel.com/docs/notifications">Notifications</a> component.</p><p>Laravel provides support for some channels: SMTP, Vonage and Slack. Developers can then make their own channels and share them as community packages.</p><p>That&#39;s what we&#39;ve done at Yield Studio by developing packages for <a href="https://github.com/YieldStudio/laravel-brevo-notifier">Brevo</a>, <a href="https://github.com/YieldStudio/laravel-mailjet-notifier">Mailjet</a> and <a href="https://github.com/YieldStudio/laravel-expo-notifier">Expo</a> !</p><p>In this step-by-step tutorial, we&#39;ll show you how to send transactional emails and SMS messages with <a href="https://github.com/YieldStudio/laravel-brevo-notifier">yieldstudio/laravel-brevo-notifier</a> !</p><h3>Step 1 : Create A Brevo Account</h3><p>To get started, you’ll need to <a href="https://onboarding.brevo.com/account/register">create a Brevo account</a> and verify your email address. After that you can go to the <a href="https://app.brevo.com/">dashboard</a>.</p><p>Brevo’s Free plan lets you send up to 300 e-mails a day. For SMS you’ll need to load your account with SMS credits. For example, a pack of 100 SMS credits to United States costs $1.</p><h3>Step 2 : Install Laravel Brevo Notifier</h3><p>Once you’ve created your Brevo account, we can continue with the installation.</p><pre>composer require yieldstudio/laravel-brevo-notifier</pre><p>Once the installation is complete, we can head to .env file and add the following key with your own value.</p><pre>BREVO_KEY=your-brevo-key<br>BREVO_SMS_SENDER=Yield<br><br># Laravel variables<br>MAIL_FROM_ADDRESS=hello@yieldstudio.fr<br>MAIL_FROM_NAME=&quot;Yield Studio&quot;</pre><p>The BREVO_KEY value can be found on your dashboard <a href="https://app.brevo.com/settings/keys/api">SMTP and API</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDKCi3AcOHrhwNZ_ybJvJA.png" /><figcaption>Create an API key on Brevo</figcaption></figure><p>The value of BREVO_SMS_SENDER is limited to 11 alphanumeric or 15 numeric characters. This is the sender your user will see when sending the SMS (Yield, Amazon, IKEA).</p><h3>Step 3 : Authenticate Your Senders</h3><p>With Brevo, as with many providers, email addresses used to send emails must be authenticated. You can authenticate a specific email address or a domain name directly.</p><p>Go to <a href="https://app.brevo.com/senders/list">Senders, domains and dedicated IPs</a> and add the e-mail addresses or domains you’ll be using to send e-mails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-J1b1HM7MmQebPzn6qnk3A.png" /><figcaption>List of authorized senders on Brevo</figcaption></figure><h3>Step 4 : Generate Notification</h3><p>Create a class for your notification, you can use the Artisan command below, for example we create an OrderShipped notification</p><pre>php artisan make:notification OrderShipped</pre><p>This will generate the class in App\\Notifications folder. If we don’t have the folder yet, Laravel will create one for us.</p><h3>Step 5 : Send Email And SMS</h3><p>Then make sure to change the method return via to add our BrevoSmsChannel and/or BrevoEmailChannel.</p><pre>namespace App\Notifications;<br><br>use Illuminate\Notifications\Notification;<br>use YieldStudio\LaravelBrevoNotifier\BrevoSmsChannel;<br>use YieldStudio\LaravelBrevoNotifier\BrevoEmailChannel;<br><br>class OrderShipped extends Notification<br>{<br>    public function via(): array<br>    {<br>        return [BrevoSmsChannel::class, BrevoEmailChannel::class];<br>    } <br>}</pre><p>You can then prepare your notification by adding the toBrevoSms and/or toBrevoEmail method.</p><pre>namespace App\Notifications;<br><br>use Illuminate\Notifications\Notification;<br>use YieldStudio\LaravelBrevoNotifier\BrevoSmsMessage;<br>use YieldStudio\LaravelBrevoNotifier\BrevoEmailMessage;<br><br>class OrderShipped extends Notification<br>{<br>    public function __construct(private Order $order) {}<br>  <br>    // ...<br>    <br>    public function toBrevoSms($notifiable): BrevoSmsMessage<br>    {<br>        return (new BrevoSmsMessage())<br>            -&gt;to($notifiable-&gt;phone)<br>            -&gt;content(&#39;The order n°&#39; . $this-&gt;order-&gt;number . &#39; has been shipped.&#39;);<br>    }<br><br>    public function toBrevoEmail($notifiable): BrevoEmailMessage<br>    {<br>        return (new BrevoEmailMessage())<br>            -&gt;templateId(1)<br>            -&gt;to($notifiable-&gt;firstname, $notifiable-&gt;email)<br>            -&gt;params([&#39;order_number&#39; =&gt; $this-&gt;order-&gt;number]);<br>    }<br>}</pre><p>To send a transactional email with Brevo, you’ll need to create <a href="https://app.brevo.com/templates/listing">Templates</a>.</p><p>You can now send your notification from your controller, a listener or wherever is most appropriate in your case:</p><pre>namespace App\Http\Controllers;<br><br>use App\Notifications\SendSMSMessageNotification;<br>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\Auth;<br><br>final class MarkOrderAsShipped extends Controller<br>{<br>    public function __invoke(Request $request, Order $order)<br>    {<br>        // ...<br>        $request-&gt;user-&gt;notify(new OrderShipped($order));<br>        // ...<br>    }<br>}</pre><p>And voilà, you’ve sent your first notification with Brevo ⚡</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*1KrBJcR6cNbTMchzg1lHqQ.gif" /></figure><h3>Conclusion</h3><p>And that’s it, sending a transactional email or SMS with Brevo from a Laravel application is very easy. First create a Brevo account, install the yieldstudio/laravel-brevo-notifier package, configure and send your superb notification.</p><p>You can go even further by adding cc, bcc, attachments (an invoice, for example) and more.</p><p>Feel free to test this package and contribute on <a href="https://github.com/YieldStudio/laravel-brevo-notifier">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0fcf14a26f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yield-studio/how-to-send-transactional-emails-and-sms-using-brevo-with-laravel-f0fcf14a26f5">How to Send Transactional Emails and SMS using Brevo with Laravel ?</a> was originally published in <a href="https://medium.com/yield-studio">The Yield Studio Playbook</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>