Skip to content

Add a server-wide maximum file lifetime (GOKAPI_MAX_EXPIRY_SECONDS) - #440

Open
D3strukt0r wants to merge 1 commit into
Forceu:masterfrom
D3strukt0r:feat/max-expiry
Open

D3strukt0r wants to merge 1 commit into
Forceu:masterfrom
D3strukt0r:feat/max-expiry

Conversation

@D3strukt0r

@D3strukt0r D3strukt0r commented Oct 31, 2026 •

Copy link
Copy Markdown

Description

Closes #265. cc @Forceu, and @i0rt and @Str00pwafel, who asked for this in #265.

Adds GOKAPI_MAX_EXPIRY_SECONDS, a server-wide maximum lifetime for files in seconds (0 or unset = no limit, behaviour unchanged). When it is set:

  • An explicit expiry that is longer than the maximum, or unlimited, is refused with HTTP 400 and the new error code ExpiryTooLong: /chunk/complete, /files/add, /files/modify and /files/duplicate. Admins included.
  • Without an explicit expiry, the default becomes the shorter of 14 days and the maximum.
  • Files uploaded through file requests, which are stored without a time limit today, expire after the maximum.
  • Duplicating a file whose expiry is unlimited or beyond the maximum without passing expiryDays is refused, so the copy can't outlive the limit.
  • /info/config reports MaxExpirySeconds. gokapi-cli uses it: when the server has a maximum and --expiry-days isn't given, it leaves the expiry out so the server default applies instead of sending "unlimited". Without a maximum the CLI behaves as before.
  • Admin UI: when a maximum is set, the time limit can't be switched off on the upload page, the days field is limited to it, and the edit dialog has no "unlimited" option and a calendar that ends at the maximum. Note: editing a file that is still unlimited from before the maximum was set pre-fills its expiry with the maximum, so saving the dialog shortens it.

The check lives in one place, fileupload.CheckMaxExpiry, with CapToMaxExpiry for expiries the uploader didn't choose. The setting is environment-only like GOKAPI_MAX_SIZE_GUESTUPLOAD, so there is no config or database change. Existing files keep their expiry when the maximum is switched on.

This probably conflicts with your draft #405 in routing.go, FileUpload.go and Api.go; happy to rebase onto it if you'd rather merge that first.

Screenshots (GOKAPI_MAX_EXPIRY_SECONDS=1209600, 14 days)

Upload page: the expiry can't be switched off and is limited to 14 days.

Bildschirmfoto 2026-10-31 um 15 15 52

Edit dialog: no "unlimited" option, the calendar ends at the maximum.

Bildschirmfoto 2026-10-31 um 15 16 15

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor / Chore

Technical Details

  • Database changes: No
  • Storage backend affected: No (applies to Local and S3 alike)
  • Usage of AI: Yes. The implementation and tests were written with Claude Code (Anthropic), following a design I specified. I reviewed the code, and the behaviour was checked end to end on a running server as described below.

How Has This Been Tested?

  • Manual Testing: server built from this branch with GOKAPI_MAX_EXPIRY_SECONDS=3600 and local storage: uploads with expiryDays=0 and 30 refused with 400, without expiryDays expiring after one hour; editing to unlimited refused; duplicating an unlimited file without expiryDays refused; a guest upload through a file request expires after one hour; gokapi-cli without --expiry-days works; admin upload page and edit dialog checked in Chrome (also with a 14-day maximum, see screenshots). With the variable unset everything behaves as before (unlimited uploads, 14-day default, unlimited guest uploads).
  • Unit Tests: go test ./... -parallel 8 with the CI tag sets test,awsmock, test,noaws, test,noaws,integration and test,awstest, all passing (12 new tests each).
  • Environment: Docker (golang:1.26) on macOS

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.

This branch has not been deployed

No deployments
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.

Feature Request: Restrict Expiry Time and Download Limit to Predefined Values

1 participant