<?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: Felipe</title>
    <description>The latest articles on DEV Community by Felipe (@fredericrypto).</description>
    <link>https://dev.to/fredericrypto</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%2F4120424%2Fd4c2292b-5251-477a-9bad-16bdf9ad9660.png</url>
      <title>DEV Community: Felipe</title>
      <link>https://dev.to/fredericrypto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fredericrypto"/>
    <language>en</language>
    <item>
      <title>The Microsoft Outage Just Exposed the Biggest Blind Spot in Modern AppSec</title>
      <dc:creator>Felipe</dc:creator>
      <pubDate>Sun, 15 Nov 2026 00:27:49 +0000</pubDate>
      <link>https://dev.to/fredericrypto/the-microsoft-outage-just-exposed-the-biggest-blind-spot-in-modern-appsec-22jh</link>
      <guid>https://dev.to/fredericrypto/the-microsoft-outage-just-exposed-the-biggest-blind-spot-in-modern-appsec-22jh</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Microsoft 365 outage of 12–14 November 2026 was an engineering failure, not an attack. Microsoft says so, and I have no evidence to the contrary.&lt;/li&gt;
&lt;li&gt;Microsoft listed Defender XDR among the affected services. The same dependency that carried email also carried part of the security tooling watching it.&lt;/li&gt;
&lt;li&gt;Whether detections were actually lost is not public yet. That uncertainty &lt;em&gt;is&lt;/em&gt; the blind spot.&lt;/li&gt;
&lt;li&gt;You can't fix this by trusting a vendor harder. You fix it with an out-of-band logging path, a degraded-mode runbook, and a habit of treating "no alerts" as a claim to verify.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;I was in a café on Thursday around lunchtime when the guy at the next table started muttering at his laptop. Outlook wouldn't load, and Teams on his phone wasn't doing any better. I looked at a status page, saw it wasn't just him, and went back to my coffee. It only got interesting that night, when I read the incident details.&lt;/p&gt;

&lt;p&gt;What stuck with me, though, wasn't the email. Everyone expects email to break sometimes. It was a quieter detail in the incident notes: the list of affected services included &lt;strong&gt;Microsoft Defender XDR&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think about that. The thing that tells you something is wrong shares a failure domain with the thing that is wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually happened
&lt;/h2&gt;

&lt;p&gt;Here is the part I can source.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start:&lt;/strong&gt; Around midday US time on Thursday, 12 November 2026 (roughly 16:00 GMT, per &lt;a href="https://www.aljazeera.com/news/2026/11/13/microsoft-says-services-still-returning-amid-widespread-outage" rel="noopener noreferrer"&gt;Al Jazeera&lt;/a&gt;). Microsoft tracked it under incidents EX1550543 (Exchange Online) and MO1550821 (the broader event).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scope:&lt;/strong&gt; Outlook, Exchange Online, Teams, SharePoint, Copilot, and Defender XDR were listed as affected. Later updates reportedly added Defender for Office 365 and Purview (&lt;a href="https://labs.cloudsecurityalliance.org/research/csa-research-note-m365-outage-copilot-defender-concentration/" rel="noopener noreferrer"&gt;CSA research note&lt;/a&gt;). Al Jazeera put the reach at 74 countries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official cause:&lt;/strong&gt; Microsoft said the problem was introduced during an earlier network capacity upgrade and surfaced after a more recent network change. Servers behind Exchange Online failed automated health checks and were pulled from rotation. The remaining servers took the extra load and got overwhelmed. Restarted servers fell over again when traffic returned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not an attack:&lt;/strong&gt; Microsoft said it was "not related to cyber or AI / agents" and found no sign of malicious activity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recovery:&lt;/strong&gt; Staged over roughly two days. Microsoft extended its email delivery timeout to 48 hours to protect delayed mail, and on Saturday, 14 November said it had fully restored service (&lt;a href="https://www.pbs.org/newshour/world/microsoft-says-services-fully-restored-after-global-outage" rel="noopener noreferrer"&gt;PBS&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1eeagyreisd5ch50y4w.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1eeagyreisd5ch50y4w.gif" alt="Animação ilustrativa: servidores saem de rotação e a carga sobe nos que restam" width="719" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The real-world fallout was broad. According to PBS and Al Jazeera: government operations disrupted in Japan, Singapore, and Australia.. Email problems for ministries in Greece and Norway.. &lt;br&gt;
UK police unable to take online crime reports; a Manchester trial halted.. &lt;br&gt;
The NHS dealing with prescription-email issues; Euronext telling firms to phone in trades..&lt;/p&gt;

&lt;p&gt;One caveat. The root cause is still preliminary. A full post-incident report was pending when I wrote this, and details may change.&lt;/p&gt;
&lt;h2&gt;
  
  
  The blind spot
&lt;/h2&gt;

&lt;p&gt;Here is the part that matters for us.&lt;/p&gt;

&lt;p&gt;Most AppSec and SOC designs quietly assume the &lt;strong&gt;security plane survives when the business plane degrades&lt;/strong&gt;. In practice, for any org that consolidated on one suite, they share infrastructure: identity, mail transport, APIs, admin portals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcltb0lfcdkfg5awes7k8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcltb0lfcdkfg5awes7k8.gif" alt="Mail, Teams, Copilot e Defender XDR compartilhando a mesma dependência, com logs out-of-band fora dela" width="760" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During this incident:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Defender XDR was listed as affected. The CSA note says the portal reportedly failed to load at times, which limits what analysts can see and do. It also says public reporting doesn't establish whether background detection kept running.&lt;/li&gt;
&lt;li&gt;Safe Links reportedly couldn't verify URLs, so links failed to open.&lt;/li&gt;
&lt;li&gt;Some admins couldn't load the admin center, where Microsoft posts service health notices (&lt;a href="https://www.getastra.com/blog/security-advisory/microsoft-365-outage/" rel="noopener noreferrer"&gt;Astra Security&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice what is &lt;em&gt;not&lt;/em&gt; in that list. I can't tell you that alerts were dropped, that anyone was breached, or that any SOC missed anything. Neither can anyone else yet. &lt;a href="https://www.security.io/articles/2026/11/13/microsoft-365-defender-xdr-outage" rel="noopener noreferrer"&gt;Security.io&lt;/a&gt; says the same thing plainly: alert delays, missed detections, and automation gaps are unverified. And I found no public reporting of Sentinel being affected, so I won't claim it.&lt;/p&gt;

&lt;p&gt;That is the blind spot. Not "we were attacked while blind," but &lt;strong&gt;"we can't prove we weren't, and our own tooling can't tell us."&lt;/strong&gt; A quiet console after an outage is not evidence of a quiet network.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why this creates attacker opportunity
&lt;/h2&gt;

&lt;p&gt;I'm not saying anyone exploited this window. I'm saying degraded monitoring changes the math, and attackers don't need a global outage to benefit from the same dynamics in a smaller one. Here is how.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Outage-themed phishing.&lt;/strong&gt; "Your mailbox is being restored, verify your account." Every user is primed to expect odd Microsoft messages and to click through restore prompts. This is a general pattern, not something reported for this incident, but it's the first thing I'd brief users about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Living off the land under reduced attention.&lt;/strong&gt; If the SOC is working from a half-loading portal and a flood of "email down" tickets, the signal that normally stands out (a new inbox rule, a fresh OAuth consent, an odd admin sign-in) is easier to bury. Native tools abused by attackers already look like admin work. Fewer eyes make it cheaper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delayed detection.&lt;/strong&gt; Even if background detection kept running, a backlog of events means alerts show up late. Dwell time is measured in hours. An alert that arrives 12 hours late has already lost most of its value for containment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blocked response.&lt;/strong&gt; Detection isn't the only thing that matters. Analysts who can't open the portal can't isolate a device, revoke a session, or purge a message. Mail-flow disruption also means purge and quarantine actions may lag.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recovery bursts.&lt;/strong&gt; When mail queues drain all at once, automations and agents that react to messages can run stale or duplicate actions. Nothing in the reporting says this caused harm. But if your workflows trigger on incoming mail, check message age and idempotency.&lt;/p&gt;
&lt;h2&gt;
  
  
  What developers and AppSec engineers should do
&lt;/h2&gt;

&lt;p&gt;Practical, not theoretical. In rough order of effort:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Review the window now, from data you control.&lt;/strong&gt;&lt;br&gt;
Pull sign-in, mail-flow, and endpoint telemetry for roughly 12 November 14:00 UTC through 14 November 12:00 UTC. If it only lives in the affected tenant, copy it somewhere else. Then rerun your hunts after ingestion backfills, because delayed data can hide things on the first pass.&lt;/p&gt;

&lt;p&gt;A starting point if you use Sentinel (adapt the table names to your setup):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let start = datetime(2026-11-12 14:00);
let finish = datetime(2026-11-14 12:00);
OfficeActivity
| where TimeGenerated between (start .. finish)
| where Operation in ("New-InboxRule", "Set-InboxRule", "UpdateInboxRules")
| project TimeGenerated, UserId, Operation, ClientIP, Parameters
| order by TimeGenerated asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also look for new OAuth app consents, MFA method changes, and admin role assignments in the same window.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Brief users on outage-themed lures.&lt;/strong&gt;&lt;br&gt;
Two lines in your internal channel. "Microsoft will not ask you to re-verify your password to restore your mailbox." Done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Build an out-of-band channel.&lt;/strong&gt;&lt;br&gt;
If incident response depends on the platform that's down, you have no incident response. Pick a channel that doesn't share Microsoft identity or mail: Signal, a separate Slack, a phone tree. Test it before you need it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Subscribe to service health outside the tenant.&lt;/strong&gt;&lt;br&gt;
Some admins couldn't open the admin center during this incident. Don't make that your only source of truth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Write a degraded-mode runbook.&lt;/strong&gt;&lt;br&gt;
One page. How do we triage if the XDR console is down? Do we fail open or fail closed on link checking? Who decides? How do we backfill telemetry after recovery? Decide this on a calm Tuesday, not during the outage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Make "no alerts" a claim you verify.&lt;/strong&gt;&lt;br&gt;
After any provider incident, ask: did detection &lt;em&gt;run&lt;/em&gt;, or was it silent because it was broken? A heartbeat alert, a canary event, or a synthetic detection that fires on schedule gives you an answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The longer-term lessons
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Map real dependencies, not product names.&lt;/strong&gt; "Microsoft" on a risk register is one line, but Exchange Online, Defender for Office 365, Purview, and Copilot behaved like one failure domain here. Trace what actually shares mail transport, identity, and Graph APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep one independent detection path.&lt;/strong&gt; I'm not arguing against Defender. It's a strong product, and consolidation has real benefits: fewer integrations, better correlation, less overhead. But "at least one logging and detection path outside the suite" is cheap insurance. An external SIEM, endpoint logs shipped to storage you control, network telemetry that doesn't care about your email vendor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fms4wvvudooo85pbtcx84.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fms4wvvudooo85pbtcx84.gif" alt="Heartbeat periódico confirmando que a detecção está rodando" width="760" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Treat monitoring as a tier-zero service.&lt;/strong&gt; We design production for redundancy and then run the monitoring that watches it on a single dependency. Monitoring should be at least as available as what it monitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design AI agents to fail loudly.&lt;/strong&gt; Copilot and third-party AI connectors reportedly couldn't reach Microsoft 365 data. The risk isn't the outage itself; it's an assistant that quietly keeps answering without its inputs. If your agents depend on a platform, surface tool failures instead of producing fluent but ungrounded output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be honest about SLAs.&lt;/strong&gt; Credits are a pricing mechanism, not a resilience control. They don't un-miss an alert.&lt;/p&gt;

&lt;p&gt;None of this needs multi-cloud religion or a rewrite. It needs a short list of questions you can answer: What shares a failure domain with my detection? What do I do if the portal won't load? Where does my evidence live?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This wasn't an attack. It was a routine-looking infrastructure change that cascaded, and Microsoft's engineers fixed it. That's exactly why it's useful: no adversary, no drama, just a clear look at how much of our security posture rides on one dependency.&lt;/p&gt;

&lt;p&gt;The lesson isn't "Microsoft bad." It's that &lt;strong&gt;resilience of the security plane is part of AppSec&lt;/strong&gt;, and most of us haven't designed it on purpose.&lt;/p&gt;

&lt;p&gt;I'd rather find the gaps in a tabletop than in a postmortem.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sources &amp;amp; Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.pbs.org/newshour/world/microsoft-says-services-fully-restored-after-global-outage" rel="noopener noreferrer"&gt;PBS NewsHour: Microsoft says services fully restored after global outage&lt;/a&gt;, restoration on 14 November, cause, government impact&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.aljazeera.com/news/2026/11/13/microsoft-says-services-still-returning-amid-widespread-outage" rel="noopener noreferrer"&gt;Al Jazeera: Microsoft says affected services fully recovered following worldwide outage&lt;/a&gt;, timing, scale, impact on governments and businesses&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://labs.cloudsecurityalliance.org/research/csa-research-note-m365-outage-copilot-defender-concentration/" rel="noopener noreferrer"&gt;Cloud Security Alliance research note: When the Assistant and the Alarm Go Dark Together&lt;/a&gt;, concentration risk, Defender and Copilot impact, recommendations&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.getastra.com/blog/security-advisory/microsoft-365-outage/" rel="noopener noreferrer"&gt;Astra Security: Microsoft 365 Outage, What Happened and What I'd Do Next&lt;/a&gt;, timeline, security impact, admin center access&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.security.io/articles/2026/11/13/microsoft-365-defender-xdr-outage" rel="noopener noreferrer"&gt;Security.io: Microsoft 365 outage puts Defender XDR continuity under review&lt;/a&gt;, what is confirmed vs. unverified&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ransomnews.com/microsoft-365-outage-cyberattack-november-2026/" rel="noopener noreferrer"&gt;Ransomnews: Microsoft 365 outage, was it a cyberattack?&lt;/a&gt;, Microsoft's "not related to cyber" statement and root-cause wording&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Incident IDs (EX1550543, MO1550821) are visible in the Microsoft 365 admin center, where the post-incident report should appear.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>devsecops</category>
      <category>cybersecurity</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>13 Things Hiding Inside Your Laptop That Most Developers Never Learn</title>
      <dc:creator>Felipe</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:49:26 +0000</pubDate>
      <link>https://dev.to/fredericrypto/13-things-hiding-inside-your-laptop-that-most-developers-never-learn-5ghg</link>
      <guid>https://dev.to/fredericrypto/13-things-hiding-inside-your-laptop-that-most-developers-never-learn-5ghg</guid>
      <description>&lt;p&gt;I started out on the hardware side of things, long before I ever opened a code editor. Even so, when I moved into computer science, I kept getting caught out by the same thing: a problem that looked like a software bug turned out to be hardware.&lt;/p&gt;

&lt;p&gt;A build that slowed down after ten minutes. A screen that flickered every time I moved the lid.. A battery that aged much faster than the spec sheet promised. 😑 &lt;br&gt;
I blamed my code every single time, and I lost a lot of hours to that..&lt;/p&gt;

&lt;p&gt;What I eventually learned is that a laptop is a negotiated compromise between heat, space, cost and power. Every part has a design decision behind it, and many of those decisions explain behavior we see every day. Most of it I picked up the hard way, one confusing failure at a time.&lt;/p&gt;

&lt;p&gt;So I built two short animations that take a laptop apart in an exploded view and attach one lesser-known detail to each of its 13 main components. This post is the written companion, with the context I wish someone had given me earlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  The map
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2b9v9r8prlcs8vx8qt94.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2b9v9r8prlcs8vx8qt94.gif" alt="Exploded view of a laptop with its 13 main components labeled" width="600" height="1067"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The 13 secrets
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fun14yeedo9zd21qmu72g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fun14yeedo9zd21qmu72g.gif" alt="Animated tour that zooms into each laptop component and shows one little-known fact about it" width="600" height="1067"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick reference
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#&lt;/th&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;The detail most people miss&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Webcam&lt;/td&gt;
&lt;td&gt;The lid is so thin that bigger sensors and lenses barely fit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Screen&lt;/td&gt;
&lt;td&gt;A flex cable bending through the hinge is a classic failure point&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Power button&lt;/td&gt;
&lt;td&gt;A tap is a request, not a switch&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Keyboard&lt;/td&gt;
&lt;td&gt;Keys are read as a grid, which is why some combinations get lost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Touchpad&lt;/td&gt;
&lt;td&gt;It senses your finger's electric charge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Top case&lt;/td&gt;
&lt;td&gt;In slim and fanless designs, the shell helps cool the chip&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Fan&lt;/td&gt;
&lt;td&gt;Most are blowers that throw air sideways through the fins&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Heat sink&lt;/td&gt;
&lt;td&gt;Heat pipes move heat by boiling and condensing a little water&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;RAM&lt;/td&gt;
&lt;td&gt;Data does not vanish the instant power is cut&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Motherboard&lt;/td&gt;
&lt;td&gt;A sandwich of many copper layers with length-matched memory lines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;SSD&lt;/td&gt;
&lt;td&gt;Every write wears the flash a little&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;Battery&lt;/td&gt;
&lt;td&gt;A small controller inside the pack watches and protects the cells&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;td&gt;Bottom cover&lt;/td&gt;
&lt;td&gt;The rubber feet exist so the fan can breathe&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Input and the outside world
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Webcam.&lt;/strong&gt; Many laptops still ship with 720p cameras. The lid is only a few millimeters thick, and a larger lens and sensor need depth that the lid does not have. Thin bezels make it harder still. Higher-resolution modules are becoming more common, but the physical constraint is the reason this took so long.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Screen.&lt;/strong&gt; A thin flex cable runs through the hinge and bends every time you open the lid. When a screen flickers, shows bands or goes dark while you flex the lid, the cable is a more likely suspect than the panel. This failure pattern became widely known as &lt;a href="https://www.ifixit.com/News/12903/flexgate" rel="noopener noreferrer"&gt;"Flexgate"&lt;/a&gt; on some MacBook Pro generations, but the mechanical principle applies to any hinged display.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power button.&lt;/strong&gt; It behaves less like a switch and more like an input. A short press sends a signal to a small controller, which asks the operating system to shut down gracefully. Holding it for several seconds makes the hardware cut power on its own, which is why it still works when the OS is frozen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keyboard.&lt;/strong&gt; Keys are not wired one by one. They sit in a grid of rows and columns, and a controller scans that grid many times per second. This saves wiring, but it also means that certain combinations of simultaneous presses can be ambiguous. That is the origin of "ghosting", and the reason gaming keyboards advertise &lt;a href="https://en.wikipedia.org/wiki/Rollover_(key)" rel="noopener noreferrer"&gt;rollover&lt;/a&gt; support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Touchpad.&lt;/strong&gt; Most touchpads are capacitive. A grid of electrodes senses how your finger disturbs an electric field, which is why gloves and pencils usually fail to register. The same principle powers touchscreens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Thermals
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Top case.&lt;/strong&gt; In thin and fanless laptops, the metal body is part of the cooling system. Heat is spread from the chip into the chassis, so the whole case works as a radiator. That is also why those machines feel warm in your hands under load.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fan.&lt;/strong&gt; Laptop fans are usually blowers, also called centrifugal fans. Air enters at the center and is thrown outward through the heat sink fins. The weak point is dust: when it clogs the fins, temperatures climb and the CPU lowers its own clock speed to protect itself, a behavior known as thermal throttling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heat sink.&lt;/strong&gt; The copper tubes are &lt;a href="https://en.wikipedia.org/wiki/Heat_pipe" rel="noopener noreferrer"&gt;heat pipes&lt;/a&gt;. They contain a small amount of working fluid, typically water, at low pressure. It boils at the hot end, travels as vapor to the cool end, condenses, and flows back through a wick. There are no moving parts, and the effective heat transfer is far better than a solid copper rod of the same size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compute and memory
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Motherboard.&lt;/strong&gt; It looks flat, but many boards are built from eight or more layers of copper traces laminated together. High-speed lines such as memory are length-matched so every bit of a transfer arrives at the same moment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAM.&lt;/strong&gt; Each DRAM cell is a tiny capacitor that leaks, so the contents are refreshed continuously, on the order of every 64 milliseconds in common standards. After power is cut, the data does not disappear instantly. Researchers showed in 2008 that it can persist for seconds to minutes, and longer when the chips are cold, in the well-known &lt;a href="https://www.usenix.org/legacy/event/sec08/tech/full_papers/halderman/halderman_html/" rel="noopener noreferrer"&gt;cold boot attack&lt;/a&gt;. It is a useful reminder for anyone who thinks about disk encryption: the keys have to live in memory while the machine is running. Modern platforms add mitigations, but the physics is the reason they are needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Storage and power
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SSD.&lt;/strong&gt; Flash cells degrade slightly with each write. The controller hides this by spreading writes evenly across the drive, a technique called &lt;a href="https://en.wikipedia.org/wiki/Wear_leveling" rel="noopener noreferrer"&gt;wear leveling&lt;/a&gt;. For most workloads the endurance is far more than enough, and the drive's SMART data shows how much of it you have used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Battery.&lt;/strong&gt; The pack is smarter than it looks. A small controller inside counts charge in and out, monitors temperature, and can disconnect the cells if something goes wrong. Heat is the biggest long-term enemy of lithium-ion cells, which is one more reason the cooling story above matters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bottom cover.&lt;/strong&gt; The rubber feet are not just for grip. They lift the chassis so the fan can pull air in through the vents underneath. On a bed, a blanket or a lap, those vents get blocked and temperatures rise quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If a long build or test run slows down, check temperatures before you blame the code. Throttling is silent.&lt;/li&gt;
&lt;li&gt;Keep the vents clear and use a hard, flat surface for heavy work.&lt;/li&gt;
&lt;li&gt;When a display misbehaves as you move the lid, suspect the cable before the panel.&lt;/li&gt;
&lt;li&gt;Treat memory as sensitive. Secrets and keys live in RAM while a machine is on.&lt;/li&gt;
&lt;li&gt;Look at SSD health data occasionally instead of guessing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How the animations were made
&lt;/h2&gt;

&lt;p&gt;Both animations are generated from code. The laptop is hand-built SVG, the motion is driven by a small timeline script, frames are captured with headless Chromium through Playwright, and the final files are encoded with ffmpeg. No video editor was involved. If there is interest, I can write a follow-up on the pipeline and share the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thought
&lt;/h2&gt;

&lt;p&gt;None of these details is exotic. They are the ordinary engineering trade-offs behind a device we use for hours every day.. But they cost me real time to learn, and I only really understood them after moving between hardware and software.&lt;/p&gt;

&lt;p&gt;Knowing them will not change how you write code, but it will change how you diagnose a machine that misbehaves. I would have saved myself a lot of wasted debugging if I had known this earlier.&lt;/p&gt;

&lt;p&gt;I'm sure I'm not the only one who has blamed the wrong thing..&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Halderman et al., &lt;a href="https://www.usenix.org/legacy/event/sec08/tech/full_papers/halderman/halderman_html/" rel="noopener noreferrer"&gt;"Lest We Remember: Cold-Boot Attacks on Encryption Keys"&lt;/a&gt;, USENIX Security 2008&lt;/li&gt;
&lt;li&gt;iFixit, &lt;a href="https://www.ifixit.com/News/12903/flexgate" rel="noopener noreferrer"&gt;"Flexgate"&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Wikipedia: &lt;a href="https://en.wikipedia.org/wiki/Heat_pipe" rel="noopener noreferrer"&gt;Heat pipe&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Wear_leveling" rel="noopener noreferrer"&gt;Wear leveling&lt;/a&gt;, &lt;a href="https://en.wikipedia.org/wiki/Rollover_(key)" rel="noopener noreferrer"&gt;Rollover (key)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hardware</category>
      <category>computerscience</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>I hardened my first Express auth API: Helmet, CORS and rate limiting</title>
      <dc:creator>Felipe</dc:creator>
      <pubDate>Mon, 09 Nov 2026 20:01:48 +0000</pubDate>
      <link>https://dev.to/fredericrypto/i-hardened-my-first-express-auth-api-helmet-cors-and-rate-limiting-3k95</link>
      <guid>https://dev.to/fredericrypto/i-hardened-my-first-express-auth-api-helmet-cors-and-rate-limiting-3k95</guid>
      <description>&lt;p&gt;I started &lt;code&gt;auth-api&lt;/code&gt; to stop following tutorials and build something of my own. It's a small authentication API (register, login and a protected route) built with Node, Express, Drizzle ORM and MySQL.&lt;/p&gt;

&lt;p&gt;For a while I only cared that it worked. Routes returned JSON, users got saved, great. Then I started wondering what happens when someone points a script at it. So I spent a few days adding the basic security layers, and this post is what I did and what I learned.&lt;/p&gt;

&lt;p&gt;It's not finished. I'll tell you what's still missing at the end.&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/Fredericrypto/auth-api" rel="noopener noreferrer"&gt;github.com/Fredericrypto/auth-api&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  First: validation and password hashing
&lt;/h2&gt;

&lt;p&gt;Before any network stuff, I wanted two things: never trust the request body, and never store a password in a way I'd be embarrassed about.&lt;/p&gt;

&lt;p&gt;Validation is Zod. Every body goes through a schema before it touches the database:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'zod'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;registerSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;senha&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;nome&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Yes, Portuguese field names. I'm Brazilian.) A 6 character minimum is also low, and I plan to raise it.&lt;/p&gt;

&lt;p&gt;For passwords I used Argon2 instead of bcrypt. It's the more modern option and it's harder to crack with GPUs. I'm not a cryptographer, I'm following the OWASP recommendation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helmet
&lt;/h2&gt;

&lt;p&gt;By default Express announces itself with &lt;code&gt;X-Powered-By: Express&lt;/code&gt;. Helmet removes that and sets a bunch of security headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;helmet&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'helmet'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;helmet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked the headers with &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i -X POST http://localhost:3000/login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 400 Bad Request
RateLimit-Limit: 15
Content-Security-Policy: default-src 'self';base-uri 'self';font-src 'self' https: data:;...
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: no-referrer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I sent an empty body on purpose, so Zod rejected it with a &lt;code&gt;400&lt;/code&gt;. That's validation working. What I cared about here are the headers: Helmet is on, and &lt;code&gt;X-Powered-By: Express&lt;/code&gt; is gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  CORS: no more wildcard
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;app.use(cors())&lt;/code&gt; allows every origin. I replaced it with a whitelist of the origins I actually use, which are just my local frontend ports for now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;allowedOrigins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'http://localhost:3000'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'http://localhost:5173'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// no origin = curl, Postman, mobile apps&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;allowedOrigins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bloqueado pela política de CORS'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Allowed origin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i -X POST http://localhost:3000/login \
  -H &lt;span class="s2"&gt;"Origin: http://localhost:5173"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: http://localhost:5173
Vary: Origin
Access-Control-Allow-Credentials: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Blocked origin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -i -X OPTIONS http://localhost:3000/login \
  -H &lt;span class="s2"&gt;"Origin: http://evil.com"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Access-Control-Request-Method: POST"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=utf-8

{"sucesso":false,"erro":"Origem não permitida"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My first version had two bugs. The blocked request returned a &lt;code&gt;500&lt;/code&gt; with a full stack trace, including file paths from my machine. And I had registered the CORS middleware &lt;em&gt;after&lt;/em&gt; my routes, so real responses didn't get CORS headers at all. Express runs middleware in order, so I moved CORS above the routes and added an error handler (after all routes) that returns a clean &lt;code&gt;403&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'Bloqueado pela política de CORS'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sucesso&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;erro&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Origem não permitida'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;sucesso&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;erro&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Erro interno'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing I had to learn: CORS is enforced by the &lt;em&gt;browser&lt;/em&gt;. It stops other websites from reading your API's responses in a user's browser. It doesn't stop someone from calling your API with curl, so it's one layer, not a replacement for auth or rate limiting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate limiting
&lt;/h2&gt;

&lt;p&gt;Login is the obvious target for brute force and credential stuffing. I limited it to 15 failed attempts per IP every 15 minutes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rateLimit&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'express-rate-limit'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;authLimiter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rateLimit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;windowMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;skipSuccessfulRequests&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// only failed attempts count&lt;/span&gt;
  &lt;span class="n"&gt;standardHeaders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;legacyHeaders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;erro&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Muitas tentativas de acesso a partir desse IP. Tente novamente após 15 minutos.'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;authLimiter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;loginHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's also a global limiter of 100 requests per IP every 15 minutes for the whole API.&lt;/p&gt;

&lt;p&gt;I tested the login limit by sending requests in a loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..16&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; -X POST http://localhost:3000/login
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;400 (x14)
429
429
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had already used one request before running the loop, so 14 went through and the rest got a &lt;code&gt;429 Too Many Requests&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F06o7ep4idr6twtv3xt17.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F06o7ep4idr6twtv3xt17.gif" alt="Terminal animation: a loop of 15 curl requests returning 400, then the 16th returning 429 Too Many Requests" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Per-IP limiting has its own problems (people behind the same NAT share an IP), so Redis and smarter limits are on my list.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's still missing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Refresh tokens and logout&lt;/li&gt;
&lt;li&gt;Better error handling and logging (Winston/Morgan)&lt;/li&gt;
&lt;li&gt;Redis for rate limiting&lt;/li&gt;
&lt;li&gt;Tests. There are none yet. I know.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why I'm posting this now
&lt;/h2&gt;

&lt;p&gt;I learn faster when I write things down and someone can tell me I'm wrong. If you spot something dumb in the repo, open an issue, I MEAN IT.&lt;/p&gt;

&lt;p&gt;Next post will probably be about JWT and protected routes, and what I got wrong the first time.&lt;/p&gt;

</description>
      <category>node</category>
      <category>webdev</category>
      <category>security</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
