SecurityFaultException.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * Part of Shuzanne - An extensible sequel to an open-source imageboard.
  4. *
  5. * @package Shuzanne
  6. * @author MisleadingName, Shuzanne Contributors
  7. * @license MPL v2.0
  8. *
  9. * This Source Code Form is subject to the terms of the Mozilla Public
  10. * License, v. 2.0. If a copy of the MPL was not distributed with this
  11. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  12. */
  13. namespace Hajeebtok\Types\Exceptions;
  14. use Exception;
  15. use JetBrains\PhpStorm\Pure;
  16. use app\Logger;
  17. use app\Hajeebtok;
  18. use Throwable;
  19. class SecurityFaultException extends Exception
  20. {
  21. public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
  22. {
  23. Logger::Fatal("Security fault tripped: $message Request details:");
  24. $incidentId = bin2hex(random_bytes(16));
  25. $devmode = Hajeebtok::$Config->GetByDotKey("Instance.DebugMode") == "true";
  26. Logger::Fatal("Incident ID: $incidentId");
  27. $details = json_encode($_SERVER, JSON_PRETTY_PRINT);
  28. Logger::Fatal($details);
  29. $otherDetails = json_encode($_REQUEST, JSON_PRETTY_PRINT);
  30. Logger::Fatal($otherDetails);
  31. parent::__construct("Security fault tripped: $message", $code, $previous);
  32. $details = $devmode ? $details : "Redacted";
  33. $otherDetails = $devmode ? $otherDetails : "Redacted";
  34. http_response_code(403);
  35. die(<<<HTML
  36. <!doctype html>
  37. <html lang="en">
  38. <head>
  39. <meta charset="UTF-8">
  40. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  41. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  42. <title>Shuzanne</title>
  43. </head>
  44. <body style="font-family: sans-serif; background-color: #eee; color: #333; padding: 20px;">
  45. <div style="border: 8px solid #f00; padding: 1em; background-color: #ffff00;">
  46. <h1 style="margin: 0;">You have triggered a security fault.</h1>
  47. <p style="margin: 1em 0;">Your request has been terminated, and the incident has been logged. Please contact the site administrator if you believe this was in error.</p>
  48. <summary>
  49. <details>
  50. <summary>Request details</summary>
  51. <p>Incident ID: $incidentId</p>
  52. <pre style="white-space: pre-wrap;">$details</pre>
  53. <pre style="white-space: pre-wrap;">$otherDetails</pre>
  54. </details>
  55. </summary>
  56. </div>
  57. <p><a href="javascript:history.back()">Go back</a></p>
  58. </body>
  59. </html>
  60. HTML);
  61. }
  62. }