ExAws.Operation.S3 (ExAws v2.8.1)

Copy Markdown View Source

Holds data necessary for an operation on the S3 service.

Request host

By default the bucket is placed in the request path. Two S3 config options move it into the request host instead:

  • virtual_host: true - the request is sent to <bucket>.<host>. The bucket may only contain letters, digits, ., - and _, so the request always stays under the configured host.
  • virtual_host: true, bucket_as_host: true - the bucket name is used as the whole hostname (for example a CNAME pointing at a bucket).

Security of bucket_as_host

With bucket_as_host: true whoever chooses the bucket name chooses the server the signed request is sent to, including its body, the Authorization header and any x-amz-security-token. A name such as attacker.example, localhost or 169.254.169.254 is a perfectly valid hostname, so no character check can prevent this. Never pass an untrusted bucket name when bucket_as_host is enabled.

If bucket names are not fully under your control, set bucket_as_host_allowlist to the hostnames you trust. Any other bucket raises ArgumentError before a request is built:

config :ex_aws, :s3,
  virtual_host: true,
  bucket_as_host: true,
  bucket_as_host_allowlist: ["assets.example.com", "media.example.com"]

Hostnames are compared case-insensitively. When the option is not set, any syntactically valid hostname is accepted.

Summary

Types

t()

@type t() :: %ExAws.Operation.S3{
  body: term(),
  bucket: term(),
  headers: term(),
  http_method: term(),
  params: term(),
  parser: term(),
  path: term(),
  resource: term(),
  service: term(),
  stream_builder: term()
}