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

Port DOS protections to our protojson fork #143

Merged
merged 1 commit into from
Jan 3, 2024

Conversation

tdeebswihart
Copy link
Contributor

What changed?

I ported over the DOS fixes from the official protobuf repository

Why?

Two DOS bugs were fixed by golang/protobuf recently:

  1. protojson: vuln: malicious JSON can trivially induce stack overflow golang/protobuf#1583
  2. protojson: vuln: discard unknown fields can result in stack overflow golang/protobuf#1584

How did you test it?

I ported over their tests for the issue

Potential risks

None,

This commit ports over the fixes (and tests) for the two DOS bugs fixed
by golang/protobuf recently:

1. golang/protobuf#1583
2. golang/protobuf#1584

These changes come from protocolbuffers/protobuf-go@bfcd647
@tdeebswihart tdeebswihart requested review from a team as code owners January 3, 2024 16:59
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

In a perfect world we'd maintain just a set of patches on top of existing lib, but that is annoying.

Comment on lines +312 to +324
var open int
for {
tok, err := d.Read()
if err != nil {
return err
}

case json.ArrayOpen:
for {
tok, err := d.Peek()
if err != nil {
return err
}
switch tok.Kind() {
case json.ArrayClose:
d.Read()
return nil
default:
// Skip array item.
if err := d.skipJSONValue(); err != nil {
return err
}
switch tok.Kind() {
case json.ObjectClose, json.ArrayClose:
open--
case json.ObjectOpen, json.ArrayOpen:
open++
if open > d.opts.RecursionLimit {
return errors.New("exceeded max recursion depth")
Copy link
Contributor

Choose a reason for hiding this comment

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

You're not doing recursion anymore, so does it matter to track the depth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copied verbatim from the official codebase

@tdeebswihart
Copy link
Contributor Author

In a perfect world we'd maintain just a set of patches on top of existing lib, but that is annoying.

We'd need to fork the whole protobuf stack to do so, which would suck. We could do that and periodically rebase our changes on the upstream, but that's a lot of work

@tdeebswihart tdeebswihart merged commit 608bdd1 into master Jan 3, 2024
4 checks passed
@tdeebswihart tdeebswihart deleted the tds/patch-protojson-vuln branch January 3, 2024 18:59
tdeebswihart added a commit to temporalio/sdk-go that referenced this pull request Jan 3, 2024
tdeebswihart added a commit to temporalio/sdk-go that referenced this pull request Jan 8, 2024
tdeebswihart added a commit to temporalio/sdk-go that referenced this pull request Jan 8, 2024
Bump the version of go-api fix the protojson DOS vulns recently patched in the upstream golang/protobuf. See temporalio/api-go#143 for details
tdeebswihart added a commit to temporalio/temporal that referenced this pull request Jan 8, 2024
## What was changed

I bumped the version of api-go and sdk-go and _slightly_ altered our
nettest RPC factory interface to deal with changes in v1.60.0 of go-grpc

## Why?

To fix the protojson DOS vulns recently patched in the upstream
golang/protobuf. See temporalio/api-go#143 for
details

## How did you test it?

I pulled the tests added to the protojson repo into our fork

## Potential risks

N/A

## Is hotfix candidate?

No as it requires all our other proto changes which aren't released
tdeebswihart added a commit to temporalio/temporal that referenced this pull request Jan 9, 2024
## What was changed

I bumped the version of api-go and sdk-go and _slightly_ altered our
nettest RPC factory interface to deal with changes in v1.60.0 of go-grpc

## Why?

To fix the protojson DOS vulns recently patched in the upstream
golang/protobuf. See temporalio/api-go#143 for
details

## How did you test it?

I pulled the tests added to the protojson repo into our fork

## Potential risks

N/A

## Is hotfix candidate?

No as it requires all our other proto changes which aren't released
tdeebswihart added a commit to temporalio/temporal that referenced this pull request Jan 9, 2024
## What was changed

I bumped the version of api-go and sdk-go and _slightly_ altered our
nettest RPC factory interface to deal with changes in v1.60.0 of go-grpc

## Why?

To fix the protojson DOS vulns recently patched in the upstream
golang/protobuf. See temporalio/api-go#143 for
details

## How did you test it?

I pulled the tests added to the protojson repo into our fork

## Potential risks

N/A

## Is hotfix candidate?

No as it requires all our other proto changes which aren't released
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.

3 participants