Docs Version v0.2
Docs menu

Security

Fuzzing

Changed 5 min readv0.2

On this page

Introduction

"Fuzzing" is testing a program with a stream of generated inputs, most of them malformed, to find one that crashes it or never returns. Go has it built in: a "fuzz target" is a test function that the fuzzer feeds with inputs.

Every parser that reads what a stranger sends, before anything about the sender is known, has a native Go fuzz target. A panic in any of them would be an unauthenticated crash of a listener.

This page lists the targets, shows how to run one, and records what fuzzing has found. It also gives the files that will run the targets continuously, once the repository is public. It is for a contributor adding a parser, and for a reviewer checking how hostile input is tested.

The targets

Among the protocols the targets read are the Lightweight Directory Access Protocol (LDAP), Remote Authentication Dial-In User Service (RADIUS) and System for Cross-domain Identity Management (SCIM). Others read Proof Key for Code Exchange (PKCE) verifiers and Demonstrating Proof of Possession (DPoP) proofs.

Each target ends in an answer for any input and, where there is one, holds a property as well:

PackageWhat it readsTargets
internal/ldapdan LDAP search filter, from anybody who reaches the portFuzzDecodeFilter, decoding and then evaluating against an entry
internal/radiusa RADIUS datagram, and the EAP and EAP-TLS framing inside itFuzzDecode (every attribute read is bytes of the packet), FuzzDecodeEAP
internal/proxyprotoa PROXY v2 header, the first bytes on the listenerFuzzRead: never reads past the header it reports
internal/clientipX-Forwarded-For and ForwardedFuzzClientIP: answers an address, or nothing for unknown, never text a client wrote
internal/jsonstrictevery JSON body, firstFuzzNoDuplicateKeys: a member named twice is always seen
internal/oauthan authorization request, a PKCE verifierFuzzValidateAuthz, FuzzVerifyPKCE
internal/tokensa bearer token presented to a resourceFuzzVerifyAccessToken
internal/dpopa DPoP proofFuzzVerify
internal/rarauthorization_detailsFuzzParse, then validation
internal/samlan AuthnRequest's or a response's XMLFuzzUnmarshal
internal/scima SCIM list filter and PATCH pathFuzzParseListFilter, FuzzParsePath
internal/oid4vpa wallet's answerFuzzVerifyMdoc (unsigned bytes are never trusted), FuzzReadDCAPIAnswer, FuzzParsePath
internal/sdjwta wallet's disclosuresFuzzParse
internal/oidfedan entity statementFuzzParseStatement
internal/umaresource registrations, permission requests, scopes, claim tokensFuzzParseResourceDescription, FuzzParseScope
internal/authzenan access evaluationFuzzDecode

Running one

To fuzz one target for a minute, name it and its package:

Shellcd enginego test -run='^$' -fuzz='^FuzzDecodeFilter$' -fuzztime=1m ./internal/ldapd/

A failing input is written to the package's testdata/fuzz/<target>/. From then on, go test runs it as an ordinary case, so a fix stays fixed. Without -fuzz, go test runs every target's seeds, which is how the suite and continuous integration (CI) exercise them.

For a short run, add -fuzzminimizetime=5s. Go minimises each new input that reaches new code before it reports progress again, for up to a minute by default. So the progress line can sit still for many seconds while the worker is busy.

A run that ends in the middle of that can be reported as failed, with no failing input. Twice here a 20-second run did so. With minimisation limited, the same targets ran half a million inputs without stopping.

What it found

On its first run, the fuzzer found a loop in internal/jsonstrict. Every JSON body that is checked for duplicate members passes through it: authorization_details, an AuthZEN evaluation, a Security Event Token, and a User-Managed Access (UMA) resource registration.

Malformed JSON inside an array or an object, such as {"evaluations":[{}R}, never returned. Each level answered the token it could not read by returning, and the loop around it asked again at the same byte. A body of twenty bytes kept a core busy indefinitely. authorization_details reaches it in an unauthenticated authorization request.

The fuzzer found it three ways: through AuthZEN, through jsonstrict itself, and through authorization_details. Those inputs are kept under testdata/fuzz/, and TestMalformedJSONEndsTheWalk holds the fix with a time limit.

Continuous fuzzing

engine/fuzz/oss-fuzz-build.sh builds every target with compile_native_go_fuzzer, the helper OSS-Fuzz's and ClusterFuzzLite's Go build image provides.

TestEveryFuzzTargetIsBuiltForOSSFuzz (internal/docsync) fails when a target is missing from the script, or when the script names one that no longer exists. It also fails when a package in the table above loses its last target.

OSS-Fuzz takes open-source projects, so the project is submitted once the repository is public. Its projects/signari/ directory holds three files. The homepage, the repository address and the contact are left for whoever submits it. The first file, project.yaml, describes the project:

YAML# project.yamlhomepage: "<the project's homepage>"language: goprimary_contact: "<security contact>"main_repo: "<the repository's public address>"fuzzing_engines:  - libfuzzersanitizers:  - address

The Dockerfile clones the repository and copies the build script in:

Dockerfile# DockerfileFROM gcr.io/oss-fuzz-base/base-builder-goRUN git clone --depth 1 <the repository's public address> signariWORKDIR $SRC/signariCOPY build.sh $SRC/

The build.sh runs the repository's own build script:

Shell# build.sh#!/bin/bash -euexec "$SRC/signari/engine/fuzz/oss-fuzz-build.sh"

Until then, the same script runs under ClusterFuzzLite, which fuzzes a private repository from its own CI. That would spend the repository's CI minutes on every run, so it is not switched on here.