'403 Forbidden when connecting to pterodactyl websocket
I was wondering if someone could help me. I'm making a program that connects to pterodactyl's websocket but every time I try and connect it gives me a 403 - Forbidden. I've been researching this error for a few hours and I can't seem to find a fix. I'm using NodeJS v17.
Here's the code:
const embed = require('../../Configs/embed.json');
let PterodactylUser = require('../../Structures/Panel/PterodactylUser.js');
const SQL = require('../../Structures/Panel/SQL/SQL.js');
const mainConfig = require('../../Configs/config.json');
const WebSocket = require("ws");
module.exports = {
name: 'Output',
description: 'Sends live console output for the selected server!',
category: 'Servers',
enabled: true,
options: [
{
name: "start",
type: "SUB_COMMAND",
description: "Starts sending console output for the server.",
options: [
{
name: "id",
type: "STRING",
description: "The ID of the server to link!",
required: true
},
{
name: "channel",
type: "CHANNEL",
channelTypes: ["GUILD_TEXT", "GUILD_NEWS"],
description: "The channel to link if not set uses current channel!"
}
]
}
],
needsAPIKey: true,
async execute(client, Discord, mainConfig, interaction, args) {
const user = interaction.user || interaction.author;
const channel = args.getChannel('channel') ? args.getChannel('channel') : interaction.channel;
const serverId = args.getString('id');
const mysql = new SQL();
let apiKey = await mysql.getApiKey(user.id, interaction.guild.id);
let res = await new PterodactylUser(apiKey).getWebsocket(serverId);
const { socket, token } = res.data;
const ws = new WebSocket(socket);
}
}
Solution 1:[1]
I had similar problem caused by misconfigured panel access settings. You need to edit /etc/pterodactyl/config.yml
Citing the creator of PteroJS library from my issue:
The origin of the websocket request is not whitelisted. If you have access to Wings for the node you're using then set
allowed_originsin "config.yml" to this:
allowed_origins:
- "*"
Otherwise, contact your panel administrator about it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dmitry Antonov |
