gohugoio/hugo · error

unsupported hash algorithm

Error message

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

What it means

Returned by newHash when the algorithm string passed to Fingerprint/integrity is not one of the four supported values. Hugo's integrity transformer only supports md5, sha256, sha384, sha512; any other string (including typos or sha1) hits the default branch.

Solutions

  1. Use one of the exact lowercase tokens: md5, sha256, sha384, or sha512.
  2. If you omitted the algorithm intending the default, pass "" or nothing — Fingerprint defaults to sha256 when algo is empty.
  3. Avoid md5 if you also rely on Subresource Integrity (SRI); prefer sha384 or sha512 for SRI-compatible output.

Example fix

// before
{{ $fp := $r | fingerprint "sha1" }}

// after
{{ $fp := $r | fingerprint "sha256" }}
Defensive patterns

Strategy: validation

Validate before calling

var supportedHash = map[string]bool{"md5": true, "sha256": true, "sha384": true, "sha512": true}

func validHashAlgo(a string) bool { return supportedHash[a] }

Type guard

// Go guard narrowing to a supported algorithm.
func normalizeAlgo(a string) (string, bool) {
    allowed := []string{"md5", "sha256", "sha384", "sha512"}
    for _, s := range allowed { if s == a { return s, true } }
    return "", false
}

Prevention

When it happens

Trigger: Calling resources.Fingerprint res algo with algo set to an unsupported value, e.g. "sha1", "SHA256" (wrong case), "sha-256", or "" with a downstream override. Also reached by the | integrity template function when given a bad algorithm name.

Common situations: Passing 'sha1' for legacy compatibility, a casing mismatch, a hyphenated name from a different tool (sha-256), or an empty/undefined variable that resolves to a garbage string.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/7b1672409e5a1ed1. Report an issue: GitHub.

Appendix: 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 52c9bd7908)