Skip to content

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

feat(pam-rdp): browser RDP session replay player

bernie-g9d0f2a9c37d1
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts
new file mode 100644
index 0000000000..38ae02d094
--- /dev/null
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.d.ts
@@ -0,0 +1,126 @@
+/* tslint:disable */
+/* eslint-disable */
+
+export class DirtyRect {
+ private constructor();
+ free(): void;
+ [Symbol.dispose](): void;
+ h: number;
+ w: number;
+ x: number;
+ y: number;
+}
+
+export enum PduAction {
+ X224 = 0,
+ FastPath = 1,
+}
+
+/**
+ * A decoder session tied to a specific desktop size. Create one per
+ * replay, feed PDUs in original order, read out the framebuffer + dirty
+ * regions after each call.
+ */
+export class RdpDecoder {
+ free(): void;
+ [Symbol.dispose](): void;
+ buffer_len(): number;
+ /**
+ * Returns a pointer into the WASM linear memory for the RGBA
+ * framebuffer. JS reads this as a `Uint8Array` of length
+ * `width * height * 4`.
+ */
+ buffer_ptr(): number;
+ /**
+ * Returns the i-th dirty rect from the most recent `feed()` call.
+ */
+ dirty_rect(i: number): DirtyRect | undefined;
+ /**
+ * Feed one captured PDU into the decoder. Returns the number of
+ * dirty rectangles produced; read each via `dirty_rect(i)`.
+ *
+ * `action` is 0 for X.224 and 1 for FastPath; mirrors the tap event
+ * emitted by the gateway.
+ */
+ 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.
+ */
+ constructor(width: number, height: number);
+ /**
+ * Returns the row stride in bytes. Usually `width * 4` but IronRDP
+ * may align differently.
+ */
+ stride(): number;
+ width(): number;
+}
+
+export function start(): void;
+
+export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
+
+export interface InitOutput {
+ readonly memory: WebAssembly.Memory;
+ readonly __wbg_dirtyrect_free: (a: number, b: number) => void;
+ readonly __wbg_get_dirtyrect_h: (a: number) => number;
+ readonly __wbg_get_dirtyrect_w: (a: number) => number;
+ readonly __wbg_get_dirtyrect_x: (a: number) => number;
+ readonly __wbg_get_dirtyrect_y: (a: number) => number;
+ readonly __wbg_rdpdecoder_free: (a: number, b: number) => void;
+ readonly __wbg_set_dirtyrect_h: (a: number, b: number) => void;
+ readonly __wbg_set_dirtyrect_w: (a: number, b: number) => void;
+ readonly __wbg_set_dirtyrect_x: (a: number, b: number) => void;
+ readonly __wbg_set_dirtyrect_y: (a: number, b: number) => void;
+ readonly rdpdecoder_buffer_len: (a: number) => number;
+ readonly rdpdecoder_buffer_ptr: (a: number) => number;
+ 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;
+ readonly start: () => void;
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
+ readonly __wbindgen_exn_store: (a: number) => void;
+ readonly __externref_table_alloc: () => number;
+ readonly __wbindgen_externrefs: WebAssembly.Table;
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
+ readonly __wbindgen_start: () => void;
+}
+
+export type SyncInitInput = BufferSource | WebAssembly.Module;
+
+/**
+ * Instantiates the given `module`, which can either be bytes or
+ * a precompiled `WebAssembly.Module`.
+ *
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
+ *
+ * @returns {InitOutput}
+ */
+export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
+
+/**
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
+ * for everything else, calls `WebAssembly.instantiate` directly.
+ *
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
+ *
+ * @returns {Promise<InitOutput>}
+ */
+export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js
new file mode 100644
index 0000000000..7bcbee4f65
--- /dev/null
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder.js
@@ -0,0 +1,412 @@
+/* @ts-self-types="./infisical_rdp_decoder.d.ts" */
+
+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);
+ return obj;
+ }
+ __destroy_into_raw() {
+ const ptr = this.__wbg_ptr;
+ this.__wbg_ptr = 0;
+ DirtyRectFinalization.unregister(this);
+ return ptr;
+ }
+ free() {
+ const ptr = this.__destroy_into_raw();
+ wasm.__wbg_dirtyrect_free(ptr, 0);
+ }
+ /**
+ * @returns {number}
+ */
+ get h() {
+ const ret = wasm.__wbg_get_dirtyrect_h(this.__wbg_ptr);
+ return ret;
+ }
+ /**
+ * @returns {number}
+ */
+ get w() {
+ const ret = wasm.__wbg_get_dirtyrect_w(this.__wbg_ptr);
+ return ret;
+ }
+ /**
+ * @returns {number}
+ */
+ get x() {
+ const ret = wasm.__wbg_get_dirtyrect_x(this.__wbg_ptr);
+ return ret;
+ }
+ /**
+ * @returns {number}
+ */
+ get y() {
+ const ret = wasm.__wbg_get_dirtyrect_y(this.__wbg_ptr);
+ return ret;
+ }
+ /**
+ * @param {number} arg0
+ */
+ set h(arg0) {
+ wasm.__wbg_set_dirtyrect_h(this.__wbg_ptr, arg0);
+ }
+ /**
+ * @param {number} arg0
+ */
+ set w(arg0) {
+ wasm.__wbg_set_dirtyrect_w(this.__wbg_ptr, arg0);
+ }
+ /**
+ * @param {number} arg0
+ */
+ set x(arg0) {
+ wasm.__wbg_set_dirtyrect_x(this.__wbg_ptr, arg0);
+ }
+ /**
+ * @param {number} arg0
+ */
+ set y(arg0) {
+ wasm.__wbg_set_dirtyrect_y(this.__wbg_ptr, arg0);
+ }
+}
+if (Symbol.dispose) DirtyRect.prototype[Symbol.dispose] = DirtyRect.prototype.free;
+
+/**
+ * @enum {0 | 1}
+ */
+export const PduAction = Object.freeze({
+ X224: 0, "0": "X224",
+ FastPath: 1, "1": "FastPath",
+});
+
+/**
+ * A decoder session tied to a specific desktop size. Create one per
+ * replay, feed PDUs in original order, read out the framebuffer + dirty
+ * regions after each call.
+ */
+export class RdpDecoder {
+ __destroy_into_raw() {
+ const ptr = this.__wbg_ptr;
+ this.__wbg_ptr = 0;
+ RdpDecoderFinalization.unregister(this);
+ return ptr;
+ }
+ free() {
+ const ptr = this.__destroy_into_raw();
+ wasm.__wbg_rdpdecoder_free(ptr, 0);
+ }
+ /**
+ * @returns {number}
+ */
+ buffer_len() {
+ const ret = wasm.rdpdecoder_buffer_len(this.__wbg_ptr);
+ return ret >>> 0;
+ }
+ /**
+ * Returns a pointer into the WASM linear memory for the RGBA
+ * framebuffer. JS reads this as a `Uint8Array` of length
+ * `width * height * 4`.
+ * @returns {number}
+ */
+ buffer_ptr() {
+ const ret = wasm.rdpdecoder_buffer_ptr(this.__wbg_ptr);
+ return ret >>> 0;
+ }
+ /**
+ * Returns the i-th dirty rect from the most recent `feed()` call.
+ * @param {number} i
+ * @returns {DirtyRect | undefined}
+ */
+ dirty_rect(i) {
+ const ret = wasm.rdpdecoder_dirty_rect(this.__wbg_ptr, i);
+ return ret === 0 ? undefined : DirtyRect.__wrap(ret);
+ }
+ /**
+ * Feed one captured PDU into the decoder. Returns the number of
+ * dirty rectangles produced; read each via `dirty_rect(i)`.
+ *
+ * `action` is 0 for X.224 and 1 for FastPath; mirrors the tap event
+ * emitted by the gateway.
+ * @param {number} action
+ * @param {Uint8Array} bytes
+ * @returns {number}
+ */
+ feed(action, bytes) {
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
+ const len0 = WASM_VECTOR_LEN;
+ const ret = wasm.rdpdecoder_feed(this.__wbg_ptr, action, ptr0, len0);
+ return ret >>> 0;
+ }
+ /**
+ * @returns {number}
+ */
+ height() {
+ 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.
+ * @param {number} width
+ * @param {number} height
+ */
+ constructor(width, height) {
+ const ret = wasm.rdpdecoder_new(width, height);
+ this.__wbg_ptr = ret >>> 0;
+ RdpDecoderFinalization.register(this, this.__wbg_ptr, this);
+ return this;
+ }
+ /**
+ * Returns the row stride in bytes. Usually `width * 4` but IronRDP
+ * may align differently.
+ * @returns {number}
+ */
+ stride() {
+ const ret = wasm.rdpdecoder_stride(this.__wbg_ptr);
+ return ret >>> 0;
+ }
+ /**
+ * @returns {number}
+ */
+ width() {
+ const ret = wasm.rdpdecoder_width(this.__wbg_ptr);
+ return ret;
+ }
+}
+if (Symbol.dispose) RdpDecoder.prototype[Symbol.dispose] = RdpDecoder.prototype.free;
+
+export function start() {
+ wasm.start();
+}
+function __wbg_get_imports() {
+ const import0 = {
+ __proto__: null,
+ __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) {
+ let deferred0_0;
+ let deferred0_1;
+ try {
+ deferred0_0 = arg0;
+ deferred0_1 = arg1;
+ console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7));
+ } finally {
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
+ }
+ },
+ __wbg_log_ce2c4456b290c5e7: function(arg0, arg1) {
+ let deferred0_0;
+ let deferred0_1;
+ try {
+ deferred0_0 = arg0;
+ deferred0_1 = arg1;
+ console.log(getStringFromWasm0(arg0, arg1));
+ } finally {
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
+ }
+ },
+ __wbg_mark_b4d943f3bc2d2404: function(arg0, arg1) {
+ performance.mark(getStringFromWasm0(arg0, arg1));
+ },
+ __wbg_measure_84362959e621a2c1: function() { return handleError(function (arg0, arg1, arg2, arg3) {
+ let deferred0_0;
+ let deferred0_1;
+ let deferred1_0;
+ let deferred1_1;
+ try {
+ deferred0_0 = arg0;
+ deferred0_1 = arg1;
+ deferred1_0 = arg2;
+ deferred1_1 = arg3;
+ performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
+ } finally {
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
+ }
+ }, arguments); },
+ __wbindgen_init_externref_table: function() {
+ const table = wasm.__wbindgen_externrefs;
+ const offset = table.grow(4);
+ table.set(0, undefined);
+ table.set(offset + 0, undefined);
+ table.set(offset + 1, null);
+ table.set(offset + 2, true);
+ table.set(offset + 3, false);
+ },
+ };
+ return {
+ __proto__: null,
+ "./infisical_rdp_decoder_bg.js": import0,
+ };
+}
+
+const DirtyRectFinalization = (typeof FinalizationRegistry === 'undefined')
+ ? { register: () => {}, unregister: () => {} }
+ : 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 >>> 0, 1));
+
+function addToExternrefTable0(obj) {
+ const idx = wasm.__externref_table_alloc();
+ wasm.__wbindgen_externrefs.set(idx, obj);
+ return idx;
+}
+
+function getStringFromWasm0(ptr, len) {
+ ptr = ptr >>> 0;
+ return decodeText(ptr, len);
+}
+
+let cachedUint8ArrayMemory0 = null;
+function getUint8ArrayMemory0() {
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
+ }
+ return cachedUint8ArrayMemory0;
+}
+
+function handleError(f, args) {
+ try {
+ return f.apply(this, args);
+ } catch (e) {
+ const idx = addToExternrefTable0(e);
+ wasm.__wbindgen_exn_store(idx);
+ }
+}
+
+function passArray8ToWasm0(arg, malloc) {
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
+ getUint8ArrayMemory0().set(arg, ptr / 1);
+ WASM_VECTOR_LEN = arg.length;
+ return ptr;
+}
+
+let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
+cachedTextDecoder.decode();
+const MAX_SAFARI_DECODE_BYTES = 2146435072;
+let numBytesDecoded = 0;
+function decodeText(ptr, len) {
+ numBytesDecoded += len;
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
+ cachedTextDecoder.decode();
+ numBytesDecoded = len;
+ }
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
+}
+
+let WASM_VECTOR_LEN = 0;
+
+let wasmModule, wasm;
+function __wbg_finalize_init(instance, module) {
+ wasm = instance.exports;
+ wasmModule = module;
+ cachedUint8ArrayMemory0 = null;
+ wasm.__wbindgen_start();
+ return wasm;
+}
+
+async function __wbg_load(module, imports) {
+ if (typeof Response === 'function' && module instanceof Response) {
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
+ try {
+ return await WebAssembly.instantiateStreaming(module, imports);
+ } catch (e) {
+ const validResponse = module.ok && expectedResponseType(module.type);
+
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
+
+ } else { throw e; }
+ }
+ }
+
+ const bytes = await module.arrayBuffer();
+ return await WebAssembly.instantiate(bytes, imports);
+ } else {
+ const instance = await WebAssembly.instantiate(module, imports);
+
+ if (instance instanceof WebAssembly.Instance) {
+ return { instance, module };
+ } else {
+ return instance;
+ }
+ }
+
+ function expectedResponseType(type) {
+ switch (type) {
+ case 'basic': case 'cors': case 'default': return true;
+ }
+ return false;
+ }
+}
+
+function initSync(module) {
+ if (wasm !== undefined) return wasm;
+
+
+ if (module !== undefined) {
+ if (Object.getPrototypeOf(module) === Object.prototype) {
+ ({module} = module)
+ } else {
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
+ }
+ }
+
+ const imports = __wbg_get_imports();
+ if (!(module instanceof WebAssembly.Module)) {
+ module = new WebAssembly.Module(module);
+ }
+ const instance = new WebAssembly.Instance(module, imports);
+ return __wbg_finalize_init(instance, module);
+}
+
+async function __wbg_init(module_or_path) {
+ if (wasm !== undefined) return wasm;
+
+
+ if (module_or_path !== undefined) {
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
+ ({module_or_path} = module_or_path)
+ } else {
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
+ }
+ }
+
+ if (module_or_path === undefined) {
+ module_or_path = new URL('infisical_rdp_decoder_bg.wasm', import.meta.url);
+ }
+ const imports = __wbg_get_imports();
+
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
+ module_or_path = fetch(module_or_path);
+ }
+
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
+
+ return __wbg_finalize_init(instance, module);
+}
+
+export { initSync, __wbg_init as default };
diff --git a/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm
new file mode 100644
index 0000000000..c4399f6d8f
Binary files /dev/null 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
new file mode 100644
index 0000000000..e91b5df952
--- /dev/null
+++ b/frontend/src/lib/ironrdp-decoder/infisical_rdp_decoder_bg.wasm.d.ts
@@ -0,0 +1,29 @@
+/* tslint:disable */
+/* eslint-disable */
+export const memory: WebAssembly.Memory;
+export const __wbg_dirtyrect_free: (a: number, b: number) => void;
+export const __wbg_get_dirtyrect_h: (a: number) => number;
+export const __wbg_get_dirtyrect_w: (a: number) => number;
+export const __wbg_get_dirtyrect_x: (a: number) => number;
+export const __wbg_get_dirtyrect_y: (a: number) => number;
+export const __wbg_rdpdecoder_free: (a: number, b: number) => void;
+export const __wbg_set_dirtyrect_h: (a: number, b: number) => void;
+export const __wbg_set_dirtyrect_w: (a: number, b: number) => void;
+export const __wbg_set_dirtyrect_x: (a: number, b: number) => void;
+export const __wbg_set_dirtyrect_y: (a: number, b: number) => void;
+export const rdpdecoder_buffer_len: (a: number) => number;
+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;
+export const start: () => void;
+export const __wbindgen_free: (a: number, b: number, c: number) => void;
+export const __wbindgen_exn_store: (a: number) => void;
+export const __externref_table_alloc: () => number;
+export const __wbindgen_externrefs: WebAssembly.Table;
+export const __wbindgen_malloc: (a: number, b: number) => number;
+export const __wbindgen_start: () => void;
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx
index d470c39889..5593b1185e 100644
--- a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx
@@ -1,3 +1,4 @@
+import { lazy, Suspense } from "react";
import { ExternalLinkIcon, Loader2Icon } from "lucide-react";
import { Button } from "@app/components/v3";
@@ -16,6 +17,10 @@ import { CommandLogView } from "./CommandLogView";
import { HttpEventView } from "./HttpEventView";
import { TerminalEventView } from "./TerminalEventView";
+// The IronRDP decoder WASM is ~MB-scale; load it only when an RDP session is
+// actually being viewed. The dynamic import keeps it out of the main bundle.
+const RdpReplayView = lazy(() => import("./RdpReplayView/RdpReplayView"));
+
type Props = {
session: TPamSession;
scrollToLogIndex?: number;
@@ -45,6 +50,7 @@ export const PamSessionLogsSection = ({ session, scrollToLogIndex }: Props) => {
session.resourceType === PamResourceType.Redis;
const isHttpSession = session.resourceType === PamResourceType.Kubernetes;
const isAwsIamSession = session.resourceType === PamResourceType.AwsIam;
+ const isRdpSession = session.resourceType === PamResourceType.Windows;
const hasLogs = logs.length > 0;
return (
@@ -73,6 +79,20 @@ export const PamSessionLogsSection = ({ session, scrollToLogIndex }: Props) => {
)}
{isSSHSession && hasLogs && <TerminalEventView events={logs as TTerminalEvent[]} />}
{isHttpSession && hasLogs && <HttpEventView events={logs as THttpEvent[]} />}
+ {isRdpSession && hasLogs && (
+ <Suspense
+ fallback={
+ <div className="flex grow items-center justify-center">
+ <div className="flex items-center gap-2 text-sm text-muted">
+ <Loader2Icon className="size-4 animate-spin" />
+ <span>Loading RDP replay player...</span>
+ </div>
+ </div>
+ }
+ >
+ <RdpReplayView events={logs as TTerminalEvent[]} />
+ </Suspense>
+ )}
{isAwsIamSession && (
<div className="flex grow items-center justify-center text-muted">
<div className="text-center">
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx
new file mode 100644
index 0000000000..e3e56a005b
--- /dev/null
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/RdpReplayView.tsx
@@ -0,0 +1,140 @@
+import { useEffect, useMemo, useRef, useState } from "react";
+import { PauseIcon, PlayIcon, RotateCcwIcon } from "lucide-react";
+
+import { Button } from "@app/components/v3";
+import { TTerminalEvent } from "@app/hooks/api/pam";
+
+import { parseRdpLogEntry, RdpEvent, RdpReplayPlayer } from "./rdpReplayPlayer";
+
+const CANVAS_W = 1920;
+const CANVAS_H = 1080;
+
+const formatMs = (ms: number) => {
+ const s = Math.floor(ms / 1000);
+ const m = Math.floor(s / 60);
+ const r = s % 60;
+ return `${m.toString().padStart(2, "0")}:${r.toString().padStart(2, "0")}`;
+};
+
+type Props = {
+ events: TTerminalEvent[];
+};
+
+export const RdpReplayView = ({ events }: Props) => {
+ const canvasRef = useRef<HTMLCanvasElement | null>(null);
+ const playerRef = useRef<RdpReplayPlayer | null>(null);
+ const [isPlaying, setIsPlaying] = useState(false);
+ const [currentMs, setCurrentMs] = useState(0);
+ const [error, setError] = useState<string | null>(null);
+
+ const rdpEvents = useMemo<RdpEvent[]>(() => {
+ const parsed: RdpEvent[] = [];
+ for (const e of events) {
+ const ev = parseRdpLogEntry(e);
+ if (ev) parsed.push(ev);
+ }
+ parsed.sort((a, b) => a.elapsedMs - b.elapsedMs);
+ return parsed;
+ }, [events]);
+
+ const totalMs = rdpEvents.length ? rdpEvents[rdpEvents.length - 1].elapsedMs : 0;
+
+ useEffect(() => {
+ let cancelled = false;
+ const canvas = canvasRef.current;
+ if (!canvas || rdpEvents.length === 0) return undefined;
+
+ RdpReplayPlayer.create(rdpEvents, canvas, {
+ onTick: (ms) => setCurrentMs(ms),
+ onEnded: () => setIsPlaying(false)
+ })
+ .then((player) => {
+ if (cancelled) {
+ player.dispose();
+ return;
+ }
+ playerRef.current = player;
+ })
+ .catch((e: unknown) => {
+ setError(e instanceof Error ? e.message : "Failed to initialize RDP replay player");
+ });
+
+ return () => {
+ cancelled = true;
+ if (playerRef.current) {
+ playerRef.current.dispose();
+ playerRef.current = null;
+ }
+ };
+ }, [rdpEvents]);
+
+ const onPlayPause = () => {
+ const p = playerRef.current;
+ if (!p) return;
+ if (p.isPlaying) {
+ p.pause();
+ setIsPlaying(false);
+ } else {
+ p.play();
+ setIsPlaying(true);
+ }
+ };
+
+ const onRestart = () => {
+ const p = playerRef.current;
+ if (!p) return;
+ p.restart();
+ setIsPlaying(false);
+ setCurrentMs(0);
+ };
+
+ if (error) {
+ return (
+ <div className="flex grow items-center justify-center text-sm text-danger">
+ RDP replay failed to load: {error}
+ </div>
+ );
+ }
+
+ if (rdpEvents.length === 0) {
+ return (
+ <div className="flex grow items-center justify-center text-sm text-muted">
+ No RDP events to replay yet.
+ </div>
+ );
+ }
+
+ return (
+ <div className="flex flex-col gap-3">
+ <div className="flex items-center gap-2">
+ <Button variant="outline" size="xs" onClick={onPlayPause}>
+ {isPlaying ? (
+ <PauseIcon className="mr-1.5 size-3.5" />
+ ) : (
+ <PlayIcon className="mr-1.5 size-3.5" />
+ )}
+ {isPlaying ? "Pause" : "Play"}
+ </Button>
+ <Button variant="outline" size="xs" onClick={onRestart}>
+ <RotateCcwIcon className="mr-1.5 size-3.5" />
+ Restart
+ </Button>
+ <span className="ml-2 font-mono text-xs text-muted">
+ {formatMs(currentMs)} / {formatMs(totalMs)}
+ </span>
+ </div>
+ <div className="overflow-hidden rounded-md border border-border bg-black">
+ <canvas
+ ref={canvasRef}
+ width={CANVAS_W}
+ height={CANVAS_H}
+ className="h-auto w-full"
+ aria-label="RDP session replay"
+ />
+ </div>
+ </div>
+ );
+};
+
+// Default export for React.lazy convenience.
+export default RdpReplayView;
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/index.ts b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/index.ts
new file mode 100644
index 0000000000..d868ea6193
--- /dev/null
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/index.ts
@@ -0,0 +1 @@
+export { RdpReplayView } from "./RdpReplayView";
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts
new file mode 100644
index 0000000000..8eb604a975
--- /dev/null
+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/RdpReplayView/rdpReplayPlayer.ts
@@ -0,0 +1,270 @@
+/**
+ * RDP replay player.
+ *
+ * Consumes RDP-tagged events drained from the gateway tap (see
+ * cli packages/pam/handlers/rdp/proxy.go) and drives a canvas at real
+ * timings. Frame decoding is delegated to the WASM module at
+ * @app/lib/ironrdp-decoder, which wraps IronRDP's ActiveStage + DecodedImage.
+ *
+ * Control surface is deliberately minimal: play / pause / restart + tick
+ * callback. Seek is not supported (frames are deltas; real seek would need
+ * keyframes or a reset-then-fast-forward pass).
+ */
+
+import wasmInit, { InitOutput, RdpDecoder } from "@app/lib/ironrdp-decoder/infisical_rdp_decoder";
+
+export type RdpEventType = "keyboard" | "unicode" | "mouse" | "target_frame";
+
+export type RdpEvent = {
+ type: RdpEventType;
+ elapsedMs: number;
+ // keyboard
+ scancode?: number;
+ // unicode
+ codePoint?: number;
+ // mouse
+ x?: number;
+ y?: number;
+ wheelDelta?: number;
+ // common
+ flags?: number;
+ // target_frame
+ action?: "x224" | "fastpath";
+ payload?: Uint8Array;
+};
+
+type PlayerCallbacks = {
+ onTick: (currentMs: number) => void;
+ onEnded: () => void;
+};
+
+let wasmReady: Promise<InitOutput> | null = null;
+const ensureWasm = (): Promise<InitOutput> => {
+ if (!wasmReady) wasmReady = wasmInit();
+ return wasmReady;
+};
+
+export class RdpReplayPlayer {
+ private events: RdpEvent[];
+
+ private canvas: HTMLCanvasElement;
+
+ private ctx: CanvasRenderingContext2D;
+
+ private callbacks: PlayerCallbacks;
+
+ private decoder: RdpDecoder;
+
+ private wasm: InitOutput;
+
+ private index = 0;
+
+ private clockMs = 0;
+
+ private wallStart: number | null = null;
+
+ private raf: number | null = null;
+
+ private constructor(
+ events: RdpEvent[],
+ canvas: HTMLCanvasElement,
+ callbacks: PlayerCallbacks,
+ decoder: RdpDecoder,
+ wasm: InitOutput
+ ) {
+ this.events = events;
+ this.canvas = canvas;
+ const c = canvas.getContext("2d");
+ if (!c) throw new Error("2d context unavailable");
+ this.ctx = c;
+ this.callbacks = callbacks;
+ this.decoder = decoder;
+ this.wasm = wasm;
+ }
+
+ static async create(
+ events: RdpEvent[],
+ canvas: HTMLCanvasElement,
+ callbacks: PlayerCallbacks
+ ): Promise<RdpReplayPlayer> {
+ const wasm = await ensureWasm();
+ const decoder = new RdpDecoder(canvas.width, canvas.height);
+ return new RdpReplayPlayer(events, canvas, callbacks, decoder, wasm);
+ }
+
+ get totalMs(): number {
+ const last = this.events[this.events.length - 1];
+ return last ? last.elapsedMs : 0;
+ }
+
+ get currentMs(): number {
+ return this.clockMs;
+ }
+
+ get isPlaying(): boolean {
+ return this.raf !== null;
+ }
+
+ play = () => {
+ if (this.raf !== null) return;
+ if (this.index >= this.events.length) return;
+ this.wallStart = performance.now() - this.clockMs;
+ this.tick();
+ };
+
+ pause = () => {
+ if (this.raf === null) return;
+ cancelAnimationFrame(this.raf);
+ this.raf = null;
+ this.wallStart = null;
+ };
+
+ restart = () => {
+ this.pause();
+ this.index = 0;
+ this.clockMs = 0;
+ // A restart needs a fresh decoder state -- frames are deltas, so
+ // replaying from T=0 against a non-fresh decoder would reuse already
+ // applied delta state on top of the still-present pixels.
+ this.decoder.free();
+ this.decoder = new RdpDecoder(this.canvas.width, this.canvas.height);
+ this.ctx.fillStyle = "#000";
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
+ this.callbacks.onTick(0);
+ };
+
+ dispose = () => {
+ this.pause();
+ try {
+ this.decoder.free();
+ } catch {
+ /* ignore */
+ }
+ };
+
+ private tick = () => {
+ if (this.wallStart === null) return;
+ const now = performance.now();
+ this.clockMs = now - this.wallStart;
+
+ while (this.index < this.events.length && this.events[this.index].elapsedMs <= this.clockMs) {
+ this.apply(this.events[this.index]);
+ this.index += 1;
+ }
+
+ this.callbacks.onTick(this.clockMs);
+
+ if (this.index >= this.events.length) {
+ this.raf = null;
+ this.wallStart = null;
+ this.callbacks.onEnded();
+ return;
+ }
+
+ this.raf = requestAnimationFrame(this.tick);
+ };
+
+ private apply = (ev: RdpEvent) => {
+ switch (ev.type) {
+ case "target_frame":
+ if (ev.payload) this.feedFrame(ev);
+ break;
+ case "mouse":
+ if (ev.x !== undefined && ev.y !== undefined) {
+ // Drive the server-rendered pointer sprite from recorded mouse
+ // input. Windows only sends PositionPointer PDUs for server-
+ // initiated cursor moves; normal movement is resolved client-side,
+ // so replay has to replay it the same way.
+ const count = this.decoder.move_pointer(ev.x, ev.y);
+ if (count > 0) this.blitDirtyRects(count);
+ }
+ break;
+ case "keyboard":
+ case "unicode":
+ // V1 renders frames only; recorded input is in the event stream
+ // but not surfaced in the player UI.
+ break;
+ default:
+ break;
+ }
+ };
+
+ private blitDirtyRects = (count: number) => {
+ // Construct a view over the WASM-side framebuffer. We re-create the view
+ // each call because wasm-bindgen can reallocate linear memory on growth,
+ // which would invalidate any cached pointer/length pair.
+ const ptr = this.decoder.buffer_ptr();
+ const len = this.decoder.buffer_len();
+ const width = this.decoder.width();
+ const height = this.decoder.height();
+ const fb = new Uint8ClampedArray(this.wasm.memory.buffer, ptr, len);
+ const fullImage = new ImageData(fb, width, height);
+
+ for (let i = 0; i < count; i += 1) {
+ const r = this.decoder.dirty_rect(i);
+ if (!r) continue;
+ // 8-arg putImageData clips to (dx, dy, dw, dh) rect of the source.
+ this.ctx.putImageData(fullImage, 0, 0, r.x, r.y, r.w, r.h);
+ r.free();
+ }
+ };
+
+ private feedFrame = (ev: RdpEvent) => {
+ if (!ev.payload) return;
+ const action = ev.action === "x224" ? 0 : 1;
+ let count: number;
+ try {
+ count = this.decoder.feed(action, ev.payload);
+ } catch {
+ return;
+ }
+ if (count === 0) return;
+ this.blitDirtyRects(count);
+ };
+}
+
+const decodeBase64ToUint8 = (b64: string): Uint8Array => {
+ const bin = atob(b64);
+ const out = new Uint8Array(bin.length);
+ for (let i = 0; i < bin.length; i += 1) out[i] = bin.charCodeAt(i);
+ return out;
+};
+
+/**
+ * Parse a TerminalEvent (channelType "rdp") into an RdpEvent, or null if
+ * the entry isn't a recognized RDP envelope. The gateway emits each event
+ * as base64-encoded JSON inside `data`; see the rdp*Envelope types in cli
+ * packages/pam/handlers/rdp/proxy.go for the wire shape.
+ */
+export const parseRdpLogEntry = (entry: unknown): RdpEvent | null => {
+ const e = entry as { data?: string; channelType?: string };
+ if (e?.channelType !== "rdp" || typeof e.data !== "string") return null;
+ let rec: Record<string, unknown>;
+ try {
+ rec = JSON.parse(atob(e.data));
+ } catch {
+ return null;
+ }
+ const type = rec.type as RdpEventType | undefined;
+ if (!type) return null;
+ const elapsedMs = Number(rec.elapsedNs ?? 0) / 1e6;
+
+ const ev: RdpEvent = { type, elapsedMs };
+ if (type === "keyboard") {
+ ev.scancode = Number(rec.scancode ?? 0);
+ ev.flags = Number(rec.flags ?? 0);
+ } else if (type === "unicode") {
+ ev.codePoint = Number(rec.codePoint ?? 0);
+ ev.flags = Number(rec.flags ?? 0);
+ } else if (type === "mouse") {
+ ev.x = Number(rec.x ?? 0);
+ ev.y = Number(rec.y ?? 0);
+ ev.flags = Number(rec.flags ?? 0);
+ ev.wheelDelta = Number(rec.wheelDelta ?? 0);
+ } else if (type === "target_frame") {
+ ev.action = rec.action as "x224" | "fastpath";
+ const payloadB64 = rec.payload as string | undefined;
+ if (payloadB64) ev.payload = decodeBase64ToUint8(payloadB64);
+ }
+ return ev;
+};