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

check body_filter rulesets even without content-length and chunked da… #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sandromodarelli
Copy link

…ta transmission

I reviewed how collections.RESPONSE_BODY have been filled. Added also a ctx.short_circuit = false to ensure rule processing.
res_body_max_size check is compared with total buffer length, so body_filter phase's rulesets can be processed even for dynamic pages (Transfer-Encoding: chunked)

…ta transmission

I reviewed how collections.RESPONSE_BODY have been filled. Added also a ctx.short_circuit = false to ensure rule processing.
res_body_max_size check is compared with total buffer length, so body_filter phase's rulesets can be processed even for dynamic pages (Transfer-Encoding: chunked)
@sandromodarelli
Copy link
Author

@p0pr0ck5 any news about this pull request?

Copy link
Owner

@p0pr0ck5 p0pr0ck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed response, and thanks for the patch. I think there may be a bug in the logic here, but I don't have time to test at this point.

ctx.res_length = ctx.res_length + string.len(data)
end

if eof or ctx.res_length > waf._res_body_max_size then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when the Nginx body filter runs a chunk again after this expression evaluates to true (ctx.res_length > waf._res_body_max_size)? from what i can tell, ctx.skip_buffering will be true because we set it in a previous body_filter run in this block. therefore, ngx.arg[1] will not be set to nil (as it is above on line 95), leading to mangled response bodies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when ctx.res_length > waf._res_body_max_size is true the response will be the concatenation of all chunks buffered.
The next chunk will not be processed because of ctx.skip_buffering on line 91: this means that ngx.arg[1] won't be touched and will contain the entire current chunk, ctx.short_circuit=true will be applied and chunk will be sent to client without lost of datas

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Do you have a test case to demonstrate this behavior?

We will need regression and integration tests for this change anyhow. Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any progress with this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandromodarelli im still waiting on a response for the following:

Do you have a test case to demonstrate this behavior?

We will need regression and integration tests for this change anyhow. Thanks!

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.

None yet

3 participants