<?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"><channel><title><![CDATA[Practical Security Notes]]></title><description><![CDATA[Practical Security Notes]]></description><link>https://matiasisnard.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 15:30:11 GMT</lastBuildDate><atom:link href="https://matiasisnard.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Security headers on 36 big tech sites: what's missing, and which gaps actually matter]]></title><description><![CDATA[Security headers are one of the few web security controls you can check from the outside in a second, which is why they show up in almost every pentest…]]></description><link>https://matiasisnard.hashnode.dev/security-headers-on-36-big-tech-sites-what-s-missing-and-which-gaps-actually-matter</link><guid isPermaLink="true">https://matiasisnard.hashnode.dev/security-headers-on-36-big-tech-sites-what-s-missing-and-which-gaps-actually-matter</guid><category><![CDATA[Security]]></category><category><![CDATA[web]]></category><category><![CDATA[Python]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Matias Isnard]]></dc:creator><pubDate>Sun, 15 Nov 2026 19:45:06 GMT</pubDate><content:encoded><![CDATA[<p>Security headers are one of the few web security controls you can check from the outside in a second, which is why they show up in almost every pentest report and vendor security questionnaire. I review a lot of those reports as part of GRC work, and a "missing headers" finding causes more back and forth than its risk usually deserves. Sometimes it's a real gap. Often it's a marketing homepage that doesn't need a strict CSP.</p>
<p>To get a feel for what normal looks like, I wrote a small Python checker and ran it against the homepages of 40 well-known tech and open source sites.</p>
<h2>A note on measuring</h2>
<p>Four of the 40 sites answered my script with a 403. They sit behind bot protection, and what came back was the challenge page, not the real site. Its headers tell you nothing about the site itself, so I left those four out. If you run any header scanner against a site behind Cloudflare, Akamai or similar, check the status code before trusting the result, or you end up grading the challenge page.</p>
<p>That leaves 36 sites (November 10, 2026).</p>
<h2>Results</h2>
<table>
<thead>
<tr>
<th>Finding</th>
<th>Sites (of 36)</th>
</tr>
</thead>
<tbody><tr>
<td>No <code>Referrer-Policy</code></td>
<td>19</td>
</tr>
<tr>
<td>No <code>X-Content-Type-Options: nosniff</code></td>
<td>14</td>
</tr>
<tr>
<td>No <code>Content-Security-Policy</code></td>
<td>11</td>
</tr>
<tr>
<td>No clickjacking protection</td>
<td>7</td>
</tr>
<tr>
<td><code>X-Powered-By</code> header present</td>
<td>5</td>
</tr>
<tr>
<td>CSP only in report-only mode</td>
<td>3</td>
</tr>
<tr>
<td>No <code>Strict-Transport-Security</code></td>
<td>2</td>
</tr>
<tr>
<td>HSTS <code>max-age</code> of one hour</td>
<td>2</td>
</tr>
<tr>
<td><code>Server</code> header shows a version</td>
<td>2</td>
</tr>
</tbody></table>
<p>Ten sites had no findings at all. Most had one to four.</p>
<p>I didn't expect this one: all five <code>X-Powered-By</code> headers said <code>Next.js</code>. Next.js sends it by default, so it's probably not something those teams chose. You turn it off with one line in <code>next.config.js</code>:</p>
<pre><code class="language-js">module.exports = { poweredByHeader: false }
</code></pre>
<p>It's low risk on its own, but it's free to remove and it shows up in every scanner, so it keeps coming back in reports until someone flips that setting.</p>
<h2>The checker</h2>
<p>Standard library only. It fetches the page (following redirects), lowercases the header names, and runs a pure function over them.</p>
<pre><code>python check_headers.py https://example.com
https://example.com -&gt; 200, 3 findings
    - no Content-Security-Policy
    - no X-Content-Type-Options: nosniff
    - no Referrer-Policy
</code></pre>
<h3>Fetching</h3>
<pre><code class="language-python">import urllib.error
import urllib.request

UA = "security-headers-check/1.0 (+https://github.com/IsnardMatias/security-headers-check)"


def fetch_headers(url, timeout=10):
    req = urllib.request.Request(url, headers={"User-Agent": UA})
    try:
        resp = urllib.request.urlopen(req, timeout=timeout)
    except urllib.error.HTTPError as e:
        resp = e
    headers = {k.lower(): v for k, v in resp.headers.items()}
    return resp.geturl(), resp.status, headers
</code></pre>
<p>Two details. <code>HTTPError</code> responses still carry headers, so a 404 or 403 is returned instead of raised, and the status ends up in the output where you can see it. And the user agent names the tool and links to it. If you're going to point a script at other people's sites, it's polite to say who you are.</p>
<h3>Evaluating</h3>
<pre><code class="language-python">HSTS_MIN = 15552000  # 180 days


def evaluate(headers):
    findings = []

    hsts = headers.get("strict-transport-security")
    if not hsts:
        findings.append("no Strict-Transport-Security")
    else:
        m = re.search(r"max-age\s*=\s*(\d+)", hsts, re.I)
        if not m or int(m.group(1)) &lt; HSTS_MIN:
            findings.append(f"HSTS max-age below 180 days ({hsts})")

    csp = headers.get("content-security-policy")
    if not csp:
        if headers.get("content-security-policy-report-only"):
            findings.append("CSP only in report-only mode")
        else:
            findings.append("no Content-Security-Policy")

    frame_ok = "frame-ancestors" in (csp or "").lower() or headers.get("x-frame-options")
    if not frame_ok:
        findings.append("no clickjacking protection (X-Frame-Options or CSP frame-ancestors)")

    if headers.get("x-content-type-options", "").lower() != "nosniff":
        findings.append("no X-Content-Type-Options: nosniff")

    if not headers.get("referrer-policy"):
        findings.append("no Referrer-Policy")

    server = headers.get("server", "")
    if re.search(r"\d", server):
        findings.append(f"Server header shows a version ({server})")
    if headers.get("x-powered-by"):
        findings.append(f"X-Powered-By present ({headers['x-powered-by']})")
    return findings
</code></pre>
<p>A few choices worth explaining:</p>
<ul>
<li>Clickjacking passes with either <code>X-Frame-Options</code> or a CSP <code>frame-ancestors</code> directive. Some scanners only look for <code>X-Frame-Options</code> and report a false positive on sites that use the modern CSP way.</li>
<li>Report-only CSP gets its own finding. It means the team has started on CSP but isn't enforcing it yet, which is a different situation from having nothing. Three sites were in that state.</li>
<li>The <code>Server</code> check only flags it when there's a digit in it. <code>Server: nginx</code> is fine. <code>Server: nginx/1.14.0</code> tells an attacker which CVEs to try.</li>
<li>There's no check for <code>X-XSS-Protection</code>. Old scanners still flag it as missing, but browsers removed the feature years ago and the current advice is to leave it out or set it to <code>0</code>.</li>
</ul>
<p>Because <code>evaluate</code> takes a plain dict, testing it doesn't need the network:</p>
<pre><code class="language-python">f = evaluate({"strict-transport-security": "max-age=300", "server": "Apache/2.4.41 (Ubuntu)"})
assert any("HSTS max-age" in x for x in f)
assert any("Server header shows a version" in x for x in f)
</code></pre>
<h2>What to fix first</h2>
<p>If this finds things on your site, I would not treat them as equal. Roughly in order:</p>
<ol>
<li>HSTS missing or with a short <code>max-age</code>. This is the one that protects real users on hostile networks, and it's one header. Two sites in the sample had <code>max-age=3600</code>, which means the protection lapses an hour after each visit. Use at least six months, a year if you plan to join the preload list.</li>
<li>Clickjacking protection on anything with a logged-in session. For a static marketing page it matters much less. For an app where a click can change settings or move money, it matters a lot.</li>
<li>CSP on pages that handle user input or sessions. A good CSP is real work: inventory your scripts, move inline code out, roll out in report-only mode, then enforce. That's why 11 of 36 big sites still don't have one on their homepage. Start with the app, not the marketing site.</li>
<li><code>nosniff</code>, <code>Referrer-Policy</code> and version banners. One line each, low risk, and they make the next pentest report shorter. Worth doing, but not urgent.</li>
</ol>
<h2>Wrapping up</h2>
<p>The pattern across these 36 sites is that the cheap headers are often missing and the expensive one (CSP) is present more often than I expected. If you run the checker on your own sites, fix HSTS first, look at CSP for the parts of the site that hold sessions, and clear the one-line ones in a single change so they stop showing up in reports.</p>
<p>Code and tests: <a href="https://github.com/IsnardMatias/security-headers-check">https://github.com/IsnardMatias/security-headers-check</a></p>
<p>If you'd rather not run and schedule this yourself, I maintain a hosted version on Apify that checks security headers together with HTTPS, TLS version and email authentication for a list of domains: <a href="https://apify.com/isnard/domain-security-checker">Domain Security &amp; Email Deliverability Checker</a>.</p>
]]></content:encoded></item><item><title><![CDATA[I checked SPF and DMARC on 40 well-known domains. The open source projects were the interesting part]]></title><description><![CDATA[Since February 2024, Gmail and Yahoo reject or spam-folder bulk mail from domains that don't have SPF, DKIM and DMARC set up. Microsoft added similar rules…]]></description><link>https://matiasisnard.hashnode.dev/i-checked-spf-and-dmarc-on-40-well-known-domains-the-open-source-projects-were-the-interesting-part</link><guid isPermaLink="true">https://matiasisnard.hashnode.dev/i-checked-spf-and-dmarc-on-40-well-known-domains-the-open-source-projects-were-the-interesting-part</guid><category><![CDATA[Security]]></category><category><![CDATA[email]]></category><category><![CDATA[dns]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Matias Isnard]]></dc:creator><pubDate>Sun, 15 Nov 2026 19:43:06 GMT</pubDate><content:encoded><![CDATA[<p>Since February 2024, Gmail and Yahoo reject or spam-folder bulk mail from domains that don't have SPF, DKIM and DMARC set up. Microsoft added similar rules for Outlook.com in 2025. So most teams have "done DMARC" by now, at least on paper.</p>
<p>What "done" means varies a lot, though. A DMARC record with <code>p=none</code> is valid, passes most checklists, and protects nobody: a spoofed email from your domain still lands in the inbox. An SPF record can look fine and still fail at the receiver because it needs too many DNS lookups.</p>
<p>I wanted to see what this looks like on real domains, so I wrote a small Python script and ran it against 40 well-known tech and open source domains. This post walks through the script and what came out of it.</p>
<h2>What the results looked like</h2>
<p>All 40 domains had SPF and DMARC. That part is solved. The details were less uniform:</p>
<table>
<thead>
<tr>
<th></th>
<th>Count</th>
</tr>
</thead>
<tbody><tr>
<td>DMARC <code>p=reject</code></td>
<td>24</td>
</tr>
<tr>
<td>DMARC <code>p=quarantine</code></td>
<td>10</td>
</tr>
<tr>
<td>DMARC <code>p=none</code></td>
<td>6</td>
</tr>
<tr>
<td>SPF ending in <code>-all</code></td>
<td>17</td>
</tr>
<tr>
<td>SPF ending in <code>~all</code></td>
<td>22</td>
</tr>
<tr>
<td>SPF at exactly 10 DNS lookups</td>
<td>3</td>
</tr>
</tbody></table>
<p>Two things stood out.</p>
<p>All six domains on <code>p=none</code> were open source projects: python.org, debian.org, ubuntu.com, rust-lang.org, golang.org and linuxfoundation.org. That isn't carelessness. These projects run large public mailing lists, and mailing lists traditionally rewrite messages: they add a footer or a <code>[list-name]</code> tag to the subject. That breaks the DKIM signature, and the forwarded mail fails DMARC. With <code>p=reject</code>, people's own posts to the list would bounce. Mailman and other list software now have workarounds (rewriting the From header), but moving a big community to enforcement is slow, careful work. If you run mailing lists, this is the trade-off you will hit too.</p>
<p>Three domains sat at exactly 10 SPF lookups, the hard limit in RFC 7208. One more <code>include:</code> for a new email tool and their SPF check returns <code>permerror</code>, which many receivers treat as a fail. Nothing in the DNS console warns you about this. You find out when a new vendor's email starts going to spam.</p>
<p>(Results from November 10, 2026. DNS changes, so yours may differ if you run it today.)</p>
<h2>The script</h2>
<p>It does three things per domain: read the SPF record and how it ends, count the DNS lookups SPF needs (following includes), and read the DMARC policy. It needs one dependency, <code>dnspython</code>, because the standard library can't query TXT records.</p>
<pre><code>pip install dnspython
python check_email_auth.py github.com python.org
</code></pre>
<pre><code>github.com               SPF ~all     lookups 10  DMARC p=quarantine   rua yes
python.org               SPF ~all     lookups 8   DMARC p=none         rua yes
    - DMARC p=none: spoofed mail is still delivered
</code></pre>
<h3>Reading TXT records</h3>
<pre><code class="language-python">import dns.exception
import dns.resolver

resolver = dns.resolver.Resolver()
resolver.lifetime = 5


def txt(name):
    try:
        answers = resolver.resolve(name, "TXT")
    except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.NoNameservers, dns.exception.Timeout):
        return []
    return [b"".join(r.strings).decode(errors="replace") for r in answers]
</code></pre>
<p>The <code>b"".join(r.strings)</code> part matters more than it looks. TXT records longer than 255 characters are split into several strings, and long SPF records hit that all the time. If you only read the first string, you get half a record and wrong results.</p>
<h3>Counting SPF lookups</h3>
<p>This is the check that bites in practice. Every <code>include</code>, <code>a</code>, <code>mx</code>, <code>ptr</code>, <code>exists</code> and <code>redirect</code> costs one DNS lookup, and so does everything inside the records they point to. The total must stay at 10 or below.</p>
<pre><code class="language-python">LOOKUP_TERMS = {"include", "a", "mx", "ptr", "exists", "redirect"}


def count_lookups(domain, depth=0, seen=None):
    seen = seen if seen is not None else set()
    if depth &gt; 10 or domain in seen:
        return 0
    seen.add(domain)
    records = spf_record(domain)
    if len(records) != 1:
        return 0
    total = 0
    for term in records[0].split()[1:]:
        mech = term.lower().lstrip("+-~?")
        name = re.split(r"[:/=]", mech, maxsplit=1)[0]
        if name in LOOKUP_TERMS:
            total += 1
            if name in ("include", "redirect"):
                target = re.split(r"[:=]", mech, maxsplit=1)[1]
                total += count_lookups(target, depth + 1, seen)
        if total &gt; 10:
            break
    return total
</code></pre>
<p>The <code>seen</code> set and the depth limit are there because SPF records can include each other in loops, usually after a few vendor migrations nobody cleaned up.</p>
<p>One caveat: real receivers also count "void lookups" (includes that return nothing) and have a separate limit for those. This count is a close approximation, good enough to see that you are at 9 or 10 and should clean up before adding anything.</p>
<h3>Reading DMARC</h3>
<p>DMARC lives at <code>_dmarc.yourdomain.com</code> and is a list of <code>key=value</code> pairs separated by semicolons:</p>
<pre><code class="language-python">def parse_tags(record):
    tags = {}
    for part in record.split(";"):
        key, sep, value = part.partition("=")
        if sep:
            tags[key.strip().lower()] = value.strip()
    return tags
</code></pre>
<p>The script flags three things: <code>p=none</code>, a missing <code>rua</code> (the address that receives aggregate reports), and more than one DMARC record. That last one is easy to create by accident when two teams each "add DMARC", and receivers respond by ignoring DMARC completely.</p>
<p>The full script, with CSV output and an exit code for CI, is on GitHub (link at the end).</p>
<h2>What about DKIM?</h2>
<p>You might notice the script doesn't check DKIM. That's deliberate. DKIM keys are published at <code>&lt;selector&gt;._domainkey.yourdomain.com</code>, and the selector is chosen by your email provider: <code>google</code>, <code>selector1</code>, <code>s1</code>, <code>k1</code>, something random. There's no way to list them from outside. Tools that "check DKIM" just guess common selectors and report "not found" when they guess wrong, which looks like a problem when there isn't one.</p>
<p>If you want to check your own DKIM, take the selector from the <code>DKIM-Signature: s=</code> header of an email you sent, and query that exact name.</p>
<h2>Moving from p=none to p=reject</h2>
<p>If you ran this on your own domain and got <code>p=none</code>, this is the order I'd follow:</p>
<ol>
<li><strong>Make sure <code>rua</code> is set</strong> and actually read the reports for two to four weeks. They list every server sending mail as your domain. You will find forgotten senders: the billing system, the HR tool, a marketing platform someone signed up for in 2021.</li>
<li><strong>Add the legitimate senders</strong> to SPF or set up DKIM for them. Watch the lookup count while you do it.</li>
<li><strong>Move to <code>p=quarantine</code></strong>, optionally with <code>pct=25</code> to apply it to a quarter of failing mail first.</li>
<li><strong>Then <code>p=reject</code></strong> once the reports show only spoofing in the failures.</li>
</ol>
<p>Skipping step 1 is how you end up blocking your own invoices.</p>
<h2>Wrapping up</h2>
<p>Every domain I checked had the records. The useful questions now are whether your policy actually blocks anything, and how much room your SPF has left before the next tool you add breaks it. The script answers both in a few seconds per domain, and with the exit code you can run it in CI or on a schedule and catch it when someone adds the eleventh lookup.</p>
<p>Code and tests: <a href="https://github.com/IsnardMatias/email-auth-check">https://github.com/IsnardMatias/email-auth-check</a></p>
<p>If you'd rather not run and schedule this yourself, I maintain a hosted version on Apify that checks SPF, DMARC, MTA-STS, CAA and DNSSEC for a list of domains and returns a score with fixes: <a href="https://apify.com/isnard/domain-security-checker">Domain Security &amp; Email Deliverability Checker</a>.</p>
]]></content:encoded></item><item><title><![CDATA[TLS certificates now expire every 200 days. Here's a small Python check before it drops to 47]]></title><description><![CDATA[On March 15, 2026, the maximum lifetime of a public TLS certificate dropped from 398 days to 200. In March 2027 it drops to 100, and in March 2029 to 47…]]></description><link>https://matiasisnard.hashnode.dev/tls-certificates-now-expire-every-200-days-here-s-a-small-python-check-before-it-drops-to-47</link><guid isPermaLink="true">https://matiasisnard.hashnode.dev/tls-certificates-now-expire-every-200-days-here-s-a-small-python-check-before-it-drops-to-47</guid><category><![CDATA[Security]]></category><category><![CDATA[Python]]></category><category><![CDATA[SSL]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Matias Isnard]]></dc:creator><pubDate>Tue, 10 Nov 2026 05:00:15 GMT</pubDate><content:encoded><![CDATA[<p>On March 15, 2026, the maximum lifetime of a public TLS certificate dropped from 398 days to 200. In March 2027 it drops to 100, and in March 2029 to 47. The CA/Browser Forum approved this schedule in April 2025 (ballot SC-081), with every major browser voting in favor.</p>
<p>If your renewals are fully automated, this changes little. If even one certificate in your estate is renewed by hand, through a ticket, a vendor portal or a calendar reminder, you will soon be doing that task eight times a year instead of once. Somewhere in that process a renewal will be missed, and the first alert will be a customer seeing a browser warning.</p>
<p>I work in identity and access management and GRC, and expired certificates show up in audit findings more often than people expect. They are rarely caused by a missing tool. They happen because nobody had a simple list of "what expires when" that someone actually checks.</p>
<p>This post builds that list with a small Python script: standard library only, no agents, no SaaS. It reads a file of hostnames, connects to each one, and reports days left, issuer and total certificate lifetime. Its exit code makes it easy to plug into cron, CI, or any monitoring system you already run.</p>
<h2>What you'll build</h2>
<pre><code class="language-plaintext">$ python check_certs.py hosts.txt
OK    github.com:443                     78 days left (expires 2027-01-27, lifetime 89d, Sectigo Limited)
OK    python.org:443                     96 days left (expires 2027-02-14, lifetime 396d, GlobalSign nv-sa)
OK    letsencrypt.org:443                83 days left (expires 2027-02-01, lifetime 89d, Let's Encrypt)
ERROR expired.badssl.com:443           [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed
</code></pre>
<p>Look at the <code>lifetime</code> column. That output is real, from November 2026. <a href="http://python.org">python.org</a> still has a 396-day certificate issued before the March cutoff. GitHub and Let's Encrypt are already at 89 days. When <a href="http://python.org">python.org</a> renews, its next certificate can last 200 days at most. The lifetime column shows you which of your certificates will feel the new rules first.</p>
<h2>Prerequisites</h2>
<ul>
<li>Python 3.9 or newer (tested on 3.13)</li>
<li>Outbound access to port 443 of the hosts you want to check</li>
</ul>
<p>Nothing to install.</p>
<h2>Step 1: Fetch the certificate</h2>
<p>Python's <code>ssl</code> module does the hard part. A default context verifies the chain and the hostname, which is what we want: a certificate that fails validation is a problem worth reporting, not something to skip.</p>
<pre><code class="language-python">import socket
import ssl


def fetch_cert(host, port, timeout=10):
    ctx = ssl.create_default_context()
    with socket.create_connection((host, port), timeout=timeout) as sock:
        with ctx.wrap_socket(sock, server_hostname=host) as tls:
            return tls.getpeercert()
</code></pre>
<p><code>getpeercert()</code> returns a dictionary. The fields we need are <code>notBefore</code>, <code>notAfter</code> and <code>issuer</code>.</p>
<h2>Step 2: Turn dates into days</h2>
<p>The dates come back as strings like <code>Oct 6 00:00:00 2026 GMT</code>. <code>ssl.cert_time_to_seconds</code> parses that exact format, so no date-format guessing is needed.</p>
<pre><code class="language-python">from datetime import datetime, timezone


def to_dt(cert_time):
    return datetime.fromtimestamp(ssl.cert_time_to_seconds(cert_time), tz=timezone.utc)


def summarize(host, port, cert, now):
    not_before, not_after = to_dt(cert["notBefore"]), to_dt(cert["notAfter"])
    issuer = dict(x[0] for x in cert["issuer"]).get("organizationName", "?")
    return {
        "host": f"{host}:{port}",
        "issuer": issuer,
        "expires": not_after.date().isoformat(),
        "days_left": (not_after - now).days,
        "lifetime_days": (not_after - not_before).days,
    }
</code></pre>
<p><code>summarize</code> takes <code>now</code> as an argument instead of calling <code>datetime.now()</code> itself. That keeps it testable: you can feed it a fixed certificate and a fixed date and check the math, without touching the network.</p>
<h2>Step 3: Check every host and classify</h2>
<pre><code class="language-python">def check(hosts, warn, now=None):
    now = now or datetime.now(timezone.utc)
    results = []
    for host, port in hosts:
        try:
            r = summarize(host, port, fetch_cert(host, port), now)
            r["status"] = "WARN" if r["days_left"] &lt;= warn else "OK"
        except (OSError, ssl.SSLError) as e:
            r = {"host": f"{host}:{port}", "status": "ERROR", "error": str(e)[:120]}
        results.append(r)
    return results
</code></pre>
<p>A host that fails is reported as <code>ERROR</code> and does not stop the run. DNS failures, timeouts, expired certificates and broken chains all land here. One bad host should never hide the other ninety-nine.</p>
<h2>Step 4: Make the exit code do the alerting</h2>
<p>The full script reads hosts from a file (one per line, <code>host:port</code> for non-443 services, <code>#</code> for comments) and accepts two flags: <code>--warn</code> to set the threshold in days (default 30) and <code>--json</code> for machine-readable output.</p>
<p>The exit code is the important part:</p>
<table>
<thead>
<tr>
<th>Exit code</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td>Every certificate is valid and outside the warning window</td>
</tr>
<tr>
<td>1</td>
<td>At least one certificate expires within <code>--warn</code> days</td>
</tr>
<tr>
<td>2</td>
<td>At least one host could not be checked or failed validation</td>
</tr>
</tbody></table>
<p>Almost every scheduler and monitoring tool understands exit codes. That is what lets the same small script work in very different places.</p>
<p><strong>Cron with email.</strong> Most cron setups mail you any output from a failing job:</p>
<pre><code class="language-plaintext">0 8 * * *  python /opt/certs/check_certs.py /opt/certs/hosts.txt --warn 21 &gt; /tmp/certs.log || cat /tmp/certs.log
</code></pre>
<p><strong>CI.</strong> A scheduled pipeline job that runs the script fails the build when something is close to expiring. The team sees it where they already look.</p>
<p><strong>Your existing monitoring.</strong> With <code>--json</code>, the output can be parsed by Nagios, Zabbix or any tool that runs external checks. Push <code>days_left</code> as a metric if you want a graph per host.</p>
<h2>Choosing the warning threshold</h2>
<p>With 398-day certificates, a 30-day warning was generous. With 47-day certificates it is more than half the certificate's life. A reasonable rule is to warn at about a third of the lifetime:</p>
<table>
<thead>
<tr>
<th>Max lifetime</th>
<th>From</th>
<th>Suggested <code>--warn</code></th>
</tr>
</thead>
<tbody><tr>
<td>200 days</td>
<td>March 2026</td>
<td>30</td>
</tr>
<tr>
<td>100 days</td>
<td>March 2027</td>
<td>21</td>
</tr>
<tr>
<td>47 days</td>
<td>March 2029</td>
<td>14</td>
</tr>
</tbody></table>
<p>If a certificate is renewed automatically, a warning means the automation failed, which is exactly what you want to know. Let's Encrypt clients usually renew at around 30 days left on a 90-day certificate, so a 21-day warning will not fire as long as renewals work.</p>
<h2>Testing without the network</h2>
<p>The parsing and date math can be checked with a fixed certificate dictionary:</p>
<pre><code class="language-python">from datetime import datetime, timezone
from check_certs import summarize

CERT = {
    "notBefore": "Mar 20 00:00:00 2026 GMT",
    "notAfter": "Oct  6 00:00:00 2026 GMT",
    "issuer": ((("countryName", "US"),), (("organizationName", "Let's Encrypt"),)),
}

r = summarize("example.com", 443, CERT, datetime(2026, 9, 26, tzinfo=timezone.utc))
assert r["days_left"] == 10
assert r["lifetime_days"] == 200
</code></pre>
<h2>Limits worth knowing</h2>
<ul>
<li><strong>It checks what the server presents, not what you own.</strong> A certificate installed on a load balancer you forgot to list will not be checked. Building the host list is the real inventory work, and it is worth doing once properly. Certificate Transparency logs, such as <a href="http://crt.sh">crt.sh</a>, can show you every certificate issued for your domains.</li>
<li><strong>Internal CAs.</strong> For hosts using a private CA, pass a context that loads your CA bundle (<code>ctx.load_verify_locations("internal-ca.pem")</code>).</li>
<li><strong>Intercepting proxies.</strong> If your network inspects TLS, you will see the proxy's certificate, not the server's. Run the check from a network path that matches your users'.</li>
<li><strong>It doesn't renew anything.</strong> The goal is to know before it breaks. Renewal belongs to ACME clients (certbot, <a href="http://acme.sh">acme.sh</a>, Caddy, cert-manager) wherever possible. Shorter lifetimes are the industry's way of pushing everyone toward that.</li>
</ul>
<h2>Wrapping up</h2>
<p>You now have a dependency-free check that lists every certificate's days left and lifetime, and fails loudly when something is close to expiring. Run it against your host list today. Any certificate still showing a lifetime over 200 days was issued under the old rules, and it is a good place to start asking how it gets renewed.</p>
<p>The full script and tests are on GitHub: <a href="https://github.com/IsnardMatias/tls-cert-expiry-check">https://github.com/IsnardMatias/tls-cert-expiry-check</a>.</p>
<p>If you'd rather not run and schedule this yourself, I maintain a hosted version on Apify that checks TLS certificate and domain registration expiry for a list of domains and reports what changed since the last run: <a href="https://apify.com/isnard/domain-ssl-expiry-monitor">Domain &amp; SSL Certificate Expiry Monitor</a>.</p>
]]></content:encoded></item></channel></rss>