Skip to content

fix: Upgrade protobufjs and fix legacy key decoding in Datastore#8088

Merged
danieljbruce merged 8 commits intomainfrom
fix-datastore-legacy-decode-protobufjs-upgrade-16655518185677337093
Apr 22, 2026
Merged

fix: Upgrade protobufjs and fix legacy key decoding in Datastore#8088
danieljbruce merged 8 commits intomainfrom
fix-datastore-legacy-decode-protobufjs-upgrade-16655518185677337093

Conversation

@danieljbruce
Copy link
Copy Markdown
Contributor

@danieljbruce danieljbruce commented Apr 21, 2026

Description

This pull request provides a better fix for what #8071 intends to fix. It resolves the protobufjs dependency issue and it ensures that unit tests don't break.

Impact

  1. Resolves security issue
  2. Ensures datastore unit tests pass

Testing

Tests have been added to ensure the legacyEncode and legacyDecode functionality remain the same. The only difference will be that with the new src changes, code that used to produce an invalid wire error will now produce a valid output.

Generated notes

Upgrades protobufjs to ^7.5.5 to address security vulnerabilities and fixes a regression in legacy App Engine key decoding. The fix involves calling .setup() on the affected protobuf types to ensure group support is preserved.


PR created automatically by Jules for task 16655518185677337093 started by @danieljbruce

Upgrades protobufjs to ^7.5.5 to address security vulnerabilities.
Introduces a fix for legacy App Engine key decoding by explicitly calling
.setup() on Reference, Path, and Element types. This ensures that group
support (wire types 3 and 4) is correctly initialized in newer versions
of protobufjs, which is required for these legacy keys.

Fixes the "invalid wire type 4" error in unit tests.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the protobufjs dependency to version ^7.5.5 and adds explicit initialization for the Reference, Path, and Element types in entity.ts to ensure group support for legacy keys. A review comment suggests refactoring the repetitive type lookups and setup calls into a loop to improve maintainability.

Comment thread handwritten/datastore/src/entity.ts Outdated
google-labs-jules Bot and others added 5 commits April 21, 2026 21:30
Upgrades protobufjs to ^7.5.5 to address security vulnerabilities (GHSA-xq3m-2v4x-88gg).
Resolves a functional regression in decoding legacy App Engine keys by
explicitly calling .setup() on Reference, Path, and Element types. This
forces the generation of optimized decoders that correctly support
proto2 groups, preventing "invalid wire type 4" errors.

Adds 10+ regression tests for legacyDecode covering various scenarios.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>
Upgrades protobufjs to ^7.5.5 to address security vulnerabilities (GHSA-xq3m-2v4x-88gg).
Resolves a functional regression in decoding legacy App Engine keys by
explicitly calling .setup() on Reference, Path, and Element types. This
forces the generation of optimized decoders that correctly support
proto2 groups, preventing "invalid wire type 4" errors.

Adds 10+ regression tests for legacyDecode and updates all legacy key tests
to verify that legacyDecode and legacyEncode are inverses of each other.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…185677337093' of https://github.com/googleapis/google-cloud-node into fix-datastore-legacy-decode-protobufjs-upgrade-16655518185677337093
@danieljbruce danieljbruce changed the title Upgrade protobufjs and fix legacy key decoding in Datastore fix: Upgrade protobufjs and fix legacy key decoding in Datastore Apr 22, 2026
@danieljbruce danieljbruce marked this pull request as ready for review April 22, 2026 15:20
@danieljbruce danieljbruce requested a review from a team as a code owner April 22, 2026 15:20
@danieljbruce danieljbruce requested a review from pearigee April 22, 2026 15:28
Comment thread handwritten/datastore/src/entity.ts Outdated
// In newer versions of protobufjs, this ensures group support
// is preserved for legacy keys.
for (const typeName of ['Reference', 'Path', 'Element']) {
(loadedRoot.lookupType(typeName) as any).setup();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove the as any? If possible we should just import and use the correct type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. It looks like when we remove as any then this works just fine.

Comment thread handwritten/datastore/test/entity.ts Outdated
);
});

const TEST_PROJECT = 'test-project';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this line and below just be its own test? Nesting it's within it's seems needlessly nested for the reader.

Alternatively, you could make a new root describe to group the tests? For example:

const testCases = [...];

describe('decoding keys`, () => {
   testCases.foreEach(tc => {
       it(`should decode "${tc.name}"`, () => {...});
   });
}); 

describe('encoding keys`, () => {
   testCases.foreEach(tc => {
       it(`should ecode "${tc.name}"`, () => {...});
   });
}); 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I added a describe block to group the tests. I'm not sure what you mean by nesting it inside it though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Before, if I understood correctly, we were doing something like this:

it('root test' () => {
    tests.forEach(t => {
        // Here we have an `it`, inside another `it`.
        it(`child test ${t.name}`, () => {

         });
    })
});

This isn't the convention I have seen in the past. It's common to nest tests in a describe, but not tests in tests.

Copy link
Copy Markdown
Contributor Author

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

Added a bit of cleanup.

Comment thread handwritten/datastore/src/entity.ts Outdated
// In newer versions of protobufjs, this ensures group support
// is preserved for legacy keys.
for (const typeName of ['Reference', 'Path', 'Element']) {
(loadedRoot.lookupType(typeName) as any).setup();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. It looks like when we remove as any then this works just fine.

Comment thread handwritten/datastore/test/entity.ts Outdated
);
});

const TEST_PROJECT = 'test-project';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I added a describe block to group the tests. I'm not sure what you mean by nesting it inside it though.

@danieljbruce danieljbruce merged commit 939d18d into main Apr 22, 2026
31 of 32 checks passed
@danieljbruce danieljbruce deleted the fix-datastore-legacy-decode-protobufjs-upgrade-16655518185677337093 branch April 22, 2026 19:20
vverman pushed a commit to vverman/google-cloud-node that referenced this pull request Apr 22, 2026
…gleapis#8088)

* fix: upgrade protobufjs and fix legacy key decoding

Upgrades protobufjs to ^7.5.5 to address security vulnerabilities.
Introduces a fix for legacy App Engine key decoding by explicitly calling
.setup() on Reference, Path, and Element types. This ensures that group
support (wire types 3 and 4) is correctly initialized in newer versions
of protobufjs, which is required for these legacy keys.

Fixes the "invalid wire type 4" error in unit tests.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>

* fix: upgrade protobufjs and fix legacy key decoding

Upgrades protobufjs to ^7.5.5 to address security vulnerabilities (GHSA-xq3m-2v4x-88gg).
Resolves a functional regression in decoding legacy App Engine keys by
explicitly calling .setup() on Reference, Path, and Element types. This
forces the generation of optimized decoders that correctly support
proto2 groups, preventing "invalid wire type 4" errors.

Adds 10+ regression tests for legacyDecode covering various scenarios.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>

* fix: upgrade protobufjs and fix legacy key decoding with inverse tests

Upgrades protobufjs to ^7.5.5 to address security vulnerabilities (GHSA-xq3m-2v4x-88gg).
Resolves a functional regression in decoding legacy App Engine keys by
explicitly calling .setup() on Reference, Path, and Element types. This
forces the generation of optimized decoders that correctly support
proto2 groups, preventing "invalid wire type 4" errors.

Adds 10+ regression tests for legacyDecode and updates all legacy key tests
to verify that legacyDecode and legacyEncode are inverses of each other.

Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>

* Apply suggestion from @gemini-code-assist[bot]

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* fix: Upgrade protobufjs and fix legacy key decoding in Datastore

* Remove the as any cast

* Add a describe block for the encode/decode tests

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: danieljbruce <8935272+danieljbruce@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

2 participants