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

feat(webhook): add request/response size limits #4837

Merged
merged 3 commits into from
Feb 16, 2025

Conversation

dbyron-sf
Copy link
Contributor

via new config properties webhook.maxRequestBytes and webhook.maxResponseBytes. The default value for both is 0.
When greater than 0, only requests/responses whose header + body size is less than or equal to the max are allowed.

via new config property webhook.maxRequestBytes (default 0).  When greater than 0, only
requests whose header + body size is less than or equal to maxRequestBytes are allowed.
via new config property webhook.maxResponseBytes (default 0).  When greater than 0, only
responses whose header + body size is less than or equal to maxResponseBytes are allowed.
…onse size

instead of cancelling the call.  The resulting exceptions from canceling were different
locally and in CI, and I suspect throwing our exceptions makes it easier to provide better
error messages to the user.
try {
contentLength = requestBody.contentLength();
if (contentLength == -1) {
// Given that OkHttp3ClientHttpRequestFactory.buildRequest (called by
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is possible. I think this occurs for streaming, e.g. trying to send a request with a massive file returns content length == -1. See chunked encoding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now, if webhooks can't do chunked encoding, then we can assume -1 wont be the value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll admit I haven't tried that hard to send a streamed request via a webhook stage. I don't think it's possible though since the request is defined in the pipeline config. Of course with SpEL expressions, etc. it can be dynamic and huge, but I still think it ends up being a String with a known length by the time we get here.

long headerSize = request.headers().byteCount();

// If the headers are already too big, no need to deal with the body size
if (headerSize > maxRequestBytes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I do like max payload size, but having a limitation on headers seems like that would already be handled by MOST http servers. Albeit they all default to some non-consistent value.

Is this more from a security stand point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, security, It's more from a quality of service / denial of service standpoint. Like, we didn't want pipeline authors to be able to generate massive requests and bog down Spinnaker.

@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Feb 16, 2025
@mergify mergify bot added the auto merged Merged automatically by a bot label Feb 16, 2025
@mergify mergify bot merged commit 028001a into spinnaker:master Feb 16, 2025
4 checks passed
@dbyron-sf dbyron-sf deleted the webhook-size-limits branch February 16, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for merge target-release/1.37
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants