Skip to content

fix: consuming v0.9 A2UI JSONL stream#868

Open
juan-vgv wants to merge 1 commit intoflutter:mainfrom
juan-vgv:main
Open

fix: consuming v0.9 A2UI JSONL stream#868
juan-vgv wants to merge 1 commit intoflutter:mainfrom
juan-vgv:main

Conversation

@juan-vgv
Copy link
Copy Markdown
Contributor

Description

Fixes #867.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-devrel channel on Discord.

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 introduces logic to handle JSONL separators by tracking whether the last processed event was a JSON message. While this correctly handles whitespace between JSON objects, a potential Denial of Service vulnerability was identified where the buffer could grow indefinitely if followed by a continuous stream of whitespace. A limit on the buffer size for whitespace-only content is recommended to prevent memory exhaustion.

Comment on lines +136 to +140
if (_lastWasJson && _buffer.trim().isEmpty) {
// Whitespace-only after a JSON message: treat as JSONL separator.
// Hold in buffer until more data arrives or stream ends.
break;
}
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.

security-high high

The newly introduced logic for handling JSONL separators in the _processBuffer method allows the _buffer to grow indefinitely if a JSON message is followed by a continuous stream of whitespace. When _lastWasJson is true and the buffer contains only whitespace, the code breaks out of the processing loop without clearing or emitting the buffer (lines 136-140). An attacker providing a stream of data can exploit this by sending a valid JSON message followed by an infinite or extremely large amount of whitespace, leading to memory exhaustion and a Denial of Service (DoS) crash of the application.

To remediate this, implement a limit on the maximum amount of whitespace that can be held in the buffer as a separator. If the whitespace-only buffer exceeds a reasonable threshold (e.g., 4KB), it should be cleared or emitted as a TextEvent to prevent unbounded memory growth.

          if (_lastWasJson && _buffer.trim().isEmpty) {
            if (_buffer.length > 4096) {
              _emitText(_buffer);
              _buffer = '';
            } else {
              break;
            }
          }

The current implementation is treating newline character as a TextEvent, as opposed to a JSONL newline separator.

See transport decoupling for more information:

https://github.com/google/A2UI/blob/main/specification/v0_9/docs/a2ui_protocol.md#transport-decoupling
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.

Fails to consume a v0.9 A2UI JSONL stream

1 participant