Using Attack Trees to Spot OAuth Token Leakage in Microservices

Microservices love short‑lived OAuth tokens to keep inter‑service traffic tight. When a token slips out, an attacker can play any service’s role and bypass every fine‑grained ACL. Attack trees let you map every possible leak path and then focus on the high‑impact ones. Below is a practical walk‑through that mixes theory, hands‑on commands, and the real trade‑offs you’ll hit in production.


2‑Layer Attack Tree Structure

Layer Goal Sub‑Goals
Root Token Leakage 1. Capture token in transit2. Retrieve token from storage3. Steal token via compromised service
Branch 1 Capture token in transit a. MITM on unencrypted trafficb. DNS hijack to redirect traffic
Branch 2 Retrieve token from storage a. Read memory of a running containerb. Access persistent storage (DB, KV store)
Branch 3 Steal token via compromised service a. Exploit insecure loggingb. Exploit debug endpointsc. Exploit misconfigured service mesh

Give each leaf a likelihood (0–5) and an impact (0–5). The product is a quick risk weight that tells you where to put your effort first.


1. Capture Token in Transit

1a. MITM on Unencrypted Traffic

Even with HTTPS in place, a mis‑configured ingress can expose a public HTTP endpoint that anyone can sniff.

# Find services that expose HTTP
kubectl get svc -A -o wide | grep -i https

If you spot an HTTP entry, force TLS:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: secure-ingress
spec:
  tls:
  - hosts:
    - api.example.com
    secretName: tls-secret
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 443

Trade‑off: TLS everywhere adds a bit of latency and you’ll need a cert manager, but the overhead is negligible compared to the risk. Automate with cert‑manager or Istio’s automatic mTLS.

1b. DNS Hijack to Redirect Traffic

If your DNS provider is compromised, an attacker can point OAuth calls at a rogue endpoint that captures the bearer token. Mitigate by:

# Verify DNSSEC on your zone
dig +dnssec example.com

Make sure your resolver validates DNSSEC (e.g., systemd-resolved with DNSSEC=yes). In Kubernetes, enable DNSSEC in kube-dns or CoreDNS.


2. Retrieve Token from Storage

2a. Read Memory of a Running Container

Containers share a kernel; a privilege escalation can read another pod’s memory:

# Example: read /proc/pid/environ
cat /proc/$(pgrep -f myservice)/environ | tr '\0' '\n'

Fix: Run as non‑root and lock down /proc with seccomp. Enforce runAsNonRoot: true via PodSecurity or a podSecurityPolicy.

2b. Access Persistent Storage

Tokens sometimes get persisted for audit or debugging. If the store is exposed or mis‑configured, it’s a goldmine.

# Check Redis ACLs
redis-cli ACL LIST

Only let the service account have READ/WRITE, and never expose the store to the public internet. Network policies help:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-redis-external
spec:
  podSelector:
    matchLabels:
      app: redis
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: auth-service

3. Steal Token via Compromised Service

3a. Insecure Logging

A lot of teams log request headers for debugging. If you’re not careful, the token ends up in the logs.

# Example log entry
2026-11-28T12:34:56Z INFO "Request received: Authorization=Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6..."

Solution: Mask tokens before they hit the logger.

func maskToken(header string) string {
    if strings.HasPrefix(header, "Bearer ") {
        return "Bearer <masked>"
    }
    return header
}

Apply this filter globally in Logrus, Zap, or whatever you’re using.

3b. Debug Endpoints

Endpoints like /debug/pprof or /metrics can leak headers if they’re left exposed. Tighten them:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: restrict-debug
spec:
  podSelector:
    matchLabels:
      app: api-service
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: monitoring
    ports:
    - protocol: TCP
      port: 9100

3c. Misconfigured Service Mesh

Service meshes can surface sidecar logs or telemetry that include Authorization. Strip it out in the mesh config:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: hide-auth-header
spec:
  workloadSelector:
    labels:
      app: api-service
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: SIDECAR_INBOUND
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
    patch:
      operation: MERGE
      value:
        request_headers_to_remove:
        - Authorization

Practical Example: End‑to‑End Attack Tree Walkthrough

  1. Root: Token Leakage
  2. Branch 1: Capture token in transit
    • Leaf 1a: MITM on unencrypted traffic
      • Likelihood: 3
      • Impact: 5
  3. Branch 2: Retrieve token from storage
    • Leaf 2b: Access Redis
      • Likelihood: 2
      • Impact: 4
  4. Branch 3: Steal token via compromised service
    • Leaf 3a: Insecure logging
      • Likelihood: 4
      • Impact: 5

Risk weight for Leaf 3a = 4 × 5 = 20 → highest priority. Start by masking logs, then enforce TLS, and finally tighten network policies.


Tooling to Automate Attack Tree Analysis

Tool Use Case Example
OpenSCAP Scan for misconfigurations that could expose tokens oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_pci-dss-3.2 /usr/share/xml/scap/ssg/content/ssg-ubuntu2004-ds.xml
Kube-bench Verify CIS Kubernetes benchmarks, including network policies kube-bench --benchmark cis-1.5.1
Istio Telemetry Detect header leakage in Envoy logs istioctl analyze

Drop these into your CI/CD pipeline. If a scan flags a risk, block the merge until it’s fixed.


Trade‑offs & Operational Considerations

Mitigation Pros Cons
Force TLS everywhere Stops MITM, meets compliance Needs cert management, tiny latency
Mask tokens in logs Keeps audit trails intact Adds code, risk of forgetting
Network policies Limits lateral movement Policy creep, can block legit traffic
Service mesh header filtering Central control Adds complexity, potential perf hit

If you already run a mesh, use its header filtering instead of writing custom code.


Troubleshooting Common Pitfalls

  1. Tokens still show up in logs

    • Make sure the masking runs before the log call.
    • Check third‑party libs that log headers internally.
  2. TLS enforcement blocks legitimate traffic

    • Inspect ingress rules for wrong hostnames or missing TLS secrets (kubectl describe ingress <name>).
  3. Network policy blocks monitoring tools

    • Add an allow rule for the monitoring namespace.
    • Audit with kubectl get networkpolicy -A.

Real‑World Incident Recap (2025)

A mid‑size fintech found OAuth tokens in its audit logs. The culprit was a mis‑configured debug endpoint that leaked request headers. After disabling the endpoint and masking logs, the team realized they needed a formal attack‑tree review. Implementing the workflow above cut token‑leak incidents by 90 % the following year.


Final Checklist

  • All external services use TLS with valid certificates.
  • Network policies block Redis, databases, and debug endpoints from the outside.
  • Logging frameworks mask Authorization headers.
  • Service mesh strips sensitive headers from telemetry.
  • OpenSCAP/Kube‑bench scans run in CI/CD.
  • Attack tree updated quarterly or after major changes.

Treat OAuth token leakage like any other attack surface: map it, score it, and fix the highest‑risk spots first. The structured approach keeps you from chasing every possible vector and lets you focus on the real threats.

See also