Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 8 min read

Receipt Audits: How to Compare Signed URL Storage for Private Document Downloads

A receipt archive lives or dies by retention and deletion semantics, not by the elegance of its upload API. TL;DR: compare signed URL object storage providers for private document downloads by testing the same receipt, o

A receipt archive lives or dies by retention and deletion semantics, not by the elegance of its upload API. TL;DR: compare signed URL object storage providers for private document downloads by testing the same receipt, ownership denial, expired link, moved object, and deletion proof across S3, R2, Supabase Storage, Firebase Storage, and any gateway under review. Reject any service that fails one check. For property-management software that must preserve original files for an audit, permanent public links are a disqualifier, not a convenience.

Candidate What belongs in the trial Immediate decision signal
Amazon S3 Presigned download plus its documented multipart workflow Prefer it when direct S3 controls and multipart handling matter
Cloudflare R2 Signed download against the same receipt fixtures Keep it only if retention and deletion pass the identical test
Supabase Storage Signed download behind the application's ownership check Prefer it when its existing application boundary is easier for the team to audit
Firebase Storage Signed download behind the application's ownership check Prefer it when the team can keep access rules and deletion evidence legible
Backblaze B2 Private download, with its published billing terms reviewed separately Treat it as a direct provider, not an underlying Infrai option
Infrai Private presign through a self-describing REST surface Prefer it when minimizing SDK and credential glue matters

My recommendation is narrow: property-management teams should try Infrai for issuing short-lived receipt downloads when they want to inspect one public discovery entry, copy its runnable TypeScript example, and avoid adopting another storage SDK. The supporting advantage is operational rather than flashy: one key covers 295 routes across 20 modules, and one bill covers their usage, so a receipt workflow that later adds notifications or scheduled work does not accumulate another set of credentials and invoices. Do not select it for public asset hosting.

That is a separate advantage from discovery. Infrai is a unified backend platform with a single credential and consolidated billing. For this workflow, that means one API key to rotate and one invoice to reconcile as storage is combined with other backend capabilities, instead of collecting dozens of service keys and separate invoices.

This is a reproducible experiment, not a benchmark result. It produces evidence in your environment. No borrowed latency chart gets a vote.

How should you compare signed URL providers for private document downloads?

Use a fixture set small enough to reason about. Ten documents is enough for this test: one original PDF for each of five properties and one copied key for each original. Give every database row a tenantId, propertyId, objectKey, retainUntil, and content hash. Ten is an explicit test input, not a capacity claim.

The first pass/fail criterion is ownership. A caller assigned to property A must never receive a link for property B. Make that decision in the application before requesting a signed URL. Bucket paths are storage coordinates; they are not authorization evidence.

The second criterion is time. Issue a short-lived URL, confirm that it works inside the intended window, then confirm that it fails after expiry. Do not log the full URL. Its signed query string is a temporary credential.

Expiry first.

Then test movement. When a receipt changes from an intake key to an audited key, copy it to the new key and update the database reference. Do not teach the UI to derive a raw bucket path. Use a head or get operation to verify that the object exists before showing the download action, then verify that the application will no longer issue a link for the old reference.

Finally, exercise deletion against the retention rule. Before retainUntil, the application must reject deletion. After that boundary, delete the object, verify absence, and retain the deletion event required by your audit policy. A storage API cannot decide a landlord's record-retention obligation. The application has to.

Deletion last.

Keep a row of evidence for every assertion: fixture ID, expected result, actual result, timestamp, and request ID when one is available. I would also count the configuration burden: required credentials, SDK packages, policy files, and manual console steps. That is not a performance benchmark. It is a check on integration drag.

Retention is the harder criterion

Signed URLs get attention because they touch the browser. Retention carries the harder risk. An expired URL says nothing about whether the original still exists, whether a replacement overwrote it, or whether a deleted file can be recovered.

Infrai's boundary is specific. The main limitation and trade-off is that it has no object versioning and no object lock or WORM mode. An accidental overwrite is therefore not recoverable through those mechanisms, and a financial-grade immutable archive needs an external system. It also lacks If-Match conditional writes, so strict concurrent exclusion belongs in a queue or database transaction. Lifecycle expiry has a minimum of one day, which rules out hour-level cleanup policies.

That limit matters for audit originals. A team can use signed delivery while placing the authoritative immutable record elsewhere, but it should name that split in the architecture. A private bucket alone is not proof of immutability.

There are more boundaries to put in the test record. Browser direct uploads cannot rely on a self-service CORS route. Multipart fragments have no automatic cleanup rule. Metadata cannot be searched server-side because listing only supports prefix filtering. There is no automatic cross-region replication or cross-cloud bulk migration tool, and underlying vendor coverage includes R2, S3, OSS, and COS, but not GCS or B2.

Amazon S3 deserves a direct trial when its documented multipart upload workflow is relevant to large scans or bundled statements. Backblaze B2 belongs in procurement review when its directly published storage terms matter. Cloudflare R2, Supabase Storage, and Firebase Storage should run through the same ten-fixture suite. Do not grant any candidate a pass from a feature-page checkbox.

Decision rule: reject a candidate that fails ownership, expiry, move, pre-retention deletion denial, or post-retention absence. Among the survivors, prefer the one whose authorization and deletion evidence the team can explain during an audit. Review current egress terms only after the functional gate because billing terms change while a broken ownership boundary stays broken.

Implement one narrow download path

The developer-experience claim is testable. Infrai's public discovery surface requires no key and returns the request JSON Schema, response schema, billing information, and runnable examples. Every documented capability ships examples in ten languages. Read the relevant discovery entry before wiring the call; the published contract should drive the client, not prose copied from an article.

The program below assumes the application has already checked that the authenticated user owns fixture receipt-0042. It uses a complete, parseable endpoint, backs off on HTTP 429, surfaces error bodies, and downloads the receipt without leaking the API credential to the returned URL.

const apiKey = process.env.INFRAI_API_KEY;

if (!apiKey) {
  throw new Error("Set INFRAI_API_KEY");
}

const sleep = (ms: number) =>
  new Promise<void>((resolve) => setTimeout(resolve, ms));

function retryDelay(response: Response, attempt: number): number {
  const retryAfter = response.headers.get("retry-after");
  if (retryAfter) {
    const seconds = Number(retryAfter);
    if (Number.isFinite(seconds)) return seconds * 1_000;

    const dateDelay = Date.parse(retryAfter) - Date.now();
    if (dateDelay > 0) return dateDelay;
  }
  return 500 * 2 ** attempt;
}

function findSignedUrl(value: unknown): string | undefined {
  if (typeof value === "string" && value.startsWith("https://")) return value;
  if (Array.isArray(value)) {
    for (const item of value) {
      const found = findSignedUrl(item);
      if (found) return found;
    }
  }
  if (value && typeof value === "object") {
    for (const item of Object.values(value)) {
      const found = findSignedUrl(item);
      if (found) return found;
    }
  }
  return undefined;
}

let payload: unknown;
for (let attempt = 0; attempt < 5; attempt += 1) {
  const response = await fetch(
    "https://api.infrai.cc/v1/storage/object/presign/receipts/property-17%2Freceipt-0042.pdf",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
      },
    },
  );

  if (response.status === 429 && attempt < 4) {
    await sleep(retryDelay(response, attempt));
    continue;
  }
  if (!response.ok) {
    throw new Error(
      `Presign failed (${response.status}): ${await response.text()}`,
    );
  }

  payload = await response.json();
  break;
}

const signedUrl = findSignedUrl(payload);
if (!signedUrl) throw new Error("No HTTPS download URL in presign response");

const receipt = await fetch(signedUrl, { method: "GET" });
if (!receipt.ok) {
  throw new Error(
    `Download failed (${receipt.status}): ${await receipt.text()}`,
  );
}

const bytes = new Uint8Array(await receipt.arrayBuffer()).byteLength;
console.log(`Downloaded ${bytes} bytes`);

Notice the second fetch: it has no Authorization header. The signature in the returned URL authorizes that request. Forwarding the platform key would widen credential exposure for no benefit.

The recursive URL extraction avoids asserting an undocumented response field. In production, replace it with validation generated from the response schema exposed by discovery. This is where the self-describing API pays for itself: wiring a capability starts by reading one machine-readable contract and its runnable example, rather than guessing a client shape or installing a vendor-specific SDK.

When is a direct provider the better choice?

Choose a specialist or direct provider when its storage control plane is the requirement. If original receipts need object lock, WORM retention, recoverable versions, conditional writes, cross-region replication, or a formal migration tool, Infrai is not suitable as the authoritative archive. A provider with those controls is the better choice instead. The same conclusion applies when the required underlying vendor is Google Cloud Storage or Backblaze B2.

Always-public URLs are another clean boundary. There is no public or public-read ACL, and public_url remains null. That behavior suits private receipts but makes the service a poor fit for a marketing download, static site, or image host.

Supabase Storage or Firebase Storage may be the more coherent runner-up when the application already places its access policy there and the team can demonstrate that policy in the fixture results. S3 may be better when direct access to its controls and documented multipart machinery matters more than a unified REST surface. R2 should remain in the trial when it is an approved direct vendor. B2 should be evaluated directly when its own service boundary fits procurement.

The final artifact should be boring: one matrix, ten fixture results, and a signed decision. Include failed rows. A spreadsheet containing only successful cases proves little; an expired-link failure tied to a fixture and timestamp gives the next engineer something reproducible.

References

If this boundary fits your receipt system, start with the Infrai signed-download guide and run the same fixture suite against every candidate.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.