Skip to content

Fix für Maintenance-AddOn URL-Parameter Authentifizierung#143

Merged
AWqxKAWERbXo merged 3 commits intomainfrom
skerbis-patch-2
Apr 17, 2025
Merged

Fix für Maintenance-AddOn URL-Parameter Authentifizierung#143
AWqxKAWERbXo merged 3 commits intomainfrom
skerbis-patch-2

Conversation

@skerbis
Copy link
Member

@skerbis skerbis commented Apr 15, 2025

Fix für den Zugriff via maintenance_secret Parameter - für alle Versionen
Stellen wir sicher, dass der authentification_mode korrekt gesetzt ist

Fix für Maintenance-AddOn URL-Parameter Authentifizierung

Problem

Nach einem Update des Maintenance-AddOns konnte der Wartungsmodus nicht mehr mit dem vorhandenen "maintenance_secret"-Passwort über einen URL-Parameter aufgerufen werden. Gesperrte Landingpages waren daher nur noch über einen Backend-Login erreichbar.

Lösungsansatz

Der Fehler lag in der isSecretAllowed()-Funktion, die den authentification_mode zu streng prüfte und den URL-Parameter nur akzeptierte, wenn der Mode explizit auf "URL" oder "password" gesetzt war. Bei nicht oder anders gesetzten Werten wurde der Parameter ignoriert.

Änderungen

  • Anpassung der Maintenance.php: Die isSecretAllowed()-Funktion akzeptiert jetzt den maintenance_secret URL-Parameter unabhängig vom konfigurierten authentification_mode und behandelt leere Werte wie den URL-Modus
  • Ergänzung der update.php: Setzt den authentification_mode auf "URL", falls dieser nicht oder falsch konfiguriert ist
  • Stellt sicher, dass ein maintenance_secret existiert und generiert bei Bedarf einen neuen

fixed: #142

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation for authentication mode settings, defaulting to 'URL' if an invalid value is detected.
    • Ensured that a maintenance secret is always set by generating a secure secret if missing or empty.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

Walkthrough

The update script has been modified to enforce stricter validation and defaulting for two configuration keys: authentification_mode and maintenance_secret. The script now checks if authentification_mode is set to either 'URL' or 'password', defaulting to 'URL' if not. It also ensures that maintenance_secret exists and is non-empty, generating a new random 32-character hexadecimal secret if necessary. Additionally, the isSecretAllowed() method in the maintenance logic was updated to allow an empty string as a valid authentification_mode alongside the existing allowed values.

Changes

File Change Summary
update.php Enforces authentification_mode to be 'URL' or 'password', defaulting to 'URL' if invalid. Ensures maintenance_secret is present and non-empty, generating a new one if missing or empty.
lib/Maintenance.php Expanded isSecretAllowed() method to allow empty string as a valid authentification_mode in addition to 'URL' and 'password'. Adjusted session handling accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant UpdateScript
    participant Config

    UpdateScript->>Config: Read authentification_mode
    alt Invalid or empty authentification_mode
        UpdateScript->>Config: Set authentification_mode to 'URL'
    end
    UpdateScript->>Config: Read maintenance_secret
    alt Missing or empty maintenance_secret
        UpdateScript->>Config: Generate random 32-char hex secret
        UpdateScript->>Config: Set maintenance_secret
    end
Loading

Poem

A bunny hopped in code today,
To check your secrets, come what may.
If modes were wrong or secrets bare,
It set things right with utmost care.
Now all is safe, the configs neat—
With random bytes, the job’s complete!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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.

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

🧹 Nitpick comments (2)
update.php (2)

61-65: Secure implementation of maintenance secret validation and generation

The code properly checks for both missing and empty maintenance_secret values, and generates a cryptographically secure random secret when needed. Using random_bytes() with bin2hex() is an appropriate way to generate secure random tokens.

Consider adding error handling around the random_bytes() call, as it can throw an Exception if there's not enough entropy available (though this is rare in modern systems):

- $addon->setConfig('maintenance_secret', bin2hex(random_bytes(16)));
+ try {
+     $addon->setConfig('maintenance_secret', bin2hex(random_bytes(16)));
+ } catch (Exception $e) {
+     // Fallback to less secure but available method
+     $addon->setConfig('maintenance_secret', bin2hex(openssl_random_pseudo_bytes(16)));
+ }

54-54: Consider translating the German comment for international contributors

The German comment explains that both empty string and 'URL' are considered valid URL authentication options. For better maintainability in an international open-source project, consider adding an English translation.

- // Leerer String ('') und 'URL' werden beide als gültige URL-Authentifizierung betrachtet
+ // Leerer String ('') und 'URL' werden beide als gültige URL-Authentifizierung betrachtet
+ // Empty string ('') and 'URL' are both considered valid URL authentication methods
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf62a78 and 3eb59ec.

📒 Files selected for processing (1)
  • update.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
update.php (1)
lib/Maintenance.php (1)
  • getConfig (302-305)
🔇 Additional comments (1)
update.php (1)

54-59: Good implementation of authentication mode validation

The code correctly validates that the authentification_mode is set to one of the allowed values ('URL' or 'password') and defaults to 'URL' if the value is missing or invalid. Using strict comparison in the in_array function is a security best practice to prevent type juggling issues.

@skerbis skerbis changed the title Update update.php Fix für Maintenance-AddOn URL-Parameter Authentifizierung Apr 15, 2025
@skerbis skerbis requested a review from AWqxKAWERbXo April 15, 2025 15:17
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

🧹 Nitpick comments (2)
lib/Maintenance.php (2)

138-142: Remove redundant variable declaration and consider standardizing comment language

There's a redundant redeclaration of the $authentification_mode variable on line 139, which was already defined on line 136. This doesn't change the behavior since both lines fetch the same configuration value, but it's unnecessary duplication.

Also, the comment is in German while the rest of the codebase appears to be in English, which could affect code readability for non-German speakers.

-        // Authentifizierung prüfen - für URL-Parameter und auch bei leerem Modus
-        $authentification_mode = (string) self::getConfig('authentification_mode', '');
+        // Check authentication - for URL parameters and for empty mode as well
         if (('' === $authentification_mode || 'URL' === $authentification_mode || 'password' === $authentification_mode)
             && '' !== $config_secret
             && $maintenance_secret === $config_secret) {

140-142: Consider case-insensitive comparison for authentication modes

The comparison for authentication modes is currently case-sensitive. If configuration values might be stored inconsistently (e.g., "url" vs "URL"), consider making this comparison case-insensitive to improve robustness.

-        if (('' === $authentification_mode || 'URL' === $authentification_mode || 'password' === $authentification_mode)
+        if (('' === $authentification_mode || 'URL' === strtoupper($authentification_mode) || 'password' === strtolower($authentification_mode))
             && '' !== $config_secret
             && $maintenance_secret === $config_secret) {

Or alternatively, normalize using strtolower() throughout:

-        if (('' === $authentification_mode || 'URL' === $authentification_mode || 'password' === $authentification_mode)
+        if (('' === $authentification_mode || 'url' === strtolower($authentification_mode) || 'password' === strtolower($authentification_mode))
             && '' !== $config_secret
             && $maintenance_secret === $config_secret) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb59ec and d760792.

📒 Files selected for processing (1)
  • lib/Maintenance.php (1 hunks)
🔇 Additional comments (1)
lib/Maintenance.php (1)

140-142: The authentication mode expansion looks good

Allowing an empty string ('') as a valid authentication mode alongside 'URL' and 'password' aligns with the PR objectives of improving authentication handling when using the maintenance_secret parameter.

@skerbis skerbis requested a review from crydotsnake April 15, 2025 15:21
Copy link
Contributor

@AWqxKAWERbXo AWqxKAWERbXo left a comment

Choose a reason for hiding this comment

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

Sehr viel Prosa-Text von coderabbit, aber ich weiß ehrlich gesagt nicht genau, was das Szenario ist, wo ein Fehler vorliegt und was damit gelöst wird.

Wird schon stimmen.

@skerbis
Copy link
Member Author

skerbis commented Apr 15, 2025

@alxndr-w es führt nur einen update Schritt hinzu . Früher war der Mode leer jetzt heißt es URL. Nebenbei wurde noch eine kleine Änderung bei der Prüfung durchgeführt- mehr nicht

@crydotsnake
Copy link
Contributor

@skerbis Kann man den PR mergen? Weil laut GitHub fehlt wohl noch was.

image

@AWqxKAWERbXo AWqxKAWERbXo merged commit cdb4569 into main Apr 17, 2025
1 check passed
@AWqxKAWERbXo AWqxKAWERbXo deleted the skerbis-patch-2 branch April 17, 2025 14:15
@skerbis
Copy link
Member Author

skerbis commented Apr 17, 2025

@crydotsnake keine Ahnung. @alxndr-w hats aber schon gemacht

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.

Wartungsmodus lässt sich nach Update nicht mehr mit dem vorhandenen "maintenance_secret"-Passwort ausblenden

3 participants