Author: canutethegreat

  • Threat modeling with STRIDE for a small team

    Threat modeling with STRIDE for a small team

    Most small teams I talk to think threat modeling is something big companies do with a dedicated security architect, a two-week engagement and a 40-page document nobody reads afterwards. That version exists, and it’s mostly a waste. The version that works for a team of five engineers fits in a 90-minute meeting around a whiteboard and ends with a handful of tickets. STRIDE is the tool I reach for because it gives a room full of people a structured way to ask “what could go wrong here?” without needing a security specialist to lead every question.

    What STRIDE actually is

    Data flow diagram of a payment webhook receiver with three trust boundaries and STRIDE threat badges on each boundary-crossing flow

    STRIDE came out of Microsoft in 1999, from Loren Kohnfelder and Praerit Garg, and was popularised by Adam Shostack’s book Threat Modeling: Designing for Security. It’s a mnemonic for six threat categories, each one the violation of a property you want your system to have:

    • Spoofing violates authentication. Someone claims to be a user, a service or a host they aren’t.
    • Tampering violates integrity. Data in transit, at rest or in memory gets modified.
    • Repudiation violates non-repudiation. Someone does something and you can’t prove it.
    • Information disclosure violates confidentiality.
    • Denial of service violates availability.
    • Elevation of privilege violates authorization. A user or component gets capabilities it shouldn’t have.

    That’s it. It isn’t a methodology on its own, and it doesn’t rank anything. It’s a checklist of question shapes. The value is that it stops the discussion from collapsing into whatever the loudest person in the room worried about last week, which in my experience is usually SQL injection.

    Start from four questions, not from the acronym

    Shostack frames the whole exercise as four questions, and the Threat Modeling Manifesto (2020) kept them:

    1. What are we working on?
    2. What can go wrong?
    3. What are we going to do about it?
    4. Did we do a good enough job?

    STRIDE only answers question two. Teams that skip question one end up applying STRIDE to a vague mental picture of “the system”, which produces vague threats like “an attacker could spoof a user”. True, useless.

    So answer question one concretely. Pick one feature or one change, not the whole platform. “We’re adding a webhook receiver that accepts events from our payment provider and updates order status” is a good scope. “Our backend” is not.

    Draw a data flow diagram with trust boundaries

    The diagram is where most of the value comes from, and it should take 15 to 20 minutes. You need four kinds of things:

    • External entities: users, third-party services, anything you don’t control.
    • Processes: your services, workers, lambdas.
    • Data stores: databases, queues, buckets, caches.
    • Data flows: arrows between them, labelled with what moves and over what protocol.

    Then draw trust boundaries, the dashed lines where the level of trust changes. Internet to your load balancer. Your API to the database. Your worker to the third-party API. Your app to the admin interface. If a flow crosses a dashed line, that’s where you spend your time. Flows entirely inside one trust zone rarely produce interesting threats.

    For the webhook example, the boundaries are the payment provider to your public endpoint, your receiver to the queue, and the worker to the orders database. Three crossings. That’s a manageable meeting.

    Walk STRIDE per element

    The variant that works best for small teams is STRIDE-per-element. Not every category applies to every kind of element, and the classic mapping keeps the discussion short:

    • External entities: spoofing and repudiation.
    • Processes: all six.
    • Data stores: tampering, information disclosure, denial of service, and repudiation if the store is a log.
    • Data flows: tampering, information disclosure, denial of service.

    Go element by element along the flows that cross a boundary and ask each applicable question out loud. For the webhook receiver it might go like this:

    • Spoofing: can anyone on the internet POST a fake “payment succeeded” event? Do we verify the provider’s signature, and do we compare it in constant time?
    • Tampering: can a valid event be replayed? Is there a timestamp in the signed payload, and do we reject old ones?
    • Repudiation: if an order flips to paid by mistake, can we show which event did it and where it came from?
    • Information disclosure: do our error responses leak stack traces or internal hostnames to the caller?
    • Denial of service: what happens if someone sends 10,000 large bodies a second? Is there a size limit before we parse JSON?
    • Elevation of privilege: does the worker’s database role need to write to anything except the orders table?

    Every one of those is a concrete, testable question, and most of them are a few lines of code to fix.

    Record threats as tickets, not as a document

    The output of the session is a list of threats, each with a decision. Mitigate, accept, transfer or eliminate the feature. I like a plain table in the repo next to the code, because it gets reviewed in pull requests and it ages with the system:

    | ID | Element            | STRIDE | Threat                                  | Decision  | Ticket   |
    |----|--------------------|--------|-----------------------------------------|-----------|----------|
    | W1 | Webhook endpoint   | S      | Forged event without valid signature    | Mitigate  | PAY-412  |
    | W2 | Webhook endpoint   | T      | Replay of a captured valid event        | Mitigate  | PAY-413  |
    | W3 | Receiver -> queue  | D      | Unbounded body size exhausts memory     | Mitigate  | PAY-414  |
    | W4 | Worker DB role     | E      | Role can write to users table           | Mitigate  | PAY-415  |
    | W5 | Provider outage    | D      | Events delayed for hours                | Accept    | -        |

    Accepted risks are fine. Write down who accepted them. A threat model where everything is “mitigate” usually means nobody was honest about the effort.

    Making it stick on a small team

    Teams rarely fail by modeling badly. They model once at a kickoff and never again, and a few habits help prevent that.

    Tie it to design review. If a change adds a new trust boundary crossing, a new external entity or a new data store with sensitive data, it gets a STRIDE pass. Everything else doesn’t. That keeps it rare enough that people don’t resent it.

    Rotate who facilitates. The facilitator’s job is to keep the group moving through the elements and to stop the session from becoming a design argument. Any engineer can do that after watching it twice, and the person who facilitates tends to start thinking this way in code review too.

    Keep the diagram in the repo as text. A diagram drawn in a SaaS whiteboard is dead the day the meeting ends. Mermaid, PlantUML or OWASP Threat Dragon’s JSON files all diff fine. Microsoft’s Threat Modeling Tool is also free if your team is on Windows and wants STRIDE suggestions generated from the diagram, though I find the generated list too long for a small team to triage.

    Revisit question four. A month after the feature ships, spend ten minutes asking whether any incident, bug report or pentest finding touched an element you modeled. If one did and the model missed it, that’s the most useful feedback you’ll get about your process.

    Where STRIDE falls short

    STRIDE is good at technical threats along data flows. It’s weak on abuse of legitimate functionality, like a referral program being farmed, and on privacy harms, where LINDDUN is a better fit. It also says nothing about likelihood. When a session produces more threats than you can fix, rank them by what an attacker can reach from outside your trust boundaries first, and by what you’d have to explain in an incident report second. That’s crude, and it’s still better than ranking by gut feeling about which bug sounds scariest.

    I’ve watched a five-person team find a missing webhook signature check, an admin endpoint reachable from the public load balancer and a worker with database superuser rights, all in one 90-minute session. Nobody in the room was a security specialist; they drew the thing and asked the questions in order.

  • Cloud IAM misconfigurations: public buckets, broad roles and Capital One

    Cloud IAM misconfigurations: public buckets, broad roles and Capital One

    Most cloud breaches I’ve read about didn’t need a zero-day in the provider. They needed a bucket readable by the world, a role that could do far more than its job required, or both. The provider did exactly what it was told. The configuration just told it the wrong thing.

    The 2019 Capital One breach is still the best case study I know. It shows how a small flaw in one place becomes a large one when identity permissions are too broad.

    What happened at Capital One

    Sequence diagram of the Capital One 2019 breach chain with the control that breaks each step

    The public record, from the Justice Department’s case and the bank’s own disclosures, goes roughly like this. Capital One ran a web application firewall on EC2 in front of some of its applications. The WAF was misconfigured so that an outside attacker could make it send requests on their behalf, a server-side request forgery (SSRF).

    From the EC2 instance, the attacker requested the instance metadata service at 169.254.169.254. At the time, that service answered any plain HTTP GET from the instance, including the temporary credentials for the IAM role attached to it. So the SSRF returned working AWS credentials.

    The role attached to the WAF instance could list and read a large number of S3 buckets, more than 700 according to the criminal complaint, which held credit card application data. Data on about 100 million people in the US and 6 million in Canada was taken. The OCC fined Capital One $80 million in 2020, and the attacker was convicted in 2022.

    Notice that no single control failed outright. The WAF had a configuration bug. The metadata service worked as designed. The role had convenient permissions. The breach needed all three.

    Fix the metadata path first

    AWS introduced IMDSv2 in November 2019, a few months after the breach became public. It requires a session token obtained with a PUT request carrying a custom header, and by default it won’t answer requests that have passed through too many network hops. Most SSRF bugs can only make simple GET requests, so IMDSv2 blocks the exact path used at Capital One.

    Make it mandatory, not optional. For existing instances:

    aws ec2 modify-instance-metadata-options \
      --instance-id i-0123456789abcdef0 \
      --http-tokens required \
      --http-put-response-hop-limit 1

    Then stop new instances launching without it. A service control policy at the organisation level enforces that across every account:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "RequireIMDSv2",
          "Effect": "Deny",
          "Action": "ec2:RunInstances",
          "Resource": "arn:aws:ec2:*:*:instance/*",
          "Condition": {
            "StringNotEquals": { "ec2:MetadataHttpTokens": "required" }
          }
        }
      ]
    }

    Containers have the same problem one layer down. A pod on a node that can reach the node’s metadata endpoint can borrow the node’s role. Use per-workload identities (IRSA or EKS Pod Identity on AWS, Workload Identity on GCP and Azure) and keep the hop limit at 1 so containers can’t reach node credentials.

    Keep roles narrow

    The WAF needed, at most, to write its own logs. It didn’t need to read customer data. Broad roles usually happen for understandable reasons: someone was in a hurry, a wildcard made the error go away, and nobody revisited it.

    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "*"
    }

    That statement is a bug waiting to be reported. A role for a component should name the actions and resources it actually uses:

    {
      "Effect": "Allow",
      "Action": ["s3:PutObject"],
      "Resource": "arn:aws:s3:::example-waf-logs/waf/*"
    }

    Writing these by hand is tedious, so use the tools built for it. IAM Access Analyzer can generate a policy from the role’s real activity in CloudTrail, and the “last accessed” data shows which granted services a role has never touched. Start broad in development if you must, then generate the narrow policy from observed use before production.

    Two more patterns keep the blast radius small. Put sensitive data in separate accounts from internet-facing workloads, because cross-account access must be granted explicitly on both sides. And add resource policies on the most sensitive buckets that deny access from anything outside your expected principals or network paths, using conditions such as aws:PrincipalOrgID or aws:SourceVpce. Even if a role is over-granted, the bucket says no.

    Public buckets: turn the default on everywhere

    Accidentally public buckets have exposed voter rolls, military files and plenty of corporate backups over the years. The fix is now mostly one setting. S3 Block Public Access overrides any ACL or bucket policy that would make data public, and since April 2023 AWS enables it, with ACLs disabled, on all new buckets by default. Buckets created before that keep whatever they had, so set it at the account level too:

    aws s3control put-public-access-block \
      --account-id 111122223333 \
      --public-access-block-configuration \
      BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true

    If something genuinely needs to be public, like static website assets, serve it through a CDN with origin access control from a bucket that stays private, or put it in a dedicated account where public is the expected state and nothing sensitive lives.

    Other clouds have equivalents: public access prevention on Google Cloud Storage and disabling anonymous blob access on Azure storage accounts. Same idea, different flag.

    Detect what you can’t prevent

    Prevention won’t be perfect, so watch for the signs. GuardDuty flags EC2 instance credentials being used from outside AWS, which is the signature of stolen metadata credentials. CloudTrail data events for S3 on sensitive buckets will show a role suddenly listing hundreds of buckets it normally never touches. That pattern was visible in the Capital One case, and it’s a detection worth writing. AWS Config rules or a CSPM tool can continuously report public buckets, roles with wildcard actions, and instances without IMDSv2.

    A quick audit you can run this week

    Find every role with * in its actions or resources, and work through them starting with roles attached to internet-facing compute. Check that IMDSv2 is required across all instances and launch templates. Confirm account-level Block Public Access everywhere. Pick your three most sensitive buckets and read their access logs for a week.

    None of this is exotic. Capital One had a large, capable security team, and the breach still came down to a convenient role and a metadata endpoint that answered too easily. Most of us have less, which is all the more reason to make the defaults strict.

  • SPF, DKIM and DMARC, and why p=none isn’t enough

    SPF, DKIM and DMARC, and why p=none isn’t enough

    Email was designed in an era when every host on the network trusted every other host. SMTP lets any server claim to send mail from any address, and the From: header that a person actually reads is just text the sender typed. Three standards were added later to patch that: SPF, DKIM and DMARC. Most domains I look at have all three records published, and a fair number still aren’t protected, because their DMARC policy says p=none.

    SPF: which servers may send

    Flowchart of how a receiving mail server evaluates SPF, DKIM, alignment and the DMARC policy

    Sender Policy Framework (RFC 7208) lets a domain publish, in DNS, the list of servers allowed to send mail for it. A receiving server takes the domain from the SMTP envelope sender (the MAIL FROM, also called the return path), looks up its SPF record, and checks whether the connecting IP is on the list.

    example.com.  IN TXT  "v=spf1 ip4:198.51.100.0/24 include:_spf.google.com include:sendgrid.net -all"

    SPF has two well-known weak spots. It checks the envelope sender, not the From: header the recipient sees, so on its own it does nothing against spoofing that address. It also breaks on forwarding, because the forwarding server isn’t on your list.

    There’s also a hard limit that catches growing companies: evaluating an SPF record may trigger at most 10 DNS lookups (include, a, mx, ptr, exists and redirect each count). Every SaaS tool you add with an include: eats into that budget, and when you exceed it the result is a permerror, which many receivers treat as a failure. I’ve seen a marketing team knock out a company’s outbound mail by adding one more vendor.

    DKIM: a signature on the message

    DomainKeys Identified Mail (RFC 6376) has the sending server sign selected headers and the body with a private key. The signature goes in a DKIM-Signature header naming the signing domain (d=) and a selector (s=). The receiver fetches the public key from DNS at selector._domainkey.domain and verifies.

    s1._domainkey.example.com.  IN TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."

    DKIM survives plain forwarding because the signature travels with the message, though it breaks if a mailing list rewrites the subject or appends a footer. Use 2048-bit RSA keys, and rotate them. In 2012 a mathematician found that Google was signing with a 512-bit key that he could factor, which led to a quick round of key upgrades across large providers.

    The catch: DKIM proves a message was signed by some domain (d=). It doesn’t, on its own, say that domain has anything to do with the From: address.

    DMARC: tying it to the From header

    DMARC (RFC 7489) is what makes the first two useful against spoofing. It adds alignment: a message passes DMARC only if SPF passes for a domain that matches the From: domain, or DKIM passes with a d= that matches the From: domain. Relaxed alignment (the default) accepts the same organisational domain, so mail.example.com aligns with example.com. Strict alignment requires an exact match.

    The DMARC record says what receivers should do with failing mail, and where to send reports:

    _dmarc.example.com.  IN TXT  "v=DMARC1; p=reject; rua=mailto:[email protected]; adkim=r; aspf=r"

    The p= tag is the policy: none, quarantine or reject.

    Why p=none isn’t protection

    A p=none policy tells receivers: evaluate DMARC, send me reports, but deliver failing mail exactly as you would have anyway. It’s monitoring only. Anyone can still send mail with your domain in the From: header to your customers, suppliers or finance team, and DMARC won’t stop them.

    Monitoring is the right first step, which is why p=none exists. The trouble is that many organisations treat publishing it as the finish line. Google and Yahoo’s bulk sender rules, in effect since February 2024, require a DMARC record for anyone sending more than 5,000 messages a day to their users, but the minimum they ask for is p=none. Plenty of domains published a record and stopped there.

    Business email compromise is where this hurts most. A convincing invoice from [email protected] is much easier to pull off when your domain doesn’t ask receivers to reject spoofs. With p=reject, major mailbox providers drop exact-domain spoofs outright. Attackers then fall back to lookalike domains. That’s still a problem, but a more detectable one.

    Getting from none to reject

    The path is boring, and it works.

    First, publish p=none with an rua address and actually read the aggregate reports. They’re XML, so use a parser or a reporting service rather than reading them by hand. Within a couple of weeks you’ll see every source sending mail as your domain: your mail platform, the CRM, the ticketing system, the HR tool somebody bought on a credit card, and the spoofers.

    Second, fix each legitimate source. Ideally each one signs with DKIM using your domain as d=, which most SaaS senders support through a CNAME to their key. Where you can only get SPF alignment, make sure the vendor uses a return path on your domain. Retire sources nobody can explain.

    Third, move to p=quarantine, then to p=reject. RFC 7489 provides the pct= tag to apply the policy to a percentage of failing mail, which lets you ramp up gradually. Note that the DMARCbis revision in the IETF drops pct in favour of a simpler testing flag, so don’t build long-term tooling around it.

    Don’t forget domains that send no mail at all. Parked domains are attractive for spoofing because nobody watches them. Lock them down completely:

    parked-example.com.          IN TXT  "v=spf1 -all"
    _dmarc.parked-example.com.   IN TXT  "v=DMARC1; p=reject;"

    Also check the sp= tag, which sets the policy for subdomains. If you leave it out, subdomains inherit p=, which is usually what you want.

    What DMARC doesn’t do

    DMARC protects the exact domain. It does nothing about examp1e.com or example-billing.com, nor display-name tricks where the friendly name says “Example Payroll” over an unrelated address. Those need receiver-side defences, user training and monitoring for newly registered lookalikes. MTA-STS (RFC 8461) and TLS reporting are separate pieces that protect mail in transit, and BIMI only becomes available once you’re at quarantine or reject.

    If you run a domain and its DMARC record still says p=none after a few months, you’ve built the monitoring and switched off the alarm. Read the reports, fix your senders, and finish the rollout.