No. Protocol Buffers give you typed fields, so a number arrives as a number. They do not check whether the value makes sense: an email can be any string, an age can be negative, a list can be huge. OWASP's gRPC guidance says protobuf provides type safety but not business logic validation, so validate on the server.
What protobuf checks
A .proto file defines messages, fields and types. When a server parses a message, it checks that the bytes form the declared structure. A string field holds a string, an integer field holds an integer. That removes whole classes of confusion that free form text formats allow.
It does not know your rules. The same field can hold an empty string, a ten megabyte string, a string with control characters, or a number outside any sensible range.
What it leaves to you
| Concern | Protobuf checks it? | What to do |
|---|---|---|
| Field has the right type | Yes | Nothing extra |
| String length | No | Set min and max |
| Allowed characters | No | Use an allowlist |
| Numeric range | No | Set bounds |
| Required fields | Not in a business sense | Check presence and content |
| List length | No | Cap entries |
| Authorization of the caller | No | Check per method |
| Total message size | Not by itself | Set server limits |
The protobuf documentation also gives guidance about size: it is not designed for large messages, and as a rule of thumb, messages larger than a megabyte each are a signal to consider another strategy. So set limits instead of assuming a large message will be handled.
Adding validation rules
OWASP's cheat sheet shows a rule based approach. Using a validation plugin, you annotate fields in the schema with constraints such as an email format, minimum and maximum string length and numeric bounds, and the generated code validates messages automatically. It also advises allowlist validation for string inputs to prevent unexpected characters and injection, and parameterized queries when values reach a database.
Whether you use annotations, a validation library or hand written checks, put the checks in one place that every method uses. Interceptors are a natural spot, as long as you cover both unary and streaming methods. See why a unary interceptor does not protect streams.
Steps
- For each request message, list every field and the rule it should obey.
- Write the rules into the schema annotations or a validation layer.
- Reject invalid messages early with an invalid argument status and a short message that does not reveal internals.
- Cap list and map sizes explicitly.
- Set server message size limits.
- Use allowlists for strings that reach interpreters such as databases or shells.
- Add fuzz or property tests that send odd but type correct values: empty, huge, negative, unicode.
- Validate again at trust boundaries. A message from another internal service is still input.
A note on unknown data
Messages can carry fields your code does not know about, especially when versions differ. Decide how your service handles unexpected values, and test with newer and older message versions so mismatches fail safely.
Try it yourself
Click through it at your own pace, or open it full screen.
Look at how a code scan locates unvalidated input reaching sensitive calls, then think about your handlers.
Quick check
Does protobuf stop injection attacks?
No. A string field can hold any text. Use allowlists and parameterized queries wherever values reach a database or command.
Where should validation live in a gRPC service?
In one shared layer used by every method, such as interceptors plus handler checks, covering unary and streaming calls.
Safeguard scans your dependencies and SBOMs for known vulnerabilities, including protobuf and gRPC libraries, and shows which are reachable. A free scan is at gold.safeguard.sh/scan.
Sources
Last reviewed: 19 October 2026.