From df331ce2f881aa89920c004eafcfd327c91b66f0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 4 Jul 2025 18:52:50 -0500 Subject: docs --- docs/config.md | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/config.md b/docs/config.md index cf7fb9a3..ff3e8410 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1033,11 +1033,23 @@ integration: ### Scripts -User-defined scripts can be configured to run when application events are raised. Scripts are given a name (useful for troubleshooting!), a list of triggering events, and a `run` command that's used to execute the script. +User-defined scripts can be configured to run when application events are raised. Scripts are given a name (useful for troubleshooting!), a list of triggering events, and a `run` configuration that's used to execute the script. -The `run` command must be at least one word, with the first word identifying the executable to run and the rest of the string being the command and arguments that will be passed to the executable when the script is run. The executable needs to be on the system's PATH, otherwise it must be the fully qualified path to the file on disk. +The `run` configuration can take a few different forms (see examples below), but in all cases a new process is started using either the `executable` you specify or, if you don't specify one, the executable set in your system's `$SHELL` environment variable, or `cmd.exe` on Windows. -A reserved placeholder value `$DATA` is replaced with the stringified JSON data associated with the event that caused the script to run. It's the responsibility of the script to parse and handle this JSON. +Processes are started in the `/scripts` directory (meaning the working directory), and stdout and stderr are redirected to slskd for logging purposes. Depending on the `run` configuration your defined command will be passed as either a single argument or list of arguments, with the latter being easier to properly quote and escape. + +The data associated with the event that's invoking your script is stringified to JSON and set as the value of the `SLSKD_SCRIPT_DATA` environment variable. Whatever command or script you specify will need to read this value and handle the data. + +> [!DANGER] +> **Remote Code Execution Risk**: The event data in `$SLSKD_SCRIPT_DATA` originates from the Soulseek network and may contain malicious content. Passing this data as command-line arguments could allow attackers to inject shell commands through specially crafted filenames, usernames, or other fields. For example, a filename like `song"; rm -rf /; echo "` could delete your entire filesystem if passed unsafely to a shell command. +> +> **Safe practices:** +> - ✅ Read `$SLSKD_SCRIPT_DATA` as an environment variable +> - ✅ Parse the JSON and validate/sanitize individual fields before use +> - ✅ Use programming languages with proper JSON parsing (Python, Node.js, etc.) +> - ❌ Avoid using `$SLSKD_SCRIPT_DATA` in shell command substitution like `$(echo $SLSKD_SCRIPT_DATA)` +> - ❌ Avoid passing the raw data as arguments: `my_script.sh "$SLSKD_SCRIPT_DATA"` #### **YAML** ```yaml @@ -1047,11 +1059,22 @@ integration: on: - DownloadFileComplete - DownloadDirectoryComplete - run: /bin/sh data/my_script.sh --json-to-process "$DATA" # Linux/macOS + run: + command: "echo "new event!" >> event_log.txt # command is run with system $SHELL/cmd.exe on Windows my_logging_script: on: - - All - run: cmd.exe echo $DATA >> event_log.txt # Windows + - All + run: + executable: /bin/sh # explicitly setting executable; if omitted, $SHELL/cmd.exe is used + args: '-c "echo "new event!" >> event_log.txt"' + another_script: + on: + - All + run: + executable: /bin/sh # as above, can omit to use $SHELL/cmd.exe + arglist: # easier to properly quote + - /c + - 'echo "new event!" >> event_log.txt' ``` ## System-Defined -- cgit v1.2.3