User-Preferred Gateway Detection

status: reliable
History
Commit History
Feedback
GitHub ipfs/specs (inspect source, open issue)

1. Introduction

This document defines conventions for how applications can identify an available IPFS Gateway, and how IPFS Gateway implementations can signal their own endpoint to client applications.

2. Specification

There are two ways of hinting the user-preferred gateway URL:

Applications SHOULD evaluate these hints in order and stop on the first match:

  1. Check if a valid IPFS_GATEWAY environment variable is set
  2. Check if a valid gateway file is present at one of the well-known filesystem paths

If a hint is present but its value is not a valid URL, applications SHOULD report an error instead of silently falling back to the next hint.

If no valid hint is found, gateway selection is unconfigured. Applications SHOULD NOT fall back to a hard-coded non-localhost gateway (see Security below).

2.1 IPFS_GATEWAY Environment Variable

When the IPFS_GATEWAY environment variable is set, the value SHOULD be interpreted as the URL of the IPFS Gateway to use. The value holds a single URL, following the same rules as the first line of the gateway file.

Applications SHOULD give this variable precedence over gateway URLs from internal application configuration. Explicit per-invocation user input, such as a command-line argument, MAY take precedence over this variable.

2.2 The gateway Configuration File

Client application SHOULD check if file is present at specific filesystem paths, in order:

  1. If IPFS_PATH is set, try $IPFS_PATH/gateway
  2. Otherwise, if HOME is set, try $HOME/.ipfs/gateway (the default IPFS_PATH location)
  3. Try OS-specific paths:
    • Linux/Unix:
      1. $XDG_CONFIG_HOME/ipfs/gateway (only if XDG_CONFIG_HOME is set)
      2. $HOME/.config/ipfs/gateway (default XDG location)
      3. /etc/ipfs/gateway (system-wide)
    • Windows:
      1. %LOCALAPPDATA%/ipfs/gateway (local user)
      2. %APPDATA%/ipfs/gateway (roaming user)
      3. %PROGRAMDATA%/ipfs/gateway (system-wide)
    • macOS:
      1. $HOME/Library/Application Support/ipfs/gateway (user)
      2. /Library/Application Support/ipfs/gateway (system-wide)

When gateway file is present, the file contents MUST be interpreted as an ASCII text file with one URL per line (separated by \n or \r\n).

The first line MUST be a valid http:// or https:// URL consisting only of a scheme, host, and optional port, with no path, query, or fragment (e.g., http://127.0.0.1:8080). The gateway at this URL MUST support [trustless-gateway], SHOULD support [path-gateway] when deserialized responses are required, and SHOULD support [subdomain-gateway] when Origin isolation is required.

Implementations MAY support additional lines for gateway pools or failover. Additional lines, when present, MUST follow the same URL rules, and empty lines MUST be ignored. Implementations that do not support multiple URLs SHOULD read only the first line and ignore the rest of the file.

2.3 Security

Applications that integrate IPFS support via HTTP gateways:

2.4 Privacy and User Control

Applications SHOULD NOT default to public gateways (see Security above). Instead, applications SHOULD suggest to the user how to run a local node.

2.5 Compatibility and Testing

Implementers SHOULD test against implementations mentioned in ipip-0280 as the baseline for making decisions around maximizing interoperability.

A. References

[path-gateway]
Path Gateway Specification. Henrique Dias; Marcin Rataj. 2026-03-05. URL: https://specs.ipfs.tech/http-gateways/path-gateway/
[rfc2119]
Key words for use in RFCs to Indicate Requirement Levels. S. Bradner. IETF. March 1997. Best Current Practice. URL: https://www.rfc-editor.org/rfc/rfc2119
[subdomain-gateway]
Subdomain Gateway Specification. Marcin Rataj; Adrian Lanzafame; Vasco Santos; Oli Evans; Thibault Meunier; Steve Loeppky. 2025-04-03. URL: https://specs.ipfs.tech/http-gateways/subdomain-gateway/
[trustless-gateway]
Trustless Gateway Specification. Henrique Dias; Marcin Rataj; Héctor Sanjuán; Adin Schmahmann. 2026-03-05. URL: https://specs.ipfs.tech/http-gateways/trustless-gateway/

B. Acknowledgments

We gratefully acknowledge the following individuals for their valuable contributions, ranging from minor suggestions to major insights, which have shaped and improved this specification.

Editors
Mark Gaiser GitHub
Marcin Rataj (Shipyard) GitHub
Special Thanks
Tim Perry GitHub
Dietrich Ayala GitHub
Dave Justice GitHub
dirkf GitHub
Daniel Norman GitHub
1
  1. No bibliographic reference for key "ipip-0280".