gohugoio/hugo · error

unsupported hash algorithm: %q, use either md5, sha256, sha3

Error message

unsupported hash algorithm: %q, use either md5, sha256, sha384 or sha512

What it means

The integrity/fingerprint transformer builds a hash.Hash from the algorithm name passed to `resources.Fingerprint`. Only md5, sha256, sha384, and sha512 are supported; any other string hits the default case in newHash and returns this error. The same algorithm feeds both the cache-busting filename suffix and the base64 Subresource Integrity value.

Source

Thrown at resources/resource_transformers/integrity/integrity.go:94

	}

	ctx.Data["Integrity"] = integrity(t.algo, d)
	ctx.AddOutPathIdentifier("." + hex.EncodeToString(d[:]))
	return nil
}

func newHash(algo string) (hash.Hash, error) {
	switch algo {
	case "md5":
		return md5.New(), nil
	case "sha256":
		return sha256.New(), nil
	case "sha384":
		return sha512.New384(), nil
	case "sha512":
		return sha512.New(), nil
	default:
		return nil, fmt.Errorf("unsupported hash algorithm: %q, use either md5, sha256, sha384 or sha512", algo)
	}
}

// Fingerprint applies fingerprinting of the given resource and hash algorithm.
// It defaults to sha256 if none given, and the options are md5, sha256 or sha512.
// The same algo is used for both the fingerprinting part (aka cache busting) and
// the base64-encoded Subresource Integrity hash, so you will have to stay away from
// md5 if you plan to use both.
// See https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
func (c *Client) Fingerprint(res resources.ResourceTransformer, algo string) (resource.Resource, error) {
	if algo == "" {
		algo = defaultHashAlgo
	}

	return res.Transform(&fingerprintTransformation{algo: algo})
}

func integrity(algo string, sum []byte) string {

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Use one of the exact lowercase names: `resources.Fingerprint "sha512"` (or md5, sha256, sha384).
  2. Omit the argument to get the sha256 default: `{{ $r := $css | fingerprint }}`.
  3. Avoid md5 if you emit the value as an `integrity` attribute — browsers reject md5 for SRI.

Example fix

// before
{{ $css := $css | resources.Fingerprint "sha-256" }}
// after
{{ $css := $css | resources.Fingerprint "sha256" }}
Defensive patterns

Strategy: validation

Validate before calling

var validAlgos = map[string]bool{"md5": true, "sha256": true, "sha384": true, "sha512": true}
if !validAlgos[strings.ToLower(algo)] {
    return fmt.Errorf("unsupported hash algorithm %q; use md5, sha256, sha384 or sha512", algo)
}

Prevention

When it happens

Trigger: Calling `{{ $r := $css | resources.Fingerprint "sha1" }}` (or any unsupported/misspelled algorithm like "SHA256", "sha-256", "crc32") in a template. The empty string is fine — it defaults to sha256.

Common situations: Typos or wrong casing in the algorithm argument; copying snippets that use "sha1" from other tooling; passing an options dict or wrong variable as the second argument so a non-algorithm string arrives.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/7b1672409e5a1ed1.json. Report an issue: GitHub ↗.