ory/hydra · error

failed to parse URL

Error message

failed to parse URL

What it means

Returned by readFile when url.Parse rejects the source string, i.e. before any scheme dispatch happens. The source itself is not a parseable URL — control characters, invalid percent-escapes, or a malformed scheme cause this. This is an input-format error in the source argument.

Source

Thrown at oryx/osx/file.go:151

// - https://host.com/path/to/file
// - http://host.com/path/to/file
// - base64://<base64 encoded string>
//
// For more options, check:
//
// - WithDisabledFileLoader
// - WithDisabledHTTPLoader
// - WithDisabledBase64Loader
// - WithBase64Encoding
// - WithHTTPClient
func ReadFileFromAllSources(source string, opts ...Option) (bytes []byte, err error) {
	return readFile(source, newOptions().apply(opts))
}

func readFile(source string, o *options) (bytes []byte, err error) {
	parsed, err := url.Parse(source)
	if err != nil {
		return nil, errors.Wrap(err, "failed to parse URL")
	}

	switch parsed.Scheme {
	case "":
		if o.disableFileLoader {
			return nil, errors.New("file loader disabled")
		}

		//#nosec G304 -- false positive
		bytes, err = os.ReadFile(source)
		if err != nil {
			return nil, errors.Wrap(err, "unable to read the file")
		}
	case "file":
		if o.disableFileLoader {
			return nil, errors.New("file loader disabled")
		}

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Sanitize or percent-encode the source string so net/url can parse it
  2. Remove control characters or stray whitespace from the configured source
  3. Validate sources with url.Parse at configuration load time
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at oryx/osx/file.go:151 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/d22b1ce821a9a788. Report an issue: GitHub.