Skip to content

Security

Refringe edited this page Oct 28, 2026 · 17 revisions

Security

Anchor LFS includes several security features to protect your data and infrastructure.

HMAC-Signed URLs

All transfer URLs (download, upload, verify) are signed with HMAC-SHA256 to prevent unauthorised access and URL tampering.

How It Works

  1. During batch negotiation, the server generates action URLs with two query parameters:
    • exp: Expiration timestamp (Unix epoch)
    • sig: Base64-encoded HMAC-SHA256 signature computed over the operation (download, upload or verify), the full URL and the expiration
  2. When a client uses the URL, the server recomputes the signature for the operation of the route and the URL the request arrived at, and checks expiration
  3. Expired or tampered URLs are rejected with a 403 Forbidden response, as are URLs used for another operation (such as a download URL used to upload), at another scheme or host, or with any other query parameter

The URL a request arrived at starts with base_url when it is set. Without base_url, it is built from the Host header, or from X-Forwarded-Proto and X-Forwarded-Host sent by a peer in trusted_proxies, so transfer requests must reach the server with the same values as the batch request that issued them.

Signed URLs Are Bearer Credentials

A signed URL needs no other credentials: whoever holds it can use it until it expires. It works only for its operation, its object and the server address it was issued for, but it is not tied to a user or a client IP address, the same as the transfer URLs GitHub issues for its own LFS storage. The signature is checked when a transfer starts, so an upload or download that starts before the expiry finishes even if it runs past it.

Signed URLs can show up in:

  • Reverse proxy access logs, which usually record the full request line, sig included. Anchor LFS's own access log records only the path
  • Git LFS debug output: GIT_TRACE=1 and GIT_CURL_VERBOSE=1 print them, so treat a shared trace as sensitive until url_expiry has passed

To limit the exposure:

  • Lower url_expiry (default 10 minutes). Git LFS asks for a new URL when one has expired before its transfer starts, so a shorter expiry mostly costs extra batch requests
  • Restrict who can read proxy logs, or log without the query string (with Nginx, use $uri instead of $request in the log_format)
  • Rotate the signing key to revoke every outstanding URL at once

Batch, lock and download responses send Cache-Control: no-store, so a caching proxy does not keep signed URLs or objects. Presigned S3 URLs follow the same rules: they expire after url_expiry, and rotating the S3 credentials revokes them.

Configuration

[options]
# HMAC signing key (hex-encoded, minimum 32 bytes / 64 hex characters)
# If omitted, auto-generated and saved to <data_directory>/signing.key
#signing_key = ""

# How long signed URLs remain valid (default: 10m)
#url_expiry = "10m"

Signing Key Management

  • Auto-generated: If no signing_key is configured, a random 32-byte key is generated at startup and saved to <data_directory>/signing.key so it persists across restarts
  • Manual: Generate a key with openssl rand -hex 32 and set it in the config, via ANCHOR_LFS_SIGNING_KEY, or in a file named by ANCHOR_LFS_SIGNING_KEY_FILE
  • Minimum size: 32 bytes (64 hex characters)
  • Memory safety: Signing key material is zeroed in memory during graceful shutdown
  • Rotation: See Rotating the Signing Key

Replacing or Overlapping Instances

Anchor LFS supports one running instance per data_directory (see Storage Backends). If two instances overlap, for example while a server is being replaced, they must use the same signing_key; otherwise a URL signed by one instance is rejected by the other. An auto-generated key lives in the data_directory, so set the key explicitly in the configuration whenever the instances do not share that directory.

Rate Limiting

Per-IP rate limiting protects the batch and lock API against abuse using a fixed window counter.

Configuration

[options]
rate_limit_tokens = 600
rate_limit_window = "1m"

Behaviour

  • Per-IP: Each client IP gets its own budget
  • Real IP detection: The client IP is taken from X-Forwarded-For only when the request comes from a peer in trusted_proxies (loopback and private ranges by default), using the rightmost address that is not itself a trusted proxy, or the leftmost when every address is one. Otherwise it is the connecting address, so a directly connected client cannot pick its own IP. See Reverse Proxy.
  • Fixed window: Each IP may make rate_limit_tokens rate-limited requests per rate_limit_window. The budget is restored in full when the window ends, not gradually, so keep the window short: with a 24h window, a client that runs out waits up to a day.
  • Rate-limited endpoints: Batch and all lock operations
  • Not rate-limited: Object download, upload and verify. These need a signed, time-limited URL that only a rate-limited batch request can issue, and one batch request covers up to 1,000 objects (Git LFS sends 100 at a time).
  • Fail-open: If the rate limiter encounters an internal error, requests pass through rather than being rejected (prevents limiter failures from causing outages)
  • 429 response: Rate-limited requests receive HTTP 429 Too Many Requests with a Retry-After header giving the seconds until the window ends. Git LFS clients wait that long and retry.

Input Validation

OID Validation

Object IDs (OIDs) must be exactly 64 hexadecimal characters (representing a SHA-256 hash). Invalid OIDs are rejected by the HTTP layer (422 in a batch or verify request, 404 in a download or upload URL), and the storage adapters independently validate every OID before building a filesystem path or S3 key, so a malformed OID can never reach the disk or the bucket.

Upload Integrity

  • Content-Length header is required for all uploads
  • Uploads exceeding max_upload_size are rejected during batch negotiation
  • Local storage and proxied S3 uploads compute the SHA-256 while receiving the data and store the object only if it matches the declared OID
  • Presigned S3 uploads sign the expected SHA-256 and size into the URL, so the storage provider rejects any other bytes (see Storage Backends)
  • An object whose hash does not match is never written

Lock Path Validation

Lock paths are the repository-relative paths Git LFS sends, and are stored only as text in locks.json. The server answers 422 to a lock request whose path breaks these rules:

  • Must be a relative path in valid UTF-8, with / between directories
  • Rejects empty, . and .. elements, so a leading or trailing /, //, ./ and traversal are all refused
  • Rejects null bytes
  • Allows backslashes, colons and Windows reserved names such as CON, which Git allows in file names on Linux and macOS

The rules are the same whichever operating system the server runs on.

Endpoint Path Sanitisation

Endpoint paths become storage directory names by dropping the leading slash and replacing / with _ (/org/repo becomes org_repo). Paths containing unsafe characters, dot segments or empty segments, and paths whose directory names would collide, are rejected when the configuration is loaded.

Request Body Limits

  • JSON request bodies are capped at 1 MB
  • Batch requests accept a maximum of 1000 objects

Media Type Validation

LFS endpoints strictly validate Content-Type and Accept headers, rejecting requests that don't use application/vnd.git-lfs+json.

HTTP Security

Timeout Configuration

ReadHeaderTimeout: 10 seconds
IdleTimeout:       120 seconds
Upload idle:       60 seconds without data (upload_idle_timeout)
ReadTimeout:       (none; supports large transfers)
WriteTimeout:      (none; supports large transfers)
  • ReadHeaderTimeout protects against slowloris attacks during the header phase
  • IdleTimeout closes idle keep-alive connections after 2 minutes
  • upload_idle_timeout abandons an upload with 408 Request Timeout when its client sends no data for 60 seconds (configurable), so a client trickling bytes cannot hold a connection and a temporary file open indefinitely
  • Total read and write timeouts are intentionally omitted to support large file transfers without killing legitimate connections

Streaming

Uploads are streamed directly to storage without in-memory buffering, preventing memory exhaustion from large files.

Metrics Endpoint

The optional metrics endpoint has no authentication, and it shows endpoint paths, request rates and free disk space. It is served only on metrics_address, never on listen_address, so bind that to loopback or a private network and keep it out of the reverse proxy.

Reverse Proxy Security

When running behind a reverse proxy:

Warning

Always set base_url in production. Without it, the server relies on X-Forwarded-* headers to construct transfer URLs. If a reverse proxy is misconfigured or absent, clients could manipulate these headers to redirect LFS transfers to a malicious server. Setting base_url eliminates this attack surface entirely.

  1. Use base_url: Setting base_url in the configuration eliminates reliance on X-Forwarded-* headers, removing header-based attack surface
  2. Header validation: The X-Forwarded-Host header is validated as a URL authority to prevent header injection
  3. Restrict direct access: Bind the server to 127.0.0.1 or use Docker networking so it's only accessible through the proxy

See Reverse Proxy for detailed proxy configuration.

Authentication Security

  • GitHub Personal Access Tokens are never logged or stored
  • Auth cache entries are keyed by a hash of the token (not the token itself)
  • Each token is checked for its own contents permission, not only its owner's role, so a read-only or narrowly scoped token cannot upload, take locks or read a private repository it was not granted
  • Transient authentication failures (network errors) are not cached, preventing permanent lockouts from temporary issues
  • The shared HTTP client for GitHub API calls uses a 10-second timeout

See Authentication for details.

Next Steps

Clone this wiki locally

⌂ 换网址