Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/bots/PerplexityBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Bot from "@/bots/Bot";
import axios from "axios";
import { v4 as uuidv4 } from "uuid";
import WebSocketAsPromised from "websocket-as-promised";
import i18n from "@/i18n";

export default class PerplexityBot extends Bot {
static _brandId = "perplexity";
Expand Down Expand Up @@ -174,7 +175,7 @@ export default class PerplexityBot extends Bot {
return new Promise((resolve, reject) => {
try {
const wsp = new WebSocketAsPromised(
`wss://www.perplexity.ai/socket.io/?EIO=4&transport=polling&t=${this.t}&sid=${sid}`,
`wss://www.perplexity.ai/socket.io/?EIO=4&transport=websocket&t=${this.t}&sid=${sid}`,
{
packMessage: (data) => {
return `42${this.seq++}${JSON.stringify(data)}`;
Expand Down Expand Up @@ -309,7 +310,11 @@ export default class PerplexityBot extends Bot {
wsp.onError.addListener((event) => {
wsp.removeAllListeners();
wsp.close();
reject(event);
reject(
i18n.global.t("error.failedConnectUrl", {
url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The WebSocket URL contains sensitive query parameters, including the session ID (sid) and a timestamp (t). Displaying the full URL in the error message could lead to accidental exposure of these tokens if a user shares a screenshot of the error. It is safer to strip the query parameters and only display the base URL in the UI.

Suggested change
url: event.target?.url ?? "wss://www.perplexity.ai/socket.io/",
url: event.target?.url?.split("?")[0] ?? "wss://www.perplexity.ai/socket.io/",

}),
);
});

wsp.onClose.addListener(() => {
Expand Down