Skip to content

Add HMAC-SHA256 signed URL support for time-limited PDF access - #14

Merged
HermanPlay merged 15 commits into
masterfrom
copilot/add-signed-url-support
Mar 9, 2026
Merged

Add HMAC-SHA256 signed URL support for time-limited PDF access#14
HermanPlay merged 15 commits into
masterfrom
copilot/add-signed-url-support

Conversation

Copilot AI commented Jan 25, 2026

Copy link
Copy Markdown
Contributor

Storage needs to serve PDFs via signed URLs with expiration validation, no user authentication required. Backend generates signatures, storage validates and enforces access control.

Implementation

URL Signing (pkg/urlsigner)

  • HMAC-SHA256 signature generation: path:timestamp → base64-encoded signature
  • Validation with constant-time comparison (timing attack prevention)
  • Query parameter format: ?expires={unix_ts}&signature={hmac}

Server Validation (internal/api/http/middleware/signature.go)

  • Intercepts GET requests to /buckets/{bucket}/{object}
  • Validates signature + expiration on PDF files only (backward compatible)
  • Returns 403 for expired/invalid/missing signatures
  • Bypasses validation for ?metadataOnly=true requests

Client API (pkg/filestorage)

// Generate signed URL valid for 1 hour
signedURL, err := storage.GetSignedFileURL(
    "bucket", "file.pdf", 
    1*time.Hour, 
    signingSecret,
)

Configuration

  • SIGNING_SECRET env var (logs ERROR if unset)
  • Shared secret between backend and storage

Behavior

Scenario Response
Valid signature, not expired 200 + file content
Expired signature 403 Forbidden
Invalid/tampered signature 403 Forbidden
Missing signature (PDF) 403 Forbidden
Missing signature (non-PDF) 200 + file content
Metadata request 200 + metadata JSON

Testing

  • 27 tests covering signing, validation, integration
  • End-to-end validation with test server

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy /home/REDACTED/work/_temp/runtime-logs/mkcert/rootCA.pem --updater-env NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/dbot-ca.crt 8426�� g_.a -I ache/go/1.24.12/168.63.129.16 --gdwarf-5 ge/internal/api/rev-parse -o ache/go/1.24.12/53 (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-0a67a4931c29 -j DROP igiCert_High_Assurance_EV_Root_CA.pem /opt/hostedtoolc-e /bin/test (dns block)
  • go.uber.org
    • Triggering command: /update-job-proxy /update-job-proxy /home/REDACTED/work/_temp/runtime-logs/mkcert/rootCA.pem --updater-env NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/dbot-ca.crt 8426�� g_.a -I ache/go/1.24.12/168.63.129.16 --gdwarf-5 ge/internal/api/rev-parse -o ache/go/1.24.12/53 (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-0a67a4931c29 -j DROP igiCert_High_Assurance_EV_Root_CA.pem /opt/hostedtoolc-e /bin/test (dns block)
  • gopkg.in
    • Triggering command: /update-job-proxy /update-job-proxy /home/REDACTED/work/_temp/runtime-logs/mkcert/rootCA.pem --updater-env NODE_EXTRA_CA_CERTS=/usr/local/share/ca-certificates/dbot-ca.crt 8426�� g_.a -I ache/go/1.24.12/168.63.129.16 --gdwarf-5 ge/internal/api/rev-parse -o ache/go/1.24.12/53 (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy -o br-0a67a4931c29 -j DROP igiCert_High_Assurance_EV_Root_CA.pem /opt/hostedtoolc-e /bin/test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>File Storage — Support signed, time-limited access to task PDFs</issue_title>
<issue_description>Title
File Storage: Enable signed, time-limited access for task description PDFs

Description
File storage must support signed URLs that allow temporary, unauthenticated access to individual PDF files.
Storage itself should not perform user authentication — only signature and expiration validation.

Context / Motivation

  • PDFs are accessed by clients via URLs generated by the backend

  • Storage must be able to validate:

    • Signature authenticity
    • Expiration timestamp
    • HTTP method (GET only)
  • This allows scalable, secure file delivery without backend involvement

Requirements

  • Storage must:

    • Validate cryptographic signatures generated by backend
    • Enforce expiration timestamps
    • Reject expired or tampered URLs with 403
    • Serve files only over HTTPS
  • Signed URLs must:

    • Be scoped to a specific object path
    • Not allow listing, overwrite, or deletion
  • Support CDN caching if applicable (signature in query params)

Non-Requirements

  • No user/session authentication at storage level
  • No cookies or custom auth headers
  • No long-lived or public URLs

Security Considerations

  • Use HMAC or provider-native signing mechanism
  • Signing keys must be securely stored and rotated
  • Storage access logs should include signature validation failures

Acceptance Criteria

  • Valid signed URL → PDF is returned
  • Expired or modified URL → 403 Forbidden
  • URL without signature → 403 Forbidden
  • Only GET requests are allowed

Notes

  • Prefer built-in mechanisms (e.g. S3 pre-signed URLs, GCS signed URLs, Azure SAS)
  • TTL should align with backend configuration</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits January 25, 2026 11:02
Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
…signatures only for PDFs

Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
…feature

Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
…ance security warnings

Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
Co-authored-by: TheRealSeber <111927572+TheRealSeber@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for signed, time-limited access to task PDFs Add HMAC-SHA256 signed URL support for time-limited PDF access Jan 25, 2026
Copilot AI requested a review from TheRealSeber January 25, 2026 11:15
Using a hardcoded public default secret allows anyone to forge valid
signed URLs. Refuse to start if SIGNING_SECRET is not set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@TheRealSeber
TheRealSeber marked this pull request as ready for review March 7, 2026 20:09
@TheRealSeber
TheRealSeber requested a review from a team as a code owner March 7, 2026 20:09
@TheRealSeber
TheRealSeber requested a review from Copilot March 7, 2026 21:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds signed, time-limited URL support to enable unauthenticated (but authorized via HMAC) PDF downloads, enforced at the storage service layer via HTTP middleware.

Changes:

  • Introduce pkg/urlsigner for HMAC-SHA256 signing/validation (expires + signature query params).
  • Enforce signed URL validation for GET requests to object endpoints, requiring signatures for PDF downloads (with a metadataOnly=true bypass).
  • Expose signed URL generation from the Go client (pkg/filestorage) and document the feature.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
pkg/urlsigner/urlsigner.go Implements HMAC signing and signature/expiry validation.
pkg/urlsigner/urlsigner_test.go Unit tests for signing/validation behavior.
internal/api/http/middleware/signature.go Adds request-time validation/enforcement middleware for signed URLs.
internal/api/http/middleware/signature_test.go Middleware unit tests for valid/invalid/expired/missing signature scenarios.
internal/api/http/server/router.go Wires the signature middleware into the server and updates NewServer signature.
internal/config/config.go Adds SIGNING_SECRET config loading into app configuration.
cmd/app/main.go Instantiates URLSigner and passes it into the HTTP server.
cmd/app/integration_test.go End-to-end-ish test verifying middleware enforcement through the server handler.
pkg/filestorage/file_storage.go Adds GetSignedFileURL to generate signed URLs from the client library.
pkg/filestorage/file_storage_test.go Adds tests for GetSignedFileURL behavior.
SIGNED_URLS.md New documentation for signed URL format, usage, and behavior.
Readme.md Mentions signed URL support and links to detailed docs.
.env.dist Adds SIGNING_SECRET to the example environment file.
.gitignore Ignores the built file-storage binary.
go.mod Promotes lumberjack.v2 to a direct dependency (used by logger).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/config/config.go
Comment thread SIGNED_URLS.md Outdated
Comment thread pkg/urlsigner/urlsigner.go Outdated
Comment thread Readme.md Outdated
Comment thread Readme.md Outdated
Comment thread pkg/urlsigner/urlsigner_test.go Outdated
Comment thread internal/api/http/middleware/signature.go Outdated
Comment thread internal/api/http/middleware/signature.go
Comment thread pkg/urlsigner/urlsigner.go Outdated
@TheRealSeber
TheRealSeber requested a review from Copilot March 8, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@HermanPlay
HermanPlay requested a review from Copilot March 8, 2026 09:25
Comment thread pkg/filestorage/file_storage.go Outdated
Comment thread pkg/filestorage/file_storage.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Thread urlsigner into NewInternalServer; add GET /sign?bucket=&key=&ttl=
handler that returns {"signedPath": "..."} with a default TTL of 300s.
Update main.go and integration tests accordingly.

TDD: failing compile error confirmed before implementation.
SDK no longer does in-process HMAC signing. GetSignedFilePath now calls
GET <config.URL>/sign?bucket=...&key=...&ttl=... on the internal server
and returns the signed path. Remove SigningSecret from FileStorageConfig.

TDD: failing compile confirmed before implementation.
@HermanPlay
HermanPlay merged commit 676cfe6 into master Mar 9, 2026
1 check passed
@HermanPlay
HermanPlay deleted the copilot/add-signed-url-support branch March 9, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File Storage — Support signed, time-limited access to task PDFs

4 participants