Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(pam-rdp): prime replay pointer off-screen instead of DOM overlay

bernie-g28410e1aaae2
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts
index 74adf46873..38ae02d094 100644
--- a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts
@@ -44,6 +44,18 @@ export class RdpDecoder {
*/
feed(action: number, bytes: Uint8Array): number;
height(): number;
+ /**
+ * Move the server-rendered pointer sprite to (x, y) and re-composite
+ * it into the framebuffer. Returns the number of dirty rectangles
+ * produced (read via `dirty_rect(i)`, same as `feed`).
+ *
+ * The server only emits PositionPointer PDUs for server-initiated
+ * cursor moves (dialog focus pulls, etc). Client-driven mouse
+ * movement is resolved locally — a live IronRDP client calls this
+ * on every mousemove. For replay we drive it from recorded input
+ * events so the cursor tracks the user's actual pointer path.
+ */
+ move_pointer(x: number, y: number): number;
/**
* Construct a decoder with a framebuffer of `width x height` pixels
* in RGBA32 format.
@@ -78,6 +90,7 @@ export interface InitOutput {
readonly rdpdecoder_dirty_rect: (a: number, b: number) => number;
readonly rdpdecoder_feed: (a: number, b: number, c: number, d: number) => number;
readonly rdpdecoder_height: (a: number) => number;
+ readonly rdpdecoder_move_pointer: (a: number, b: number, c: number) => number;
readonly rdpdecoder_new: (a: number, b: number) => number;
readonly rdpdecoder_stride: (a: number) => number;
readonly rdpdecoder_width: (a: number) => number;
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js
index 9421d5a092..7bcbee4f65 100644
--- a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js
@@ -2,6 +2,7 @@
export class DirtyRect {
static __wrap(ptr) {
+ ptr = ptr >>> 0;
const obj = Object.create(DirtyRect.prototype);
obj.__wbg_ptr = ptr;
DirtyRectFinalization.register(obj, obj.__wbg_ptr, obj);
@@ -145,6 +146,24 @@ export class RdpDecoder {
const ret = wasm.rdpdecoder_height(this.__wbg_ptr);
return ret;
}
+ /**
+ * Move the server-rendered pointer sprite to (x, y) and re-composite
+ * it into the framebuffer. Returns the number of dirty rectangles
+ * produced (read via `dirty_rect(i)`, same as `feed`).
+ *
+ * The server only emits PositionPointer PDUs for server-initiated
+ * cursor moves (dialog focus pulls, etc). Client-driven mouse
+ * movement is resolved locally — a live IronRDP client calls this
+ * on every mousemove. For replay we drive it from recorded input
+ * events so the cursor tracks the user's actual pointer path.
+ * @param {number} x
+ * @param {number} y
+ * @returns {number}
+ */
+ move_pointer(x, y) {
+ const ret = wasm.rdpdecoder_move_pointer(this.__wbg_ptr, x, y);
+ return ret >>> 0;
+ }
/**
* Construct a decoder with a framebuffer of `width x height` pixels
* in RGBA32 format.
@@ -153,7 +172,7 @@ export class RdpDecoder {
*/
constructor(width, height) {
const ret = wasm.rdpdecoder_new(width, height);
- this.__wbg_ptr = ret;
+ this.__wbg_ptr = ret >>> 0;
RdpDecoderFinalization.register(this, this.__wbg_ptr, this);
return this;
}
@@ -182,7 +201,7 @@ export function start() {
function __wbg_get_imports() {
const import0 = {
__proto__: null,
- __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
},
__wbg_log_0c201ade58bb55e1: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
@@ -244,10 +263,10 @@ function __wbg_get_imports() {
const DirtyRectFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
- : new FinalizationRegistry(ptr => wasm.__wbg_dirtyrect_free(ptr, 1));
+ : new FinalizationRegistry(ptr => wasm.__wbg_dirtyrect_free(ptr >>> 0, 1));
const RdpDecoderFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
- : new FinalizationRegistry(ptr => wasm.__wbg_rdpdecoder_free(ptr, 1));
+ : new FinalizationRegistry(ptr => wasm.__wbg_rdpdecoder_free(ptr >>> 0, 1));
function addToExternrefTable0(obj) {
const idx = wasm.__externref_table_alloc();
@@ -256,7 +275,8 @@ function addToExternrefTable0(obj) {
}
function getStringFromWasm0(ptr, len) {
- return decodeText(ptr >>> 0, len);
+ ptr = ptr >>> 0;
+ return decodeText(ptr, len);
}
let cachedUint8ArrayMemory0 = null;
@@ -299,9 +319,8 @@ function decodeText(ptr, len) {
let WASM_VECTOR_LEN = 0;
-let wasmModule, wasmInstance, wasm;
+let wasmModule, wasm;
function __wbg_finalize_init(instance, module) {
- wasmInstance = instance;
wasm = instance.exports;
wasmModule = module;
cachedUint8ArrayMemory0 = null;
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm
index 3ea18ceadc..c4399f6d8f 100644
Binary files a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm and b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm differ
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm.d.ts b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm.d.ts
index ceb09f97d1..e91b5df952 100644
--- a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm.d.ts
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm.d.ts
@@ -16,6 +16,7 @@ export const rdpdecoder_buffer_ptr: (a: number) => number;
export const rdpdecoder_dirty_rect: (a: number, b: number) => number;
export const rdpdecoder_feed: (a: number, b: number, c: number, d: number) => number;
export const rdpdecoder_height: (a: number) => number;
+export const rdpdecoder_move_pointer: (a: number, b: number, c: number) => number;
export const rdpdecoder_new: (a: number, b: number) => number;
export const rdpdecoder_stride: (a: number) => number;
export const rdpdecoder_width: (a: number) => number;
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx
index 4dfbe9bd69..8170b71691 100644
--- a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx
@@ -46,10 +46,6 @@ export const RdpReplayView = ({ events, isStreaming = false, totalDurationMs }:
const progressFillRef = useRef<HTMLDivElement | null>(null);
const timeTextRef = useRef<HTMLSpanElement | null>(null);
const currentMsRef = useRef(0);
- // Cursor follows mouse input events as a DOM overlay (see PlayerCallbacks
- // doc); ref-driven so cursor moves don't re-render the player subtree.
- const cursorRef = useRef<HTMLDivElement | null>(null);
- const contentBoundsRef = useRef({ width: CANVAS_W, height: CANVAS_H });
const [isPlaying, setIsPlaying] = useState(false);
const [isBuffering, setIsBuffering] = useState(false);
const [lastSeenEventMs, setLastSeenEventMs] = useState(0);
@@ -83,18 +79,6 @@ export const RdpReplayView = ({ events, isStreaming = false, totalDurationMs }:
}
};
- const moveCursor = (x: number, y: number) => {
- const el = cursorRef.current;
- if (!el) return;
- // Cursor coords are in canvas pixel space. The cursor element is
- // absolutely positioned inside the same container the canvas fills, so
- // percentages of contentBounds map to the same scaled space.
- const { width, height } = contentBoundsRef.current;
- el.style.left = `${((x / width) * 100).toFixed(3)}%`;
- el.style.top = `${((y / height) * 100).toFixed(3)}%`;
- el.style.opacity = "1";
- };
-
// Player lifetime is mount-scoped; later chunks land via appendEvents.
useEffect(() => {
let cancelled = false;
@@ -122,12 +106,8 @@ export const RdpReplayView = ({ events, isStreaming = false, totalDurationMs }:
setIsPlaying(false);
setIsBuffering(false);
},
- onContentBoundsChange: (width, height) => {
- contentBoundsRef.current = { width, height };
- setContentBounds({ width, height });
- },
- onBuffering: (b) => setIsBuffering(b),
- onCursorMove: moveCursor
+ onContentBoundsChange: (width, height) => setContentBounds({ width, height }),
+ onBuffering: (b) => setIsBuffering(b)
})
.then((player) => {
if (cancelled) {
@@ -261,22 +241,6 @@ export const RdpReplayView = ({ events, isStreaming = false, totalDurationMs }:
}}
aria-label="RDP session replay"
/>
- <div
- ref={cursorRef}
- aria-hidden
- className="pointer-events-none absolute opacity-0"
- style={{ left: 0, top: 0, willChange: "left, top, opacity" }}
- >
- <svg width="14" height="22" viewBox="0 0 14 22" xmlns="http://www.w3.org/2000/svg">
- <path
- d="M0 0 L0 18 L4.5 14 L7 20 L9.5 19 L7 13 L13 13 Z"
- fill="white"
- stroke="black"
- strokeWidth="1"
- strokeLinejoin="round"
- />
- </svg>
- </div>
</div>
<AnimatePresence>
{feedback && (
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts
index 779eab8f7c..c91150e2d5 100644
--- a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts
@@ -20,11 +20,6 @@ type PlayerCallbacks = {
onEnded: () => void;
onContentBoundsChange: (width: number, height: number) => void;
onBuffering: (buffering: boolean) => void;
- // Cursor position is rendered as a DOM overlay rather than composited into
- // the canvas. IronRDP's pointer pipeline hides the framebuffer cursor as
- // soon as the server emits SetDefault (typical for Windows sessions) and
- // expects the host OS to render it; replay has no host cursor.
- onCursorMove: (x: number, y: number) => void;
};
let wasmReady: Promise<InitOutput> | null = null;
@@ -90,6 +85,9 @@ export class RdpReplayPlayer {
): Promise<RdpReplayPlayer> {
const wasm = await ensureWasm();
const decoder = new RdpDecoder(canvas.width, canvas.height);
+ // Prime pointer position off-screen so the first server-emitted pointer
+ // bitmap doesn't paint at (0,0) before the first recorded mouse event.
+ decoder.move_pointer(0xffff, 0xffff);
return new RdpReplayPlayer(events, canvas, callbacks, decoder, wasm);
}
@@ -146,6 +144,7 @@ export class RdpReplayPlayer {
// Frames are deltas, so replaying needs a fresh decoder state.
this.decoder.free();
this.decoder = new RdpDecoder(this.canvas.width, this.canvas.height);
+ this.decoder.move_pointer(0xffff, 0xffff);
this.ctx.fillStyle = "#000";
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.callbacks.onTick(0);
@@ -234,8 +233,10 @@ export class RdpReplayPlayer {
if (ev.payload) this.feedFrame(ev);
break;
case "mouse":
+ // Server only sends PositionPointer for its own moves; drive cursor from input.
if (ev.x !== undefined && ev.y !== undefined) {
- this.callbacks.onCursorMove(ev.x, ev.y);
+ const count = this.decoder.move_pointer(ev.x, ev.y);
+ if (count > 0) this.blitDirtyRects(count);
}
break;
case "keyboard":
diff --git a/wasm/ironrdp-decoder/src/lib.rs b/wasm/ironrdp-decoder/src/lib.rs
index a1056ce756..a20b2db2a5 100644
--- a/wasm/ironrdp-decoder/src/lib.rs
+++ b/wasm/ironrdp-decoder/src/lib.rs
@@ -14,6 +14,8 @@ use ironrdp_connector::connection_activation::ConnectionActivationSequence;
use ironrdp_connector::{BitmapConfig, Config, ConnectionResult, Credentials, DesktopSize};
use ironrdp_graphics::image_processing::PixelFormat;
use ironrdp_pdu::gcc::KeyboardType;
+use ironrdp_pdu::input::fast_path::FastPathInputEvent;
+use ironrdp_pdu::input::mouse::{MousePdu, PointerFlags};
use ironrdp_pdu::rdp::capability_sets::{BitmapCodecs, MajorPlatformType};
use ironrdp_pdu::rdp::client_info::{PerformanceFlags, TimezoneInfo};
use ironrdp_pdu::Action;
@@ -113,6 +115,47 @@ impl RdpDecoder {
self.last_dirty.len() as u32
}
+ /// Move the server-rendered pointer sprite to (x, y) and re-composite
+ /// it into the framebuffer. Returns the number of dirty rectangles
+ /// produced (read via `dirty_rect(i)`, same as `feed`).
+ ///
+ /// The server only emits PositionPointer PDUs for server-initiated
+ /// cursor moves (dialog focus pulls, etc). Client-driven mouse
+ /// movement is resolved locally — a live IronRDP client calls this
+ /// on every mousemove. For replay we drive it from recorded input
+ /// events so the cursor tracks the user's actual pointer path.
+ pub fn move_pointer(&mut self, x: u16, y: u16) -> u32 {
+ self.last_dirty.clear();
+ let event = FastPathInputEvent::MouseEvent(MousePdu {
+ flags: PointerFlags::empty(),
+ number_of_wheel_rotation_units: 0,
+ x_position: x,
+ y_position: y,
+ });
+ let outputs = match self
+ .stage
+ .process_fastpath_input(&mut self.image, &[event])
+ {
+ Ok(o) => o,
+ Err(_) => return 0,
+ };
+ for out in outputs {
+ if let ActiveStageOutput::GraphicsUpdate(region) = out {
+ let rx = region.left;
+ let ry = region.top;
+ let rw = region.right.saturating_sub(region.left).saturating_add(1);
+ let rh = region.bottom.saturating_sub(region.top).saturating_add(1);
+ self.last_dirty.push(DirtyRect {
+ x: rx,
+ y: ry,
+ w: rw,
+ h: rh,
+ });
+ }
+ }
+ self.last_dirty.len() as u32
+ }
+
/// Returns the i-th dirty rect from the most recent `feed()` call.
pub fn dirty_rect(&self, i: u32) -> Option<DirtyRect> {
self.last_dirty.get(i as usize).copied()