Limit read of well-known files #1

Open
opened 2026-03-19 21:13:32 +00:00 by Jade · 12 comments
Owner

CWE-409 or similar

CWE-409 or similar
Contributor

with "limit read" here do you mean like limit how much data is read?

with "limit read" here do you mean like limit how much data is read?

@s1lv3r wrote in #1 (comment):

with "limit read" here do you mean like limit how much data is read?

I think so, to avoid e.g. zip bombs

@s1lv3r wrote in https://forgejo.ellis.link/continuwuation/resolvematrix/issues/1#issuecomment-28052: > with "limit read" here do you mean like limit how much data is read? I think so, to avoid e.g. zip bombs

Something similar to spider size for URL previews could be used I guess?

Something similar to spider size for URL previews could be used I guess?
Contributor

or set a hardcoded max of like 1MB, no reasonable well-known file will ever be above that size

or set a hardcoded max of like 1MB, no reasonable well-known file will ever be above that size
Author
Owner

It's just an option that needs to be passed to reqwest iirc, not too hard to do.

It's just an option that needs to be passed to reqwest iirc, not too hard to do.
Contributor

Looked into it, would have to be done using either:

Probably the easiest to do the former, and fall back to the latter if the former fails. Will start an implementation.

Looked into it, would have to be done using either: - [`Response::content_length()`](https://docs.rs/reqwest/latest/reqwest/struct.Response.html#method.content_length): Not always known - Chunking, reading e.g. 8096 bytes at a time, adding to a `Vec`, counting the total (as described in https://github.com/seanmonstar/reqwest/issues/848) Probably the easiest to do the former, and fall back to the latter if the former fails. Will start an implementation.

@s1lv3r wrote in #1 (comment):

Looked into it, would have to be done using either:

* [`Response::content_length()`](https://docs.rs/reqwest/latest/reqwest/struct.Response.html#method.content_length): Not always known

One of the reasons this isnt known is

The response is gzipped and automatically decoded (thus changing the actual decoded length).

Given the CWE this is trying to avoid is with GZIP/compressed content, I would say that way is not helpful really.

@s1lv3r wrote in https://forgejo.ellis.link/continuwuation/resolvematrix/issues/1#issuecomment-28061: > Looked into it, would have to be done using either: > > * [`Response::content_length()`](https://docs.rs/reqwest/latest/reqwest/struct.Response.html#method.content_length): Not always known One of the reasons this isnt known is > The response is gzipped and automatically decoded (thus changing the actual decoded length). > Given the CWE this is trying to avoid is with GZIP/compressed content, I would say that way is not helpful really.

Anyways, I thought jade said it was just one param

Anyways, I thought jade said it was just one param
Contributor

I thought so too, doesn't look like it from what I could find

I thought so too, doesn't look like it from what I could find
Author
Owner

It's already done in Continuwuity, I was just going to copy from there

It's already done in Continuwuity, I was just going to copy from there
Contributor

oh

good idea, might as well yeah

oh good idea, might as well yeah
Owner

@Jade wrote in #1 (comment):

It's already done in Continuwuity, I was just going to copy from there

Relevant file: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/src/core/utils/response.rs

@Jade wrote in https://forgejo.ellis.link/continuwuation/resolvematrix/issues/1#issuecomment-28065: > It's already done in Continuwuity, I was just going to copy from there Relevant file: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/src/core/utils/response.rs
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#1505 Rewrite resolver service
continuwuation/continuwuity
Reference
continuwuation/resolvematrix#1
No description provided.