Skip to content

Latest commit

 

History

History
213 lines (187 loc) · 15.8 KB

CHANGELOG.md

File metadata and controls

213 lines (187 loc) · 15.8 KB

Changelog

This file lists the changes in each release that affect code using the library. The format follows Keep a Changelog. Releases before 3.0.0 are listed in the Git tags.

3.0.0 - Unreleased

Version 3 encodes URLs by the rules of RFC 3986, adds a way to sign URLs, signs S3 URLs with Signature Version 4, and fixes several bugs in the S3 and CloudFront builders. Some URLs differ from the ones version 2 produced, so read the upgrade notes first.

Upgrading from 2.x

  1. Pass the bucket's region to every signed S3 URL. S3UrlBuilder now signs with AWS Signature Version 4 (SigV4) by default, because AWS is retiring Signature Version 2 (SigV2) for S3. A signed URL needs the bucket's region, from inRegion(region) or the new withEndpoint(endpoint, region); without one, toString() throws IllegalStateException. withEndpoint(endpoint) clears any region that inRegion set. The region must be the bucket's own: code that passes the application's region to inRegion signs for the wrong region when the bucket lives in another one, and S3 answers the request with a 400. A SigV4 URL lasts from 1 second to 7 days, and toString() throws IllegalArgumentException for an expiration outside that range. The URL carries X-Amz-Algorithm, X-Amz-Credential, X-Amz-Date, X-Amz-Expires, X-Amz-SignedHeaders, X-Amz-Signature, and with a session token X-Amz-Security-Token, in place of Signature, Expires, AWSAccessKeyId, and x-amz-security-token. To keep SigV2 for a bucket or S3-compatible service that still accepts it, call the deprecated usingSignatureVersion2().

  2. Check the URLs you generate. The default encoding changed. A path segment now keeps @, :, and !$&'()*+,;=, and a query parameter now encodes * and keeps ~.

    new UrlBuilder("my.host.com", "a b+c@d").addParameter("q", "x y*z~").toString()
    // 2.x: http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E
    // 3.0: http://my.host.com/a%20b+c@d?q=x%20y%2Az~

    Both forms decode to the same text. To get the 2.x output back, call usingLegacyEncoding() on the builder.

    new UrlBuilder("my.host.com", "a b+c@d")
        .usingLegacyEncoding()
        .addParameter("q", "x y*z~")
        .toString()
    // http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E

    To switch back only the path or only the query string, pass a LegacyEncoder to usingPathEncoder or usingQueryEncoder.

    builder.usingPathEncoder(new LegacyEncoder());   // 2.x path, 3.0 query string
    builder.usingQueryEncoder(new LegacyEncoder());  // 3.0 path, 2.x query string

    The switch applies to the whole URL whenever you call it, including a URL that new UrlBuilder(String) parsed.

    new UrlBuilder("http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E").usingLegacyEncoding().toString()
    // http://my.host.com/a%20b%2Bc%40d?q=x%20y*z%7E

    It has two limits:

    • A parameter added with its own encoder, through addParameter(key, value, encoder), keeps that encoder.
    • S3UrlBuilder and CloudfrontUrlBuilder always use the 3.0 encoding. Their keys encode every character except letters, digits, -._~, and /, as the AWS SDKs do, so they differ from 2.x only in writing * as %2A and keeping ~.
  3. Replace usingEncoder(Encoder). Call usingPathEncoder(Encoder), usingQueryEncoder(Encoder), or both. LegacyEncoder replaces BuiltinEncoder. Check code that calls it after adding parameters: usingEncoder encoded only the parameters added after the call, and usingQueryEncoder encodes every parameter, including the ones added before it. To encode one parameter differently, pass its encoder to addParameter(key, value, encoder).

  4. Expect unencoded text from getPath(), getPathSegments(), and S3UrlBuilder.getKey(). They returned percent-encoded text in 2.x. getKey() now returns the key as given, without leading slashes.

  5. Check code that parses a URL and writes it back. new UrlBuilder(String) now decodes the path, so /a%20b stays /a%20b. In 2.x it became /a%2520b. A trailing slash now stays as well, so /foo/ no longer becomes /foo. Check S3 and CloudFront keys that end with a slash or contain // too: both builders now keep those slashes, and write each slash after the first of a run as %2F, so a//b becomes /a/%2Fb. A + in the query string still reads as a space, as in 2.x, and is written back as %20. A percent-encoded sequence that is not UTF-8, such as /caf%E9, now throws IllegalArgumentException, because the builder cannot write that URL back unchanged.

  6. Check code that adds a parameter whose value is only whitespace. addParameter("q", " ") now writes q=%20. In 2.x it wrote q alone, as a null or empty value still does.

  7. Check code that calls both expireIn and expireAt. The later call now wins. In 2.x expireAt always won.

  8. Check code that passes zero, a negative number, or null as an expiration. expireIn now throws IllegalArgumentException for a zero or negative duration, and expireAt throws it for null. In 2.x S3UrlBuilder.expireIn(0, unit) produced an unsigned URL, and expireAt(null) cleared the expiration.

  9. Check S3UrlBuilder calls that version 2 accepted. withContentType now requires a signed URL, as withAttachmentFilename does, because S3 rejects an anonymous request that sets response-content-type. Without an expiration and credentials, toString() throws IllegalStateException. withKey and the constructor throw IllegalArgumentException for a key of only slashes, which named the bucket itself. inRegion throws it for a blank region, and withEndpoint throws it for a blank endpoint.

  10. Move from expireAt(Date) to expireAt(Instant). The Date overload still works and is deprecated.

  11. Check code that pairs a scheme with port 80 or 443, or reads getPort(). The port now wins over the scheme: https://host:80/ parses as http://host/, and setPort(80) turns HTTPS off. A usingSsl(boolean) call after the port keeps the port, so new UrlBuilder("host", 80, "a").usingSsl() writes https://host:80/a where 2.x wrote https://host/a. new UrlBuilder(hostname, path) sets no port, so its getPort() returns 0 where 2.x returned 80. A URL parsed without a port returns 0 as well, where 2.x returned -1.

  12. Update any rule that names the BouncyCastle artifacts. The library now depends on bcprov-jdk18on and bcpkix-jdk18on 1.87, where 2.x depended on bcprov-jdk15to18 and bcpkix-jdk15to18 1.80.

  13. Expect https from S3UrlBuilder and CloudfrontUrlBuilder. Both now write an HTTPS URL by default, where 2.x wrote http, so a signature and a session token no longer travel in clear text. To keep http, call usingSsl(false) on S3UrlBuilder or the new withSsl(false) on CloudfrontUrlBuilder. A CloudFront signature covers the scheme, so CloudFront rejects a link signed for https that is requested over http.

  14. Check S3 URLs for a bucket whose name contains a period. In an HTTPS URL the bucket now goes in the path, as in https://s3.amazonaws.com/my.bucket/key.txt, because the endpoint's wildcard certificate does not match my.bucket.s3.amazonaws.com. A path-style URL reaches a bucket outside us-east-1 only through its regional endpoint, so call inRegion for such a bucket. A bucket also goes in the path when the endpoint is an IP address. An http URL and usingBucketVirtualHost() keep the bucket in the hostname.

  15. Check CloudfrontUrlBuilder calls that version 2 accepted. The constructor and withKey throw IllegalArgumentException for a key that is blank or only slashes, which signed the root of the distribution. addParameter throws it for Expires, Signature, Key-Pair-Id, and Policy, which CloudFront reads the signature from.

  16. Give a protocol-relative URL a hostname. toString() now throws IllegalArgumentException for a blank hostname in protocol-relative mode, as it does in fully qualified mode. In 2.x it wrote //null/path.

  17. Stop importing StringUtilsInternal and InternalUtils. The two helper classes are no longer public.

Added

  • UrlSigner and UrlBuilder.usingUrlSigner(UrlSigner) add a signature of your own to any URL. The signer receives a SigningContext, adds any parameter the signature must cover with addParameter, signs getStringToSign(), and returns the query parameters to append.
  • PathSegmentEncoder and QueryParameterEncoder encode by RFC 3986, and usingPathEncoder(Encoder) and usingQueryEncoder(Encoder) set them separately.
  • LegacyEncoder and usingLegacyEncoding() produce the encoding of 2.x.
  • NoEncodingEncoder.INSTANCE is a shared instance of that encoder.
  • S3UrlBuilder and CloudfrontUrlBuilder gain expireAt(Instant) and expireIn(Duration).
  • S3UrlBuilder.withEndpoint(endpoint, region) sets a custom endpoint and the region Signature Version 4 signs for.
  • CloudfrontUrlBuilder.withSsl(boolean) sets the scheme, as S3UrlBuilder.usingSsl(boolean) does.
  • CloudfrontPrivateKeyUtils.fromPemString reads PKCS#8 keys (BEGIN PRIVATE KEY) as well as PKCS#1 keys.
  • The jar declares the module name com.widen.urlbuilder through Automatic-Module-Name.

Changed

  • S3UrlBuilder signs with AWS Signature Version 4 by default. A signed URL needs the bucket's region and lasts at most 7 days. inRegion sets the signing region, and withEndpoint(endpoint) clears it.
  • Path segments and query parameters are encoded by RFC 3986, with separate rules for each.
  • The builder encodes the path when it writes the URL, so getPath() and getPathSegments() return unencoded text, and S3UrlBuilder.getKey() returns the key as given.
  • new UrlBuilder(String) decodes the path of the URL it parses.
  • A parameter value of only whitespace is written, as in q=%20. A null or empty value still writes the name alone.
  • Port 80 turns HTTPS off, as port 443 turns it on, and new UrlBuilder(hostname, path) sets no port.
  • expireIn and expireAt replace each other, so the later call sets the expiration.
  • expireIn rejects a zero or negative duration, and expireAt rejects null.
  • S3UrlBuilder.withContentType requires a signed URL, withKey rejects a key of only slashes, inRegion rejects a blank region, and withEndpoint rejects a blank endpoint.
  • S3UrlBuilder writes the host in lower case and leaves out the default port of the scheme, so withEndpoint("MinIO.example.com:443", region).usingSsl() writes https://bucket.minio.example.com/. The SigV4 signature covers that host. CloudfrontUrlBuilder writes and signs the distribution hostname the same way.
  • S3UrlBuilder and CloudfrontUrlBuilder write an HTTPS URL by default.
  • S3UrlBuilder puts the bucket in the path when its name contains a period and the URL is HTTPS, and when the endpoint is an IP address.
  • S3UrlBuilder.inRegion reads the region in lower case, so the signature names the region as the host does.
  • CloudfrontUrlBuilder rejects a key that is blank or only slashes, and addParameter rejects the parameter names CloudFront reads the signature from.
  • new UrlBuilder(String), PathSegmentEncoder.decode, and QueryParameterEncoder.decode throw IllegalArgumentException for a percent-encoded sequence that is not UTF-8. They wrote U+FFFD in its place.
  • UrlBuilder.toString() throws IllegalArgumentException for a blank hostname in protocol-relative mode.
  • UrlBuilder.getPort() returns 0 for a URL parsed without a port and for a negative port.
  • An expiration past Instant.MAX throws IllegalArgumentException instead of ArithmeticException.
  • toURL() wraps a MalformedURLException in a RuntimeException.
  • NoEncodingEncoder is final.
  • The BouncyCastle dependency is bcprov-jdk18on and bcpkix-jdk18on 1.87.

Deprecated

  • S3UrlBuilder.expireAt(Date) and CloudfrontUrlBuilder.expireAt(Date). Use expireAt(Instant).
  • LegacyEncoder and usingLegacyEncoding(). They exist to ease the move from 2.x.
  • S3UrlBuilder.usingSignatureVersion2(), which signs with Signature Version 2 for buckets and S3-compatible services that still accept it. Sign with Signature Version 4 instead.

Removed

  • UrlBuilder.usingEncoder(Encoder). Use usingPathEncoder(Encoder) and usingQueryEncoder(Encoder).
  • BuiltinEncoder. Use LegacyEncoder for the same output.
  • StringUtilsInternal and InternalUtils from the public API. They are helpers for the library's own code.

Fixed

  • S3UrlBuilder signed a URL that S3 rejected when the URL set both an attachment file name and a content type.
  • S3UrlBuilder.toString() left parameters behind when it threw, and the next call wrote and signed them twice.
  • S3UrlBuilder.usingCredentials(key, secret) kept the session token of an earlier call and signed it, so S3 rejected every URL after a switch from temporary to long-term credentials.
  • A Content-Disposition header wrote * unencoded in filename*, so a strict parser ignored the UTF-8 file name.
  • CloudfrontPrivateKeyUtils.fromPemString built a new BouncyCastle provider on every call.
  • CloudfrontUrlBuilder could sign one expiration and write another when the clock passed a second boundary during signing, and CloudFront rejected that URL.
  • CloudfrontUrlBuilder and S3UrlBuilder produced wrong URLs and signatures when several threads called toString() on one builder.
  • CloudfrontUrlBuilder.addParameter and UrlBuilder.addParameters threw NullPointerException for a null value. A null value now adds the name alone.
  • new UrlBuilder(String) mishandled a query value that contains =. It removed trailing = characters, so ?sig=abc== parsed as abc, and it dropped the whole parameter for a value such as ?a=b=c.
  • new UrlBuilder(String) encoded an already encoded path a second time.
  • new UrlBuilder(String) dropped the trailing slash of a path, so /foo/ became /foo.
  • S3UrlBuilder and CloudfrontUrlBuilder dropped a trailing slash and empty segments from a key, so folder/ and a//b named the objects folder and a/b.
  • UrlBuilder left port 80 out of an https URL and port 443 out of an http URL, so the URL named the wrong port. SigningContext.getPort() returned null for those ports as well.
  • S3UrlBuilder.inRegion wrote an amazonaws.com host for a China region such as cn-north-1, whose endpoint ends in amazonaws.com.cn.

Security

  • On Java 9 and later, the file name in a Content-Disposition header kept \, ", and %. A file name containing " could add a filename* parameter and change the name a browser saves the download under. withAttachmentFilename now removes those characters on every Java version.
  • S3UrlBuilder put any bucket name without uppercase letters, _, !, @, or # in the hostname, so a name containing / or ? sent the URL, with its access key ID and signature, to another host. A bucket name with any character other than lowercase letters, digits, ., and - now goes in the path.
  • A key of only slashes, such as /, made S3UrlBuilder sign the bucket itself, a URL that lists the bucket's keys.
  • A null, empty, or slash-only key made CloudfrontUrlBuilder sign the root of the distribution.
  • A protocol-relative UrlBuilder with an empty hostname wrote ///path, which a browser reads as a link to the host that the first path segment names.
  • The parser read % followed by digits of another script, such as the fullwidth 2E, as a percent-encoded byte, so %2E%2E came out as .. after a filter had found no dots in the URL. It now reads only ASCII hex digits.
  • BouncyCastle 1.87 includes the fixes for CVE-2025-14813, CVE-2026-5588, CVE-2026-8763, and CVE-2026-13506.