Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/packages/engine/tests/common/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@
.expect("Failed to create WebSocket request");

// Add protocols for routing through guard to actor
// URL encode the actor ID since colons are not allowed in WebSocket protocol names

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs

Check warning on line 440 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/rivet/rivet/engine/packages/engine/tests/common/actors.rs
request.headers_mut().insert(
"Sec-WebSocket-Protocol",
format!("rivet, rivet_target.actor, rivet_actor.{}", actor_id)
format!("rivet, rivet_target.actor, rivet_actor.{}", urlencoding::encode(&actor_id))

Check failure on line 443 in engine/packages/engine/tests/common/actors.rs

View workflow job for this annotation

GitHub Actions / Check

failed to resolve: use of unresolved module or unlinked crate `urlencoding`
.parse()
.unwrap(),
);
Expand Down
10 changes: 7 additions & 3 deletions engine/packages/guard/src/routing/pegboard_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn route_request(

let protocols: Vec<&str> = protocols_header.split(',').map(|p| p.trim()).collect();

let actor_id = protocols
let actor_id_raw = protocols
.iter()
.find_map(|p| p.strip_prefix(WS_PROTOCOL_ACTOR))
.ok_or_else(|| {
Expand All @@ -70,6 +70,10 @@ pub async fn route_request(
.build()
})?;

let actor_id = urlencoding::decode(actor_id_raw)
.context("invalid url encoding in actor id")?
.to_string();

let token = protocols
.iter()
.find_map(|p| p.strip_prefix(WS_PROTOCOL_TOKEN));
Expand All @@ -95,11 +99,11 @@ pub async fn route_request(
.transpose()
.context("invalid x-rivet-token header")?;

(actor_id, token)
(actor_id.to_string(), token)
};

// Find actor to route to
let actor_id = Id::parse(actor_id_str).context("invalid x-rivet-actor header")?;
let actor_id = Id::parse(&actor_id_str).context("invalid x-rivet-actor header")?;

route_request_inner(ctx, shared_state, actor_id, path, token).await
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class CloudflareActorsManagerDriver implements ManagerDriver {
const protocols: string[] = [];
protocols.push(WS_PROTOCOL_STANDARD);
protocols.push(`${WS_PROTOCOL_TARGET}actor`);
protocols.push(`${WS_PROTOCOL_ACTOR}${actorId}`);
protocols.push(`${WS_PROTOCOL_ACTOR}${encodeURIComponent(actorId)}`);
protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
if (params) {
protocols.push(
Expand Down Expand Up @@ -205,7 +205,7 @@ export class CloudflareActorsManagerDriver implements ManagerDriver {
const protocols: string[] = [];
protocols.push(WS_PROTOCOL_STANDARD);
protocols.push(`${WS_PROTOCOL_TARGET}actor`);
protocols.push(`${WS_PROTOCOL_ACTOR}${actorId}`);
protocols.push(`${WS_PROTOCOL_ACTOR}${encodeURIComponent(actorId)}`);
protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
if (params) {
protocols.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
WS_PROTOCOL_ACTOR,
WS_PROTOCOL_CONN_PARAMS,
WS_PROTOCOL_ENCODING,
WS_PROTOCOL_STANDARD,
WS_PROTOCOL_TARGET,
WS_TEST_PROTOCOL_PATH,
} from "@/common/actor-router-consts";
Expand Down Expand Up @@ -180,12 +181,11 @@ export function createTestInlineClientDriver(
const wsProtocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
const finalWsUrl = `${wsProtocol}//${wsUrl.host}${wsUrl.pathname}`;

logger().debug({ msg: "connecting to websocket", url: finalWsUrl });

// Build protocols for the connection
const protocols: string[] = [];
protocols.push(WS_PROTOCOL_STANDARD);
protocols.push(`${WS_PROTOCOL_TARGET}actor`);
protocols.push(`${WS_PROTOCOL_ACTOR}${actorId}`);
protocols.push(`${WS_PROTOCOL_ACTOR}${encodeURIComponent(actorId)}`);
protocols.push(`${WS_PROTOCOL_ENCODING}${encoding}`);
protocols.push(
`${WS_TEST_PROTOCOL_PATH}${encodeURIComponent(normalizedPath)}`,
Expand All @@ -196,6 +196,12 @@ export function createTestInlineClientDriver(
);
}

logger().debug({
msg: "connecting to websocket",
url: finalWsUrl,
protocols,
});

// Create and return the WebSocket
// Node & browser WebSocket types are incompatible
const ws = new WebSocket(finalWsUrl, protocols) as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ async function handleWebSocketGateway(
if (protocol.startsWith(WS_PROTOCOL_TARGET)) {
target = protocol.substring(WS_PROTOCOL_TARGET.length);
} else if (protocol.startsWith(WS_PROTOCOL_ACTOR)) {
actorId = protocol.substring(WS_PROTOCOL_ACTOR.length);
actorId = decodeURIComponent(protocol.substring(WS_PROTOCOL_ACTOR.length));
} else if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
encodingRaw = protocol.substring(WS_PROTOCOL_ENCODING.length);
} else if (protocol.startsWith(WS_PROTOCOL_CONN_PARAMS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function addManagerRoutes(

for (const protocol of protocols) {
if (protocol.startsWith(WS_PROTOCOL_ACTOR)) {
actorId = protocol.substring(WS_PROTOCOL_ACTOR.length);
actorId = decodeURIComponent(protocol.substring(WS_PROTOCOL_ACTOR.length));
} else if (protocol.startsWith(WS_PROTOCOL_ENCODING)) {
encoding = protocol.substring(
WS_PROTOCOL_ENCODING.length,
Expand Down
Loading