Temporary Public Links: When to Expire, Redirect, or Return an Error

Learn when expired share links should return an error or redirect, how to protect private content, and what to test before shipping a recovery flow.

Published
Reading time
8 min read
Temporary Public Links: When to Expire, Redirect, or Return an Error
On this page

Temporary share links need a predictable end of life. When a report link expires or an invitation is revoked, the response should help legitimate users without turning an old URL into a path to private information.

This guide explains how to handle expired public share links, choose between an error and a redirect, and test the resulting behavior.

Key Takeaways

  • Expiry ends a link’s validity on a schedule; revocation ends it early. Neither necessarily deletes the underlying resource.
  • Use an error when access has ended. A redirect is appropriate only when its destination is safe and independently authorized.
  • 404, 410, and other responses have different meanings, but no single status is right for every product.
  • Treat a share token as a credential: avoid exposing it in logs, redirect URLs, or downstream requests.
  • Test the response and the destination with non-sensitive accounts, including after redirects and at the expiry boundary.

A public share link may grant access to anyone who possesses it, even if the underlying report or workspace is private. Decide separately what happens to the link, the resource, and any user who already has independent access.

SituationExampleDecision
ExpiredA report link reaches its configured end time.Reject the token and show a neutral explanation or a generic unavailable page.
RevokedAn owner disables an invitation before its expiry.Reject it immediately; do not rely on the original expiry time.
ReplacedA report has moved to a new location.Redirect only if the destination enforces its own appropriate access checks.
Resource removedThe shared report itself was deleted.Return an unavailable response; do not imply that obtaining a new link will restore it.
Still authorizedA signed-in employee has separate permission to view the report.Offer a route through the normal authenticated access flow, with authorization checked again.

For a sensitive invitation, a generic “This link is unavailable” page may be safer than revealing whether it expired, was revoked, or was addressed to a particular person. The product can still give a next step, such as asking the user to contact the sender.

Advertisement

Choose an HTTP response

The following choices describe common HTTP semantics, not a mandatory product policy. RFC 9110 was not available to consult for this article; verify the relevant semantics and your framework’s behavior against it before implementation.

ResponseWhen it can fitConsideration
404 Not FoundThe link is unavailable, or the service does not want to confirm that it existed.A generic response can cover unknown, expired, and revoked tokens.
410 GoneThe service knows the link is no longer available and considers that condition permanent.It communicates more than 404; use it only when that disclosure is acceptable. The link may be gone even if the report still exists.
400 Bad RequestThe request is malformed in a way the server chooses to identify as a client error.For an invalid token, a generic 404 may avoid distinguishing token formats or states.
401 UnauthorizedAuthentication is required for the requested endpoint.A 401 response requires an appropriate authentication challenge in WWW-Authenticate; it is not simply a synonym for an expired token.
403 ForbiddenThe server understands the request but refuses it, for example after an authenticated user lacks permission.Consider whether confirming the resource or permission state reveals too much.
302 Found or 303 See OtherA safe recovery page or authorized replacement should be visited.303 is useful after a form submission when the next step should be a retrieval. Check the destination independently.

An HTML error page can have a clear message while still returning an appropriate error status. Returning 200 OK for every unavailable link can make monitoring and automated clients treat failures as successes.

Expiry is not the same as deletion

Suppose /share/<token> grants temporary access to a report. Once the token expires, the server should reject that token even if the report remains available to its owner. A 410 can describe the permanently unavailable link, not necessarily the underlying report. If the same token can later be reactivated, that permanence claim may not fit; choose a response consistent with the actual lifecycle.

Redirect without widening access

A redirect changes where the browser goes; it does not transfer authorization safely by itself. An expired access link must not redirect to a page that grants broader access or reveals private information.

For example, do not redirect an expired report link to a publicly accessible copy of the report, an unprotected workspace page, or a URL containing the report’s title or recipient’s email address. Do not forward the expired token in the destination query string. A destination must enforce its own access policy, including authentication and authorization where required.

Safer options include:

  • Return a generic unavailable page with a link to the product’s normal sign-in page.
  • Redirect to a generic recovery page that contains no private resource details and does not grant access.
  • For a known replacement resource, redirect only when its access controls are appropriate for the original audience. Avoid accepting an arbitrary destination from a request parameter; use an approved destination selected by the server.

A signed-in user’s independent access can be checked after sign-in. Possession of an expired token alone should not restore that access. Also make the recovery flow work when the user has no account or permission: ask them to contact the sender rather than exposing private details.

Advertisement

Implement the lifecycle deliberately

For a shared report or invitation, record enough server-side state to determine whether the token is valid, expired, or revoked. Check that state on every access, using a consistent server-side clock and a defined expiry boundary. Revocation should take effect immediately in the authorization path; caches or replicas that retain old state can otherwise extend access.

Use unpredictable tokens and handle them as secrets. Avoid recording full share URLs in application logs or analytics, and avoid including tokens in redirect destinations. A Referrer-Policy: no-referrer header on sensitive link pages can reduce referrer leakage. Use Cache-Control: no-store on sensitive responses, including redirects, where retaining them would be unsafe; also review intermediary caching behavior.

For invitations, do not make a simple page visit perform an irreversible acceptance. Link previews and security scanners may open URLs automatically. Show a confirmation page and require an intentional action to accept; protect state-changing requests against cross-site request forgery as appropriate. If accepting creates or changes account access, verify the intended recipient and authorization according to the product’s policy.

Test with non-sensitive accounts

Use isolated test reports and accounts with no real customer data. Inspect both the HTTP status and response headers, and follow any redirect separately. The following cases are a starting point; adjust expected statuses to your documented policy.

TestSetup and actionCheck
ExpiredCreate a link with an expiry in the past, then request it.The token cannot retrieve the report; the chosen error or recovery page reveals no private data.
RevokedCreate a valid link, revoke it, then request it before its scheduled expiry.Access is denied immediately, including through any cache or alternate application instance.
MalformedRequest a truncated or otherwise invalid token.The server handles it without an exception or private diagnostic details; its response follows your disclosure policy.
Still authorizedSign in as a test user who has separate permission, then open an expired link and use the normal access flow.The expired token is rejected, but the user can reach the report only after an independent authorization check.
Valid linkOpen an unexpired, unrevoked link with the intended access scope.It grants only the configured access, without exposing unrelated resources.
RedirectTrigger each configured recovery or replacement redirect.The Location is approved, contains no token or private data, and the destination does not grant unauthorized access.
Boundary and scanningCheck just before and at the defined expiry boundary; separately open an invitation without confirming it.The boundary matches policy, and a page visit alone does not accept the invitation.

Also test a signed-in account without independent permission and a user who is signed out. Neither should gain access through an expired token. These are suggested test cases; they have not been executed for this article.

Common Mistakes

  • Treating expiry as resource deletion. A link and the resource it once exposed can have different lifecycles.
  • Redirecting to an easier-to-access copy. A replacement must not bypass the original access decision.
  • Leaking state in error messages. Recipient names, report titles, and distinct error details can disclose information to someone holding or guessing a link.
  • Assuming a redirect is harmless. Check its Location, caching, referrer behavior, and destination authorization.
  • Revoking only in the interface. The server must reject the token, including when requests reach cached or replicated state.

Best Practices

Document the expiry boundary, revocation behavior, and recovery path as product decisions. Use a consistent response policy for sensitive link states, monitor failures without storing credentials, and recheck authorization at every destination. Review the complete flow whenever a replacement page, cache, or invitation workflow changes.

Conclusion

When a public share link ends, reject the old token first. Then choose an error or a safe recovery path based on what the product can disclose and whether the destination independently protects the resource.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.