From 300363d8aa1c2314641d374a4a5a7facc5b6b7aa Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:53:29 -0500 Subject: map ipv6-mapped ipv4 IPs back to ipv4 before checking them against configured CIDR --- src/slskd/Relay/API/Hubs/RelayHub.cs | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/slskd/Relay/API/Hubs/RelayHub.cs b/src/slskd/Relay/API/Hubs/RelayHub.cs index 53e2830f..8430164c 100644 --- a/src/slskd/Relay/API/Hubs/RelayHub.cs +++ b/src/slskd/Relay/API/Hubs/RelayHub.cs @@ -109,7 +109,6 @@ namespace slskd.Relay private IOptionsMonitor OptionsMonitor { get; } private OptionsAtStartup OptionsAtStartup { get; } private RelayMode OperationMode => OptionsAtStartup.Relay.Mode.ToEnum(); - private IPAddress RemoteIpAddress => Context.Features.Get().RemoteIpAddress; /// /// Executed when a new connection is established. @@ -119,13 +118,13 @@ namespace slskd.Relay { if (!OptionsAtStartup.Relay.Enabled || !new[] { RelayMode.Controller, RelayMode.Debug }.Contains(OperationMode)) { - Log.Debug("Agent connection {Id} from {IP} aborted; Relay is not enabled, or is not in Controller mode", Context.ConnectionId, RemoteIpAddress); + Log.Debug("Agent connection {Id} from {IP} aborted; Relay is not enabled, or is not in Controller mode", Context.ConnectionId, GetRemoteIPAddress()); Context.Abort(); } var token = Relay.GenerateAuthenticationChallengeToken(Context.ConnectionId); - Log.Information("Agent connection {Id} from {IP} established. Sending authentication challenge {Token}...", Context.ConnectionId, RemoteIpAddress, token); + Log.Information("Agent connection {Id} from {IP} established. Sending authentication challenge {Token}...", Context.ConnectionId, GetRemoteIPAddress(), token); await Clients.Caller.Challenge(token); } @@ -138,7 +137,7 @@ namespace slskd.Relay { if (Relay.TryDeregisterAgent(Context.ConnectionId, out var record)) { - Log.Warning("Agent {Agent} (connection {Id}) from {IP} disconnected", record.Agent.Name, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent {Agent} (connection {Id}) from {IP} disconnected", record.Agent.Name, Context.ConnectionId, GetRemoteIPAddress()); Relay.TryDeregisterAgent(record.Agent.Name, out _); } @@ -170,23 +169,25 @@ namespace slskd.Relay return false; } + var remoteIP = GetRemoteIPAddress(); + if (!TryGetAgentConfig(agent, out var agentOptions)) { - Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Unauthorized login attempt from unknown Agent {Agent} (connection {Id}) from {IP}", agent, Context.ConnectionId, remoteIP); throw new UnauthorizedAccessException(); } if (!agentOptions.Cidr.Split(',') .Select(cidr => IPAddressRange.Parse(cidr)) - .Any(range => range.Contains(RemoteIpAddress))) + .Any(range => range.Contains(remoteIP))) { - Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}); remote IP address {IP} is not within the configured range {CIDR}", agent, Context.ConnectionId, RemoteIpAddress, agentOptions.Cidr); + Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}); remote IP address {IP} is not within the configured range {CIDR}", agent, Context.ConnectionId, remoteIP, agentOptions.Cidr); throw new UnauthorizedAccessException(); } if (!Relay.TryValidateAuthenticationCredential(Context.ConnectionId, agent, challengeResponse)) { - Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}) from {IP}; authentication failed", agent, Context.ConnectionId, RemoteIpAddress); + Log.Warning("Unauthorized login attempt by Agent {Agent} (connection {Id}) from {IP}; authentication failed", agent, Context.ConnectionId, remoteIP); Relay.TryDeregisterAgent(Context.ConnectionId, out var _); // just in case! throw new UnauthorizedAccessException(); } @@ -208,12 +209,12 @@ namespace slskd.Relay if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { // this can happen if the agent attempts to upload before logging in - Log.Information("Agent connection {Id} from {IP} requested a share upload token, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Information("Agent connection {Id} from {IP} requested a share upload token, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } var token = Relay.GenerateShareUploadToken(record.Agent.Name); - Log.Information("Agent {Agent} (connection {Id}) from {IP} requested share upload token {Token}", record.Agent.Name, record.ConnectionId, RemoteIpAddress, token); + Log.Information("Agent {Agent} (connection {Id}) from {IP} requested share upload token {Token}", record.Agent.Name, record.ConnectionId, GetRemoteIPAddress(), token); return token; } @@ -227,11 +228,11 @@ namespace slskd.Relay { if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { - Log.Warning("Agent connection {Id} from {IP} attempted to report a failed upload, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent connection {Id} from {IP} attempted to report a failed upload, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } - Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", record.Agent, Context.ConnectionId, RemoteIpAddress, id, exception.Message); + Log.Warning("Agent {Agent} (connection {ConnectionId}) from {IP} reported upload failure for {Id}: {Message}", record.Agent, Context.ConnectionId, GetRemoteIPAddress(), id, exception.Message); Relay.NotifyFileStreamException(record.Agent.Name, id, exception); } @@ -247,13 +248,26 @@ namespace slskd.Relay { if (!Relay.TryGetAgentRegistration(Context.ConnectionId, out var record)) { - Log.Warning("Agent connection {Id} from {IP} attempted to return file information, but is not registered.", Context.ConnectionId, RemoteIpAddress); + Log.Warning("Agent connection {Id} from {IP} attempted to return file information, but is not registered.", Context.ConnectionId, GetRemoteIPAddress()); throw new UnauthorizedAccessException(); } - Log.Information("Agent {Agent} (connection {ConnectionId}) from {IP} returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, RemoteIpAddress, id, exists, length); + Log.Information("Agent {Agent} (connection {ConnectionId}) from {IP} returned file info for {Id}; exists: {Exists}, length: {Length}", record.Agent.Name, Context.ConnectionId, GetRemoteIPAddress(), id, exists, length); Relay.HandleFileInfoResponse(record.Agent.Name, id, (exists, length)); } + + private IPAddress GetRemoteIPAddress() + { + var ip = Context.Features.Get().RemoteIpAddress; + + // looks like '::ffff:127.0.0.1'; not compatible with CIDR.Contains(), so convert it back to IPv4 + if (ip.IsIPv4MappedToIPv6) + { + ip = ip.MapToIPv4(); + } + + return ip; + } } } \ No newline at end of file -- cgit v1.2.3 From 38c821d0eb5f22c30ca9be8f24e452f5ce0b83ca Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:53:51 -0500 Subject: don't log share upload success on failure --- src/slskd/Relay/RelayClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index 6fb2f360..de6edcf7 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -532,6 +532,8 @@ namespace slskd.Relay Log.Information("Uploading shares..."); await UploadSharesAsync(); + + Log.Information("Shares uploaded. Ready to relay files."); } catch (Exception ex) { @@ -542,8 +544,6 @@ namespace slskd.Relay await StopAsync(); _ = StartAsync(); } - - Log.Information("Shares uploaded. Ready to relay files."); } private Task HubConnection_Reconnecting(Exception arg) -- cgit v1.2.3 From 3b9d14bf6f128d771149f6589f345967aea5dc4d Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Apr 2026 18:54:10 -0500 Subject: don't try to catch typed exceptions from hub invocations --- src/slskd/Relay/RelayClient.cs | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src') diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs index de6edcf7..9aec7b00 100644 --- a/src/slskd/Relay/RelayClient.cs +++ b/src/slskd/Relay/RelayClient.cs @@ -362,11 +362,6 @@ namespace slskd.Relay LoggedInTaskCompletionSource.TrySetResult(); } - catch (UnauthorizedAccessException) - { - await HubConnection.StopAsync(); - Log.Error("Relay controller authentication failed. Check configuration."); - } catch (Exception ex) { Log.Error(ex, "Failed to handle authentication challenge: {Message}", ex.Message); -- cgit v1.2.3 From acbfa366baa274c04499e835f469168477e387af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Apr 2026 03:42:48 +0000 Subject: Bump follow-redirects from 1.15.11 to 1.16.0 in /src/web Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.11 to 1.16.0. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.11...v1.16.0) --- updated-dependencies: - dependency-name: follow-redirects dependency-version: 1.16.0 dependency-type: indirect ... Signed-off-by: dependabot[bot] --- src/web/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web/package-lock.json b/src/web/package-lock.json index f309d9af..22d9c714 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -10906,9 +10906,9 @@ "license": "ISC" }, "node_modules/follow-redirects": { - "version": "1.15.11", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", - "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", "funding": [ { "type": "individual", -- cgit v1.2.3 From 8ddc38f768e18a7c72a3b904446fdb01835092bd Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:04:14 -0500 Subject: disable weird rule --- src/web/.eslintrc.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/web/.eslintrc.js b/src/web/.eslintrc.js index 0c36e3ed..81d1001c 100644 --- a/src/web/.eslintrc.js +++ b/src/web/.eslintrc.js @@ -5,6 +5,7 @@ const overrides = { 'no-eq-null': 'off', // noisy 'react/forbid-component-props': 'off', // noisy 'react/prop-types': 'off', // noisy + 'canonical/sort-keys': 'off', // noisy 'unicorn/no-array-reduce': 'off', // noisy }; -- cgit v1.2.3 From 8a22018aefbb89d1b74788a0d6bda97b0d8da6b0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:05:03 -0500 Subject: use state for message input instead of dom ref (causing delay in updates) --- src/web/src/components/Chat/Chat.jsx | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 23619bd1..9e3605b8 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -20,6 +20,7 @@ const initialState = { conversations: {}, interval: undefined, loading: false, + message: '', }; class Chat extends Component { @@ -106,21 +107,15 @@ class Chat extends Component { await chat.acknowledge({ username }); }; - sendMessage = async (username, message) => { - if (!username || !message || username === '') return; - await chat.send({ message, username }); - }; - sendReply = async () => { - const { active } = this.state; - const message = this.messageRef.current.value; + const { active, message } = this.state; if (!this.validInput()) { return; } - await this.sendMessage(active, message); - this.messageRef.current.value = ''; + await chat.send({ username: active, message }); + this.setState({ message: '' }); // force a refresh to append the message // we could probably do this in the browser but we can be lazy @@ -129,12 +124,7 @@ class Chat extends Component { validInput = () => (this.state.active || '').length > 0 && - ( - (this.messageRef && - this.messageRef.current && - this.messageRef.current.value) || - '' - ).length > 0; + (this.state.message || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -294,7 +284,7 @@ class Chat extends Component { name="send" /> ), - onClick: this.sendMessage, + onClick: this.sendReply, }} fluid input={ @@ -302,7 +292,11 @@ class Chat extends Component { autoComplete="off" data-lpignore="true" id="chat-message-input" + onChange={(event) => + this.setState({ message: event.target.value }) + } type="text" + value={this.state.message} /> } onKeyUp={(event) => -- cgit v1.2.3 From e70664167d1766b63a12fa1833b452a217e8b6cc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 10:05:18 -0500 Subject: focus input when conversation is loaded --- src/web/src/components/Chat/Chat.jsx | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 9e3605b8..0a080466 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -170,6 +170,12 @@ class Chat extends Component { } catch { // no-op } + + try { + this.messageRef.current.focus(); + } catch { + // no-op + } }, ); }, -- cgit v1.2.3 From 402b4d7509c582bd2d93e73a33778068e660259e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 11:09:33 -0500 Subject: use state instead of dom ref for rooms --- src/web/src/components/Rooms/Rooms.jsx | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 0f2e4382..d30828eb 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -32,6 +32,7 @@ const initialState = { }, joined: [], loading: false, + message: '', room: { messages: [], users: [], @@ -131,6 +132,12 @@ class Rooms extends Component { } catch { // no-op } + + try { + this.messageRef.current.focus(); + } catch { + // no-op + } }); }, ); @@ -150,12 +157,7 @@ class Rooms extends Component { validInput = () => (this.state.active || '').length > 0 && - ( - (this.messageRef && - this.messageRef.current && - this.messageRef.current.value) || - '' - ).length > 0; + (this.state.message || '').length > 0; focusInput = () => { this.messageRef.current.focus(); @@ -174,15 +176,14 @@ class Rooms extends Component { }; sendMessage = async () => { - const { active } = this.state; - const message = this.messageRef.current.value; + const { active, message } = this.state; if (!this.validInput()) { return; } await rooms.sendMessage({ message, roomName: active }); - this.messageRef.current.value = ''; + this.setState({ message: '' }); }; handleContextMenu = (clickEvent, message) => { @@ -207,8 +208,12 @@ class Rooms extends Component { }; handleReply = () => { - this.messageRef.current.value = `[${this.state.contextMenu.message.username}] ${this.state.contextMenu.message.message} --> `; - this.focusInput(); + this.setState( + (previousState) => ({ + message: `[${previousState.contextMenu.message.username}] ${previousState.contextMenu.message.message} --> `, + }), + () => this.focusInput(), + ); }; handleUserProfile = () => { @@ -364,7 +369,11 @@ class Rooms extends Component { autoComplete="off" data-lpignore="true" id="room-message-input" + onChange={(event) => + this.setState({ message: event.target.value }) + } type="text" + value={this.state.message} /> } onKeyUp={(event) => -- cgit v1.2.3 From a232848ee4f5539b0041e3581705edd00aec80f0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:27:20 -0500 Subject: clear any captured message when changing room/conversation --- src/web/src/components/Chat/Chat.jsx | 1 + src/web/src/components/Rooms/Rooms.jsx | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 0a080466..72960129 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -147,6 +147,7 @@ class Chat extends Component { { active: username, loading: true, + message: '', }, async () => { const { active, conversations } = this.state; diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index d30828eb..0b1366fd 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -118,6 +118,7 @@ class Rooms extends Component { { active: roomName, loading: true, + message: '', room: initialState.room, }, async () => { -- cgit v1.2.3 From 9a7556a9c9b3c1313f11f369d8b38ad8fe144b58 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:30:50 -0500 Subject: don't clear the message if the same room/convo is re-selected Co-authored-by: Copilot --- src/web/src/components/Chat/Chat.jsx | 6 +++--- src/web/src/components/Rooms/Rooms.jsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 72960129..086d2cd8 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -144,11 +144,11 @@ class Chat extends Component { selectConversation = (username) => { this.setState( - { + (previousState) => ({ active: username, loading: true, - message: '', - }, + message: previousState.active === username ? previousState.message : '', + }), async () => { const { active, conversations } = this.state; diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 0b1366fd..3d29242b 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -115,12 +115,12 @@ class Rooms extends Component { selectRoom = async (roomName) => { this.setState( - { + (previousState) => ({ active: roomName, loading: true, - message: '', + message: previousState.active === roomName ? previousState.message : '', room: initialState.room, - }, + }), async () => { const { active } = this.state; -- cgit v1.2.3 From 9ad8b004544e9edcf5141f536bb6be99b49dba51 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 3 May 2026 13:51:20 -0500 Subject: memoize history Co-authored-by: Copilot --- src/web/src/components/Chat/Chat.jsx | 58 ++++++++++++++++++++++------------ src/web/src/components/Rooms/Rooms.jsx | 58 ++++++++++++++++++++-------------- 2 files changed, 73 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/web/src/components/Chat/Chat.jsx b/src/web/src/components/Chat/Chat.jsx index 086d2cd8..39dd1a44 100644 --- a/src/web/src/components/Chat/Chat.jsx +++ b/src/web/src/components/Chat/Chat.jsx @@ -23,6 +23,32 @@ const initialState = { message: '', }; +const ChatMessageHistory = React.memo( + ({ formatTimestamp, messages, selfUsername }) => { + return ( + <> + {messages.map((message) => ( + + + {formatTimestamp(message.timestamp)} + + + {message.direction === 'Out' ? selfUsername : message.username}: + + {message.message} + + ))} + + + ); + }, +); + +ChatMessageHistory.displayName = 'ChatMessageHistory'; + class Chat extends Component { constructor(props) { super(props); @@ -63,6 +89,13 @@ class Chat extends Component { // fetch all of the active conversations (but no messages) let conversations = await chat.getAll(); + // the username '..' breaks nearly everything in slskd because it's a path traversal + // sequence and no API endpoints that expect usernames in the path work + // rather than letting this sit broken, i'm making the choice to filter it out + // eslint-disable-next-line no-warning-comments + // todo: remove this filter when the API can handle '..' + conversations = conversations.filter((f) => f.username !== '..'); + // turn into a map, keyed by username // if there are no active conversations, set to an empty map if (conversations.length === 0) { @@ -257,26 +290,11 @@ class Chat extends Component { - {messages.map((message) => ( - - - {this.formatTimestamp(message.timestamp)} - - - {message.direction === 'Out' - ? user.username - : message.username} - :{' '} - - - {message.message} - - - ))} - + diff --git a/src/web/src/components/Rooms/Rooms.jsx b/src/web/src/components/Rooms/Rooms.jsx index 3d29242b..f6bdb685 100644 --- a/src/web/src/components/Rooms/Rooms.jsx +++ b/src/web/src/components/Rooms/Rooms.jsx @@ -39,6 +39,36 @@ const initialState = { }, }; +const RoomMessageHistory = React.memo( + ({ formatTimestamp, messages, onHandleContextMenu }) => { + return ( + <> + {messages.map((message) => ( +
+ onHandleContextMenu(clickEvent, message) + } + > + + + {formatTimestamp(message.timestamp)} + + {message.username}: + {message.message} + +
+ ))} + + + ); + }, +); + +RoomMessageHistory.displayName = 'RoomMessageHistory'; + class Rooms extends Component { constructor(props) { super(props); @@ -325,29 +355,11 @@ class Rooms extends Component { - {room.messages.map((message) => ( -
- this.handleContextMenu(clickEvent, message) - } - > - - - {this.formatTimestamp(message.timestamp)} - - - {message.username}:{' '} - - - {message.message} - - -
- ))} - +
-- cgit v1.2.3