Summary card: Go and Node hand-written SigV4 signers match four AWS vectors; the JavaScript library drops the Date header

A while ago we <a href="https://tport.space/articles/signing-s3-request-by-hand-sigv4-canonical-request-checked-against-botocore">signed one S3 request by hand in Python</a>. This time it is Go and Node, and we use all four examples AWS publishes for S3, not just one. Then we feed the same requests to the SDK signers and see what each one does with the headers and the path.

Short version: both hand-written signers (about 40 lines each, standard library only) match all four AWS signatures. botocore and the Go SDK match them too. The JavaScript library only matches three of the four, and the reason is a header it quietly does not sign.

The four vectors

All four are from the AWS documentation page for the Authorization header on S3. Same keys, same date, same region:

  • access key AKIAIOSFODNN7EXAMPLE, secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY (public, from the AWS docs)
  • time 20130524T000000Z, region us-east-1, service s3, host examplebucket.s3.amazonaws.com
  • no network and no account involved: this is only arithmetic on a request
VectorWhat it testsSignature the docs give (first 16 hex)
GET ObjectRange headerf0e8bdb87c964420
PUT Objectpath /test$file.text, Date header, storage class, a body98ad721746da40c6
GET Bucket lifecyclequery string with an empty value (?lifecycle)fea454ca298b7da1
GET Bucket (List Objects)two query parameters, sorted (max-keys=2&prefix=J)34b48302e7b5fa45

Node: the whole signer

Only <code>node:crypto</code>. The two details that bite: lower-case and sort the header names, and encode each path segment once (S3 does not double-encode like other AWS services).

javascript
import { createHash, createHmac } from "node:crypto";
const sha = (d) => createHash("sha256").update(d).digest("hex");
const hmac = (k, d) => createHmac("sha256", k).update(d).digest();
const enc = (s) => encodeURIComponent(s).replace(/[!'()*]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase());

export function sign(c, ak, sk, amzdate, region) {
  const date = amzdate.slice(0, 8), ph = sha(c.payload);
  const h = { host: c.host, "x-amz-content-sha256": ph, "x-amz-date": amzdate };
  for (const [k, v] of Object.entries(c.headers)) h[k.toLowerCase()] = v;
  const names = Object.keys(h).sort();
  const canonHeaders = names.map((n) => `${n}:${String(h[n]).trim().replace(/\s+/g, " ")}\n`).join("");
  const path = c.path.split("/").map(enc).join("/");
  const query = c.query ? c.query.split("&").map((p) => { const [k, v = ""] = p.split("="); return [enc(k), enc(v)]; })
      .sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : 1)).map(([k, v]) => `${k}=${v}`).join("&") : "";
  const canonical = [c.method, path, query, canonHeaders, names.join(";"), ph].join("\n");
  const sts = ["AWS4-HMAC-SHA256", amzdate, `${date}/${region}/s3/aws4_request`, sha(canonical)].join("\n");
  const key = hmac(hmac(hmac(hmac("AWS4" + sk, date), region), "s3"), "aws4_request");
  return createHmac("sha256", key).update(sts).digest("hex");
}

Go: the same thing with the standard library

<code>crypto/hmac</code>, <code>crypto/sha256</code>, <code>sort</code> and <code>strings</code>. Go has no <code>encodeURIComponent</code>, and <code>url.QueryEscape</code> turns a space into <code>+</code>, which SigV4 does not want, so we write the encoder ourselves: everything except <code>A-Z a-z 0-9 - _ . ~</code> becomes <code>%XX</code> in upper-case hex.

go
func encode(s string) string {
	var b strings.Builder
	for _, c := range []byte(s) {
		if c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9' || c == '-' || c == '_' || c == '.' || c == '~' {
			b.WriteByte(c)
		} else {
			fmt.Fprintf(&b, "%%%02X", c)
		}
	}
	return b.String()
}

func hm(k []byte, d string) []byte { m := hmac.New(sha256.New, k); m.Write([]byte(d)); return m.Sum(nil) }

// headers: lower-case names; values trimmed and inner runs of spaces collapsed with strings.Fields.
// canonical := strings.Join([]string{method, path, query, canonHeaders, signedHeaders, payloadHash}, "\n")
// key := hm(hm(hm(hm([]byte("AWS4"+secret), date), region), "s3"), "aws4_request")
// signature := hex.EncodeToString(hm(key, stringToSign))

Results on the four vectors

SignerGET ObjectPUT ObjectGET lifecycleGET List Objects
Node, hand-writtenmatchmatchmatchmatch
Go, hand-writtenmatchmatchmatchmatch
botocore 1.44.9matchmatchmatchmatch
aws-sdk-go-v2 v1.48.0 (v4.Signer)matchmatchmatchmatch
@smithy/signature-v4 5.7.5 (what the AWS SDK for JavaScript v3 uses)matchdiffersmatchmatch

Run on 2026-11-22 on Windows 11 with Node 26.8.2, Go 1.25.4 and Python with botocore 1.44.9. Every signature is compared with the value printed in the AWS documentation, character for character.

Why the JavaScript library misses the PUT vector

The PUT example sends a <code>Date: Fri, 24 May 2013 00:00:00 GMT</code> header and AWS signs it (<code>SignedHeaders=date;host;x-amz-content-sha256;x-amz-date;x-amz-storage-class</code>). @smithy/signature-v4 deletes any header called <code>date</code>, <code>authorization</code> or <code>x-amz-date</code> from your request before it signs, because it makes its own <code>x-amz-date</code>. So its SignedHeaders has no <code>date</code>, and its signature is for a different canonical request. That is not a bug when the library sends the request itself: the server only checks the headers the Authorization header lists. It matters when you compare against a published vector or when something downstream (a proxy, a test) expects <code>date</code> to be signed.

There is a second trap in the same vector, the <code>$</code> in <code>/test$file.text</code>. We changed only the path handling, with the <code>date</code> header removed from the request, so the results are comparable (our hand signer without <code>date</code> gives <code>1ee3a9a719bf</code>):

Library settingPath handed to the signerSignature (first 12 hex)Same as hand?
smithy uriEscapePath: false (what the S3 client sets)/test$file.textf6a9c6ad82f9no
smithy uriEscapePath: false/test%24file.text (already encoded)1ee3a9a719bfyes
smithy uriEscapePath: true (the default)/test$file.text1ee3a9a719bfyes
smithy uriEscapePath: true/test%24file.text7ac1d84c414eno (encoded twice)
Go SDK DisableURIPathEscaping=trueURL with decoded path onlyf6a9c6ad82f9no
Go SDK DisableURIPathEscaping=trueURL with RawPath set to the encoded form1ee3a9a719bfyes
Go SDK DisableURIPathEscaping=falseURL with decoded path only1ee3a9a719bfyes
Go SDK DisableURIPathEscaping=falseURL with RawPath set7ac1d84c414eno (encoded twice)

Read the table as a rule: the setting that turns off escaping expects you to hand in the path already encoded, and the setting that leaves escaping on expects a raw path. Mix them up and you either sign <code>$</code> raw or encode <code>%24</code> into <code>%2524</code>. For S3 you want exactly one encoding in the canonical request. A key like <code>photos/my file.jpg</code> is where this shows up first in real code.

Where each signer trims or skips headers

Eight small probes, each a request with one thing changed, signed by the hand-written signer (which signs every header you give it), botocore, @smithy/signature-v4 and the Go SDK. The signature tells you whether the canonical request was the same. These are the two where the signers disagree:

Probebotocore@smithy/signature-v4aws-sdk-go-v2
User-Agent, Expect, Connection, Pragma, Cache-Control set (hand-written signer signs all five)signs cache-control, pragmasigns none of themsigns cache-control, connection, pragma
Date header set by the callerdate signednot signeddate signed

The other six probes gave identical signatures in all four implementations: a plain GET, <code>Content-Type</code> with a mixed-case <code>X-Amz-Meta-Foo</code>, a header value with outer and inner spaces (<code>" a b "</code> is trimmed and collapsed to <code>a b</code> by all of them), a query with a repeated key and an encoded space (<code>a=2&amp;a=1&amp;b=x%20y&amp;c</code> sorts to <code>a=1&amp;a=2&amp;b=x%20y&amp;c=</code>), a wire path with <code>%20</code> and UTF-8 bytes (<code>/my%20dir/%C3%BC.txt</code>), and a path with <code>//</code> and <code>./</code> segments (<code>/a//b/./c</code>, kept as is for S3, not normalised).

None of these disagreements breaks a request on its own, because the server verifies the headers named in <code>SignedHeaders</code> against what it received. They bite in two places: when a proxy rewrites a header that you signed (<code>cache-control</code>, <code>pragma</code> and <code>connection</code> are the usual ones), and when you compare signatures across languages while debugging.

  • Sign fewer headers when something sits in the middle. Host, x-amz-date, x-amz-content-sha256 and the x-amz-* headers you actually need are enough.
  • If a proxy or CDN adds or edits headers, make sure none of the signed ones are among them.
  • When two languages give different signatures, print SignedHeaders first. Most of the time that is the whole difference.

Checklist for a hand-written signer in Go or Node

  • Run the four vectors above before you point the code at a real endpoint. Four matches cost a minute and remove most guesses.
  • Strip a trailing newline from a secret you read from a file.
  • On s3.tport.space the region in the scope is auto, not us-east-1. The AWS vectors keep us-east-1 so you can check the maths; switch the region for the real call.
  • If you only need one signed request in a script, an SDK is simpler. Hand-written pays off where an SDK does not fit: a tiny Worker, a CI step with no dependencies, a test that checks what you send.

Related: <a href="https://tport.space/articles/signing-s3-request-by-hand-sigv4-canonical-request-checked-against-botocore">the Python walk-through with the ten mistakes that give SignatureDoesNotMatch</a> and <a href="https://tport.space/articles/s3-bucket-names-dots-capitals-tls-virtual-host-path-style-boto3-aws-cli-rclone-curl">bucket names, TLS and path-style addressing per client</a>.

S3-compatible buckets with no egress fees. Signature Version 4 on every request, so any SDK or a hand-written client works.

Explore tport.space

Test record and sources

  • Run 2026-11-22 on Windows 11: Node 26.8.2 with @smithy/signature-v4 5.7.5 and @aws-crypto/sha256-js, Go 1.25.4 with github.com/aws/aws-sdk-go-v2 v1.48.0, Python with botocore 1.44.9. Pure computation: no network, no account, no bucket.
  • The four signatures are the ones printed in the AWS documentation for Amazon S3, Signature Calculations for the Authorization Header (examples with the public example keys).
  • The probe table and path table are our own runs of the same request with one change each; they show signatures, not a server response.
  • Sources: AWS, Signature Version 4 signing process; AWS S3 API reference, Authenticating requests: Using the Authorization header (AWS Signature Version 4); source of botocore.auth, aws-sdk-go-v2 aws/signer/v4 and smithy-typescript signature-v4.