Skip to content

Conversation

@zackspear
Copy link
Contributor

@zackspear zackspear commented Mar 21, 2025

  • Added UnraidCheckExec.php to separate concerns between UnraidCheck and ReplaceKey, allowing for JSON responses.
  • Updated unraidcheck script to parse query strings for compatibility with the new class.
  • Modified webgui.ts to call UnraidCheckExec.php instead of UnraidCheck.php for update checks.

Summary by CodeRabbit

  • New Features

    • Updated the plugin installation process to ensure critical files remain protected during updates.
    • Introduced a dedicated update check component that now returns results in a JSON format.
    • Enhanced the web interface’s update check functionality with streamlined request parameters.
  • Refactor

    • Separated update checking responsibilities for improved logic clarity and overall reliability.
    • Updated the interface for the update check payload to enhance parameter handling.

- Added `UnraidCheckExec.php` to separate concerns between UnraidCheck and ReplaceKey, allowing for JSON responses.
- Updated `unraidcheck` script to parse query strings for compatibility with the new class.
- Modified `webgui.ts` to call `UnraidCheckExec.php` instead of `UnraidCheck.php` for update checks.
- Updated `UnraidCheckExec.php` to handle `altUrl` and `json` parameters for improved flexibility in OS update checks.
- Modified `webgui.ts` to utilize the new `WebguiUnraidCheckExecPayload` interface, ensuring compatibility with the updated parameters.
… restore and preserve files

- Added `UnraidCheckExec.php` to the list of files restored during plugin updates.
- Updated preservation rules to prevent downgrade for `UnraidCheckExec.php`.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 21, 2025

Walkthrough

The changes update the Unraid plugin by adding a new file reference for restoration and preservation. A new PHP class, UnraidCheckExec, is introduced to run an external update check script with a dedicated environment setup. The external script now reads the query string from the environment variable to populate the GET parameters. Additionally, the web service interface is updated to use the new endpoint and payload format, replacing the old version. Overall, these changes extend the update check functionality without altering the existing control flow.

Changes

File(s) Summary
plugin/plugins/dynamix.unraid.net.plg Added a new file reference (.../include/UnraidCheckExec.php) to the FILES_TO_RESTORE and a corresponding entry in the preserveFilesDirs array with the action move and prevention type preventDowngrade.
plugin/source/dynamix.unraid.net/.../include/UnraidCheckExec.php Introduced a new PHP class, UnraidCheckExec, with methods for setting up the environment and executing an external script to check for Unraid updates.
plugin/source/dynamix.unraid.net/.../scripts/unraidcheck Modified the script to parse the QUERY_STRING environment variable and populate the $_GET superglobal for JSON responses.
web/composables/services/webgui.ts Updated the interface to WebguiUnraidCheckExecPayload and modified the payload and endpoint (now pointing to UnraidCheckExec.php) in the WebguiCheckForUpdate function.

Sequence Diagram(s)

sequenceDiagram
  participant WG as Web GUI
  participant PHP as UnraidCheckExec
  participant SC as unraidcheck Script

  WG->>PHP: Call WebguiCheckForUpdate (new endpoint)
  PHP->>PHP: Execute setupEnvironment() (set headers & prepare QUERY_STRING)
  PHP->>SC: exec() call to run external script
  SC-->>PHP: Return script output
  PHP-->>WG: Return concatenated result to Web UI
Loading

Possibly related PRs

Suggested reviewers

  • elibosley
  • pujitm

Poem

In our code, a new path unfurls,
A scripted check in updated swirls.
Backup and restore, safely aligned,
With JSON tales gracefully defined.
Code sings its song, fresh and clear—
A dance of updates, letting progress cheer!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@zackspear zackspear removed the request for review from mdatelle March 21, 2025 00:27
elibosley
elibosley previously approved these changes Mar 21, 2025
Copy link
Member

@elibosley elibosley left a comment

Choose a reason for hiding this comment

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

looks good but please ensure the script cannot be called with any sort of CLI injection!

…tion

- Added security headers to the setupEnvironment method for improved security.
- Enhanced altUrl validation to ensure only allowed domains are accepted.
- Updated script execution checks to include executable permission validation.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (1)

43-44: ⚠️ Potential issue

Potential command injection vulnerability

The unescaped use of http_build_query output in putenv could potentially lead to environment variable injection attacks if parameter values contain malicious characters.

Consider sanitizing or escaping the query string before setting it as an environment variable:

- putenv('QUERY_STRING=' . http_build_query($params));
+ putenv('QUERY_STRING=' . escapeshellarg(http_build_query($params)));
🧹 Nitpick comments (2)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (2)

62-63: Consider JSON encoding the response

Since the headers indicate JSON content and the 'json' parameter is set to true, consider JSON encoding the output if it's not already in JSON format from the script.

- return implode("\n", $output);
+ // Return JSON string directly if script already outputs JSON
+ $outputString = implode("\n", $output);
+ // Verify it's valid JSON before returning
+ if (json_decode($outputString) === null && json_last_error() !== JSON_ERROR_NONE) {
+     // If not valid JSON, encode it
+     return json_encode(['output' => $outputString]);
+ }
+ return $outputString;

66-69: Consider using namespaces and autoloading

For better maintainability and to avoid potential class name conflicts, consider using PHP namespaces. Also, the direct instantiation and execution at the bottom of the file makes unit testing more difficult.

<?php
+ namespace Dynamix\PluginManager;

/**
 * This file exists to maintain separation of concerns between UnraidCheck and ReplaceKey.
...
}

- // Usage
- $checker = new UnraidCheckExec();
- echo $checker->execute();
+ // Only execute if this file is being accessed directly
+ if (basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) {
+     $checker = new UnraidCheckExec();
+     echo $checker->execute();
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1481150 and 1f2d1c2.

📒 Files selected for processing (1)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test API
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.plugin.manager/include/UnraidCheckExec.php (6)

1-11: Well-documented purpose and interface

The file header clearly explains the purpose of separation of concerns and documents the expected interface parameters. Good practice to include this documentation.


12-16: Good use of constants for configuration

The class properly defines constants for script path and allowed domain, making these values easy to update if needed.


17-23: Comprehensive security headers

The security headers are well-implemented to protect against common web vulnerabilities:

  • Content-Type header prevents MIME sniffing attacks
  • X-Frame-Options prevents clickjacking
  • Content-Security-Policy restricts resource loading

24-41: Thorough URL validation for preventing SSRF

The URL validation logic correctly:

  1. Verifies the URL format
  2. Ensures HTTPS protocol is used
  3. Restricts to allowed domain and its subdomains

This is a strong defense against Server-Side Request Forgery attacks.


46-53: Good script validation checks

The code properly validates that the script exists, is readable, and is executable before attempting to execute it. This prevents potential errors and provides clear error messages.


57-60: Proper command execution with escaping

Using escapeshellcmd on the script path is a good security practice to prevent command injection. The error handling for failed execution is also appropriate.

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1265/dynamix.unraid.net.plg

@zackspear
Copy link
Contributor Author

since this was preapproved before cursor helped with security items I'm gonna merge this in so I can get these into webgui repo. Tested extensively after the security additions. Good call on having me add them

@zackspear zackspear merged commit 5935a3b into main Mar 21, 2025
8 checks passed
@zackspear zackspear deleted the feat/check-os-updates-with-unraidcheck-script branch March 21, 2025 21:05
elibosley pushed a commit that referenced this pull request Mar 25, 2025
🤖 I have created a release *beep* *boop*
---


## [4.4.0](v4.3.1...v4.4.0)
(2025-03-25)


### Features

* add ReplaceKey functionality to plugin
([#1264](#1264))
([4aadcef](4aadcef))
* downgrade page replace key check
([#1263](#1263))
([8d56d12](8d56d12))
* make log viewer component dynamic
([#1242](#1242))
([e6ec110](e6ec110))
* ReplaceKey functionality in Registration and Update pages
([#1246](#1246))
([04307c9](04307c9))
* UnraidCheckExec for Check OS Updates via UPC dropdown
([#1265](#1265))
([5935a3b](5935a3b))


### Bug Fixes

* **deps:** update all non-major dependencies
([#1236](#1236))
([7194f85](7194f85))
* **deps:** update all non-major dependencies
([#1247](#1247))
([20b0aeb](20b0aeb))
* **deps:** update all non-major dependencies
([#1251](#1251))
([33a1a1d](33a1a1d))
* **deps:** update all non-major dependencies
([#1253](#1253))
([53fec0e](53fec0e))
* **deps:** update dependency @nestjs/passport to v11
([#1244](#1244))
([edc93a9](edc93a9))
* **deps:** update dependency graphql-subscriptions to v3
([#1209](#1209))
([c14c85f](c14c85f))
* **deps:** update dependency ini to v5
([#1217](#1217))
([f27660f](f27660f))
* **deps:** update dependency jose to v6
([#1248](#1248))
([42e3d59](42e3d59))
* **deps:** update dependency marked to v15
([#1249](#1249))
([2b6693f](2b6693f))
* **deps:** update dependency pino-pretty to v13
([#1250](#1250))
([85fb910](85fb910))
* **deps:** update dependency pm2 to v6
([#1258](#1258))
([04ad2bc](04ad2bc))
* **deps:** update dependency shadcn-vue to v1
([#1259](#1259))
([1a4fe8f](1a4fe8f))
* **deps:** update dependency vue-i18n to v11
([#1261](#1261))
([0063286](0063286))
* **deps:** update vueuse monorepo to v13 (major)
([#1262](#1262))
([94caae3](94caae3))
* make scripts executable when building the plugin
([#1255](#1255))
([e237f38](e237f38))
* node installation not persisting across reboots
([#1256](#1256))
([0415cf1](0415cf1))
* update configValid state to ineligible in var.ini and adjust rel…
([#1268](#1268))
([ef8c954](ef8c954))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants