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

5 Deletion Tests for Private SaaS File Exports (Across US/EU Object Storage)

Short answer: require an S3-compatible object storage design to expire access, delete the underlying private files on schedule, and verify that deletion in both US and EU regions. A signed download URL is a delivery cred

Short answer: require an S3-compatible object storage design to expire access, delete the underlying private files on schedule, and verify that deletion in both US and EU regions. A signed download URL is a delivery credential, not a retention policy.

For a property management SaaS, the clean data flow is direct: the browser uploads inspection videos and move-out photos to a private bucket with a narrowly scoped signed upload, so the application never proxies the bytes. A worker later builds the requested export in object storage. The API authorizes the tenant, creates a short-lived signed download URL, and records the export's independent deletion deadline. This keeps large media off the Node.js request path while leaving access decisions in the application.

The distinction is small on a diagram and decisive in production. An expired URL can stop a particular request while the object still exists. Deleting an object can satisfy a retention decision while an already issued link remains meaningful only until its own expiry. Treat those clocks separately.

Expiry is not erasure.

1. How should a Node.js SaaS issue temporary links for private file exports?

Start with a storage adapter, not provider-specific calls scattered through controllers. The adapter needs capabilities for signed uploads, signed downloads, deletion, and an existence check. S3 compatibility helps here, but the label alone doesn't prove identical signing limits, regional behavior, checksum support, lifecycle semantics, or response-header controls. Those are acceptance tests for each candidate.

This TypeScript example keeps the policy visible. It assumes authentication and tenant authorization have already succeeded; store is an adapter backed by the service under evaluation.

type Region = "us" | "eu";

type ExportRecord = {
  tenantId: string;
  objectKey: string;
  region: Region;
  deleteAfter: Date;
  legalHold: boolean;
};

interface ObjectStore {
  signUpload(input: {
    key: string;
    region: Region;
    contentType: string;
    expiresInSeconds: number;
  }): Promise<URL>;
  signDownload(input: {
    key: string;
    region: Region;
    filename: string;
    expiresInSeconds: number;
  }): Promise<URL>;
  delete(input: { key: string; region: Region }): Promise<void>;
  exists(input: { key: string; region: Region }): Promise<boolean>;
}

const safeSegment = (value: string): string => {
  if (!/^[a-zA-Z0-9_-]+$/.test(value)) throw new Error("invalid object segment");
  return value;
};

async function createInspectionUpload(
  store: ObjectStore,
  tenantId: string,
  propertyId: string,
  mediaId: string,
  region: Region,
  contentType: string,
): Promise<URL> {
  const key = [
    "tenants",
    safeSegment(tenantId),
    "properties",
    safeSegment(propertyId),
    "inspections",
    safeSegment(mediaId),
  ].join("/");

  return store.signUpload({ key, region, contentType, expiresInSeconds: 900 });
}

async function createExportDownload(
  store: ObjectStore,
  record: ExportRecord,
  now: Date,
): Promise<URL> {
  if (record.legalHold || now >= record.deleteAfter) {
    throw new Error("export unavailable");
  }

  return store.signDownload({
    key: record.objectKey,
    region: record.region,
    filename: "property-inspection-export.zip",
    expiresInSeconds: 600,
  });
}

The 900-second upload and 600-second download windows are example policy inputs, not universal recommendations. Measure how long real users need, then keep the window short enough that revocation does not depend on waiting for hours. I'm not sure one expiry works for both a 20 MB report and a multi-gigabyte video archive; request size, network conditions, and your download implementation should settle that choice.

Don't place a signed URL in analytics events, exception messages, support screenshots, or referrer-bearing pages. It is a bearer credential until it expires. Keep the bucket private, authorize before every issuance, and log the export record identifier rather than the credential itself.

2. Prove that expiry and deletion are different controls

The first test freezes time just past the download deadline and confirms that a fresh authorization path refuses to issue another link. The second advances past deleteAfter, runs deletion, and checks that the object is absent. The third places the record under a documented hold and confirms that the deletion worker skips it without extending access for ordinary users.

That last split matters in property management. A move-out dispute may require retaining evidence while the former tenant's export link must still expire. One Boolean in the example makes the idea readable, but a real hold should carry who applied it, why, when it began, and what event releases it. Access and preservation answer different questions.

I use an explicit deletion job even when the storage service offers lifecycle rules β€” the application knows the tenant, property, export request, and hold state. A bucket lifecycle can remain a backstop for orphaned objects. The catch is operational ownership: application-driven deletion needs a durable job queue, idempotent retries, and reconciliation; lifecycle-only deletion is simpler but may be too coarse for per-export holds and audit evidence.

Keep it boring.

The deletion loop can be tiny, provided its database claim is concurrency-safe and its audit write is durable:

type DeletionAudit = {
  tenantId: string;
  objectKey: string;
  region: Region;
  deletedAt: Date;
};

async function deleteExpiredExport(
  store: ObjectStore,
  record: ExportRecord,
  now: Date,
): Promise<DeletionAudit | null> {
  if (record.legalHold || now < record.deleteAfter) return null;

  await store.delete({ key: record.objectKey, region: record.region });
  const stillExists = await store.exists({
    key: record.objectKey,
    region: record.region,
  });
  if (stillExists) throw new Error("deletion not verified");

  return {
    tenantId: record.tenantId,
    objectKey: record.objectKey,
    region: record.region,
    deletedAt: now,
  };
}

Here, delete should be idempotent at the adapter boundary. A retry after a lost acknowledgment must converge on absence rather than create an operator puzzle. Test an already absent object, a held record, two workers claiming the same record, and a record whose deadline is exactly equal to now. Use expected client-side outcomes such as an unavailable export; don't turn internal storage details into public error text.

3. Make regional placement a record-level decision

β€œAvailable in the US and EU” is not a data-residency design. Store the selected region on every media and export record, derive it from the tenant's approved policy, and require every adapter operation to receive that region. Never infer placement from the machine running the worker. A retry in another deployment should target the same object location.

For an export containing many property photos, decide whether processing may cross the chosen boundary before writing code. The upload bucket, export worker, temporary archive, logs, backup behavior, and deletion evidence all belong in the review. Your mileage may vary because contracts and regulatory obligations differ; the concrete resolution is a written data-flow review with counsel, followed by an automated test that asserts the selected region reaches every storage operation.

Cross-region duplication is not suitable when the tenant requires data to remain in one approved region. Stick with single-region objects plus a recovery design accepted for that policy in that case. If the business requires regional failover, document how replicas are found and deleted; deleting only the primary defeats the retention rule.

4. Test browser download behavior, not just signatures

A correct signature can still produce a poor export flow. Verify the filename, media type, archive integrity, range behavior needed by your downloader, and what the user sees after expiry. For downloads, Content-Disposition: attachment tells the browser the response should be downloaded, while its filename parameters suggest the save name. MDN documents filename and filename*, including why both may be sent for compatibility.

Use a harmless ASCII fallback and a UTF-8 name where your signer supports response-header parameters. Then test the generated response in the browsers you actually support. Don't let a tenant-provided filename become an unchecked header value.

Run the same contract suite against every region and every storage candidate. It should upload a known fixture directly, confirm the stored checksum or byte-for-byte content through the supported mechanism, download it with a signed URL, verify the archive, advance the test clock, reject new link issuance, delete the object, and confirm absence. One 403-like outcome can be useful in a black-box expiry test, but the durable assertion is β€œaccess is denied after the deadline,” not a provider-specific error body.

Test the whole chain.

5. Choose the service with a deletion evidence matrix

Score the service against behavior you can exercise, not a feature-page adjective. I would use a matrix like this before discussing request or egress cost:

Test Evidence to retain Reject when
Direct upload Scope, expiry, content constraints, successful fixture The grant permits a different object key
Private download Tenant authorization record and expiry test A new link can be issued after retention expiry
Scheduled deletion Job result and confirmed absence Only database metadata disappears
Legal hold Hold audit and skipped deletion result A hold silently makes the file downloadable
Regional placement Region on the record and adapter-call test A worker can choose a different region implicitly
Portability Contract suite against the S3-compatible endpoint Required signing or deletion semantics need leaked vendor branches

Cost still matters to a solo team, especially when inspection video makes egress and retained bytes dwarf API-call volume. Model storage duration, upload and download traffic, operations, retrieval conditions, and deletion timing from your own workload. Public pricing pages, such as Backblaze B2's, can supply candidate inputs, but don't confuse a posted unit price with a complete bill or with proof that the retention controls fit.

The final choice should be conditional. Prefer the candidate that passes the direct-upload, scoped-download, region, hold, and verified-deletion tests with the smallest adapter surface. A service is not suitable when it cannot express your required regional placement or deletion evidence, even if its S3-compatible happy path works. Keep an existing provider when it passes the same contract suite and migration would add more operational risk than it removes.

Before deployment, rehearse one full property lifecycle in each region: direct-upload several media sizes, build an export, issue a temporary link, inspect the download headers, expire access, apply and release a hold on a separate fixture, delete every copy, and reconcile the audit record. Alert on overdue deletion records and on region mismatches, then review the retention intervals when the product changes. That is the operational checklist. The signed URL is just one line in it.

References

πŸ“° 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.