Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SECRET_FILE_SIZE does not work as expected #198

Closed
casperklein opened this issue Aug 15, 2023 · 3 comments
Closed

SECRET_FILE_SIZE does not work as expected #198

casperklein opened this issue Aug 15, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@casperklein
Copy link
Contributor

Description

With SECRET_FILE_SIZE=10, a file upload of a 10MB file fails.

Relevant log output:

{"level":30,"time":1692055043495,"pid":19,"hostname":"hemmelig","reqId":"req-9","res":{"statusCode":413},"err":{"type":"FastifyError","message":"Request body is too large","stack":"FastifyError: Request body is too large\n    at rawBody (/home/node/hemmelig/node_modules/fastify/lib/contentTypeParser.js:207:16)\n    at ContentTypeParser.run (/home/node/hemmelig/node_modules/fastify/lib/contentTypeParser.js:167:5)\n    at handleRequest (/home/node/hemmelig/node_modules/fastify/lib/handleRequest.js:41:33)\n    at runPreParsing (/home/node/hemmelig/node_modules/fastify/lib/route.js:528:5)\n    at next (/home/node/hemmelig/node_modules/fastify/lib/hooks.js:168:7)\n    at handleResolve (/home/node/hemmelig/node_modules/fastify/lib/hooks.js:185:5)","name":"FastifyError","code":"FST_ERR_CTP_BODY_TOO_LARGE","statusCode":413},"msg":"Request body is too large"}
{"level":30,"time":1692055043496,"pid":19,"hostname":"hemmelig","reqId":"req-9","res":{"statusCode":413},"responseTime":3.1347219944000244,"msg":"request completed"}
{"level":30,"time":1692055073172,"pid":19,"hostname":"hemmelig","reqId":"req-a","req":{"method":"GET","url":"/","hostname":"localhost:3000","remoteAddress":"127.0.0.1","remotePort":59382},"msg":"incoming request"}

Screenshots

No response

Additional information

I noticed, that a SECRET_FILE_SIZE value of 19 or higher is needed, for a 10MB file upload.

@casperklein casperklein added the bug Something isn't working label Aug 15, 2023
@bjarneo
Copy link
Member

bjarneo commented Aug 22, 2023

Yes, this might be due to the file being encoded in the frontend before being shipped to the server, so it is kind of a bug, but not really. I think it should be documented better.

@casperklein
Copy link
Contributor Author

I think you are right. When uploading the 10MB test file, the transferred bytes are way more than 10MB.

From the HTTP request headers:

Content-Length: 18642131
Content-Type: application/json

Uploading the file json encoded seems to be the cause. I looked at other solutions for comparison.

filebrowser uses Content-Type: application/octet-stream. When uploading the 10MB test file to filebrowser, only 10MB are transfered (unencoded).

@bjarneo
Copy link
Member

bjarneo commented Aug 24, 2023

It should not be due to the json body, but due to it is being encrypted before shipped to the backend. Here is how it works: #163 (comment)

@bjarneo bjarneo closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants