SecurityFaultException.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 app\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. CORSHelper();
  36. die(<<<HTML
  37. <!doctype html>
  38. <html lang="en">
  39. <head>
  40. <meta charset="UTF-8">
  41. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  42. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  43. <title>Hajeebtok</title>
  44. </head>
  45. <body style="font-family: sans-serif; background-color: #eee; color: #333; padding: 20px;">
  46. <div style="border: 8px solid #f00; padding: 1em; background-color: #ffff00;">
  47. <h1 style="margin: 0;">You have triggered a security fault.</h1>
  48. <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>
  49. <summary>
  50. <details>
  51. <p>Message: $message</p>
  52. <summary>Request details</summary>
  53. <p>Incident ID: $incidentId</p>
  54. <pre style="white-space: pre-wrap;">$details</pre>
  55. <pre style="white-space: pre-wrap;">$otherDetails</pre>
  56. </details>
  57. </summary>
  58. </div>
  59. <p><a href="javascript:history.back()">Go back</a></p>
  60. </body>
  61. </html>
  62. HTML);
  63. }
  64. }