Skip to content

feat(policies): pass request lengths to the proxy policies - #3903

Draft
butonic wants to merge 1 commit into
mainfrom
feat/policies-request-length
Draft

butonic wants to merge 1 commit into
mainfrom
feat/policies-request-length

Conversation

@butonic

@butonic butonic commented Nov 5, 2026

Copy link
Copy Markdown
Member

The proxy policies middleware now passes the declared request lengths to the policies engine: input.request.content_length (Content-Length) and input.request.upload_length (TUS Upload-Length). That allows rejecting too big uploads before any data is transferred:

granted = false if {
    input.request.upload_length > 10737418240
}

granted = false if {
    input.request.method == ["PUT", "PATCH"][_]
    input.request.content_length > 10737418240
}

I put them on the request instead of resource.size, because the resource is the target of the request (the middleware may even stat it) and in postprocessing resource.size is the actual file size.

This can only be an early check. With the concatenation extension several smaller uploads can be merged into one file, so postprocessing still has to check input.resource.size. A single PATCH can't exceed the declared Upload-Length, tusd already answers 413 for that.

protojson encodes uint64 as strings with camelCase keys, so NewEnvironmentFromPB copies the lengths explicitly instead of relying on the json round trip.

needed for the proxy part of https://github.com/opencloud-eu/opencloud-charts/pull/367

I used Claude Code to dig through the proxy, policies, reva and tusd code, write the change and tests and draft the texts. I reviewed and tested the result.

Assisted-by: Claude Code:claude-opus-5-5

The proxy policies middleware now passes the Content-Length of the
request body and the TUS Upload-Length header to the policies engine
as input.request.content_length and input.request.upload_length. This
allows rejecting uploads that are too big before any data is
transferred, instead of only in postprocessing after the upload has
completed.

We add them to the request instead of setting resource.size, because
the resource describes the target of the request (the middleware may
even stat it) and in postprocessing resource.size is the actual file
size.

This can only be an early check. The TUS concatenation extension
allows merging several smaller uploads into one file, so the file size
still has to be checked in postprocessing.

protojson encodes uint64 values as strings with camelCase keys, so
NewEnvironmentFromPB copies the lengths explicitly.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
@codacy-production

codacy-production Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity

Metric Results
Complexity 5

View in Codacy

🟢 Coverage 50.00% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 50.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (331855f) 93429 26714 28.59%
Head commit (bd4325b) 93449 (+20) 26726 (+12) 28.60% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3903) 20 10 50.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@butonic butonic self-assigned this Nov 5, 2026
@butonic
butonic marked this pull request as draft November 5, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants