Skip to content

IMGPROXY_ENABLE_CLIENT_HINTS has no effect — Config.EnableClientHints is never populated from the env var #1709

Description

@leo020588

IMGPROXY_ENABLE_CLIENT_HINTS doesn't enable Client Hints support at all, on v4.0.12 and on master. Setting it to true has zero observable effect: imgproxy never sends the Vary header it's supposed to when the feature is active, and Width/DPR/Sec-CH-Width/Sec-CH-DPR request headers are silently ignored regardless of the URL's processing options.

Root cause

clientfeatures/config.go's LoadConfigFromEnv() never calls .Parse() for IMGPROXY_ENABLE_CLIENT_HINTS, even though the var is declared and every sibling flag in the same struct is correctly wired:

// clientfeatures/config.go
var (
	IMGPROXY_AUTO_WEBP           = env.Bool("IMGPROXY_AUTO_WEBP")
	IMGPROXY_AUTO_AVIF           = env.Bool("IMGPROXY_AUTO_AVIF")
	IMGPROXY_AUTO_JXL            = env.Bool("IMGPROXY_AUTO_JXL")
	IMGPROXY_ENFORCE_WEBP        = env.Bool("IMGPROXY_ENFORCE_WEBP")
	IMGPROXY_ENFORCE_AVIF        = env.Bool("IMGPROXY_ENFORCE_AVIF")
	IMGPROXY_ENFORCE_JXL         = env.Bool("IMGPROXY_ENFORCE_JXL")
	IMGPROXY_ENABLE_CLIENT_HINTS = env.Bool("IMGPROXY_ENABLE_CLIENT_HINTS") // declared...
)

func LoadConfigFromEnv(c *Config) (*Config, error) {
	c = ensure.Ensure(c, NewDefaultConfig)

	err := errors.Join(
		IMGPROXY_AUTO_WEBP.Parse(&c.AutoWebp),
		IMGPROXY_ENFORCE_WEBP.Parse(&c.EnforceWebp),
		IMGPROXY_AUTO_AVIF.Parse(&c.AutoAvif),
		IMGPROXY_ENFORCE_AVIF.Parse(&c.EnforceAvif),
		IMGPROXY_AUTO_JXL.Parse(&c.AutoJxl),
		IMGPROXY_ENFORCE_JXL.Parse(&c.EnforceJxl),
		// ...but never parsed here, unlike every other flag above.
	)

	return c, err
}

Since c.EnableClientHints stays at its zero value (false), Detector.Features() (clientfeatures/detector.go) returns immediately without ever checking any Client Hints header:

if !d.config.EnableClientHints {
    return f
}

Reproduction (against the official image, no custom build):

docker run -d --name imgproxy-test -p 127.0.0.1:8091:8080 \
  -e IMGPROXY_ENABLE_CLIENT_HINTS=true \
  ghcr.io/imgproxy/imgproxy:v4.0.12

SRC="https://raw.githubusercontent.com/WordPress/wordpress-develop/trunk/tests/phpunit/data/images/canola.jpg"

# No Vary header in the response, and identical output with or without a Width header:
curl -sSI "http://127.0.0.1:8091/insecure/rt:fit/plain/$SRC"
curl -sSI -H "Width: 200" "http://127.0.0.1:8091/insecure/rt:fit/plain/$SRC"
# both: Content-Length: 59187, no Vary header

# Confirms resizing itself works fine — explicit width is fully respected:
curl -sSI "http://127.0.0.1:8091/insecure/resize:fit:200:0/plain/$SRC"
# Content-Length: 5969

Expected: with IMGPROXY_ENABLE_CLIENT_HINTS=true, a request with a Width: 200 header and no explicit width in the URL should be resized accordingly, and the response should carry a Vary: Sec-Ch-Dpr, Dpr, Sec-Ch-Width, Width header.

Actual: the Width header is silently ignored and no Vary header is ever sent, regardless of the env var's value.

Suggested fix: add the missing line to LoadConfigFromEnv:

IMGPROXY_ENABLE_CLIENT_HINTS.Parse(&c.EnableClientHints),

Version: v4.0.12 (also confirmed present on master as of this writing).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions