Skip to content

Commit 51ec070

Browse files
authored
Stop json/plain from allocating arbitrary classes (0.0.7)
Oj object mode can allocate any Ruby class named in a json/plain payload. Allowlist what may round-trip, reject duplicate object keys and excessive nesting, then Oj.load the original bytes so existing encoded history still works. Encoding name stays json/plain. Runtime depends on google-protobuf ~> 3.25. CI now runs on transfers-master.
1 parent 0aa9e10 commit 51ec070

11 files changed

Lines changed: 694 additions & 41 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: Tests
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
# This fork ships from transfers-master. Without it, PRs to that branch had no CI.
6+
branches: [ "master", "transfers-master" ]
67
pull_request:
7-
branches: [ "master" ]
8+
branches: [ "master", "transfers-master" ]
89

910
jobs:
1011
test_gem:
@@ -35,9 +36,10 @@ jobs:
3536
steps:
3637
- uses: actions/checkout@v3
3738

39+
# ubuntu-latest no longer ships the docker-compose v1 binary.
3840
- name: Start dependencies
3941
run: |
40-
docker-compose \
42+
docker compose \
4143
-f examples/docker-compose.yml \
4244
up -d
4345
@@ -50,13 +52,31 @@ jobs:
5052
run: |
5153
cd examples && bundle install --path vendor/bundle
5254
53-
- name: Wait for dependencies to settle
55+
# auto-setup is not ready after a fixed sleep; wait until gRPC accepts connections.
56+
- name: Wait for Temporal
5457
run: |
55-
sleep 10
56-
58+
if timeout 300 bash -c 'until echo >/dev/tcp/127.0.0.1/7233; do sleep 2; done'; then
59+
exit 0
60+
fi
61+
echo "Temporal did not listen on 7233"
62+
docker compose -f examples/docker-compose.yml ps -a
63+
docker compose -f examples/docker-compose.yml logs --no-color --tail 400
64+
exit 1
65+
66+
# register_namespace can still race the server after 7233 is open.
5767
- name: Register namespace
5868
run: |
59-
cd examples && bin/register_namespace ruby-samples
69+
cd examples
70+
for i in $(seq 1 30); do
71+
if bin/register_namespace ruby-samples; then
72+
exit 0
73+
fi
74+
echo "register_namespace failed, retry ${i}"
75+
sleep 5
76+
done
77+
docker compose -f docker-compose.yml ps
78+
docker compose -f docker-compose.yml logs --tail 200
79+
exit 1
6080
6181
- name: Wait for namespace to settle
6282
run: |
@@ -78,6 +98,11 @@ jobs:
7898
run: |
7999
cd examples && bin/worker &
80100
101+
# Workers are started in the background; they are not ready at process spawn.
102+
- name: Wait for workers
103+
run: |
104+
sleep 10
105+
81106
- name: Run RSpec
82107
env:
83108
USE_ERROR_SERIALIZATION_V2: 1

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.0.7
4+
5+
- `json/plain` no longer builds arbitrary Ruby classes from encoded payloads. That was possible because Oj object mode can allocate any constant named in the payload.
6+
- Still round-trips first-party shapes: activity `Request` / `Response`, `Temporal::` types, Exception subclasses (including backtraces), `Date` / `DateTime` / `Rational`, anonymous Structs, and classes registered with `Temporal::JSON.allow_class`.
7+
- Rejects duplicate JSON object keys. Oj and `JSON.parse` disagree on duplicates, so a discarded value could still allocate a class.
8+
- Rejects constants that are only pending `autoload` until they are actually loaded.
9+
- Rejects JSON nested deeper than 512 levels.
10+
- Encoding name stays `json/plain`.
11+
- Runtime depends on `google-protobuf` ~> 3.25 (generated stubs under `lib/gen/` require protobuf 3).
12+
313
## 0.0.6
414

515
- Defer gRPC loading via autoload for fork safety

‎examples/docker-compose.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
version: '3.5'
22

3+
# Pin images. auto-setup:latest never bound gRPC :7233 with Cassandra 3.11 on GitHub runners.
34
services:
45
temporal:
5-
image: temporalio/auto-setup:latest
6+
image: temporalio/auto-setup:1.22.4
67
ports:
78
- "7233:7233"
89
environment:
@@ -14,7 +15,7 @@ services:
1415
- cassandra
1516

1617
temporal-web:
17-
image: temporalio/web:latest
18+
image: temporalio/web:1.15.0
1819
environment:
1920
- "TEMPORAL_GRPC_ENDPOINT=temporal:7233"
2021
ports:
@@ -23,6 +24,6 @@ services:
2324
- temporal
2425

2526
cassandra:
26-
image: cassandra:3.11
27+
image: cassandra:3.11.16
2728
ports:
2829
- "9042:9042"

‎lib/temporal/concerns/input_deserializer.rb‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ module Concerns
33
module InputDeserializer
44
def deserialize(input)
55
JSON.deserialize(input)
6-
rescue Oj::ParseError
6+
rescue Oj::ParseError, ::JSON::ParserError
7+
# JSON.parse now runs before Oj.load, so newline-split Go-client input raises
8+
# JSON::ParserError instead of Oj::ParseError. Do not rescue JSONDisallowedClassError.
79
# Copied over from the Cadence side, similar situation happening with Temporal
810
#
911
# cadence official go-client serializes / deserializes input in a different format than this ruby client

‎lib/temporal/errors.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ module Temporal
22
# Superclass for all Temporal errors
33
class Error < StandardError; end
44

5+
# Raised when json/plain asks Oj to allocate a class that is not allowlisted.
6+
class JSONDisallowedClassError < Error; end
7+
58
# Superclass for errors specific to Temporal worker itself
69
class InternalError < Error; end
710

0 commit comments

Comments
 (0)