Browse Source

[Web] use SEC_FETCH_DEST header to block api requests

FreddleSpl0it 1 year ago
parent
commit
cd24057f1a
1 changed files with 6 additions and 0 deletions
  1. 6 0
      data/web/json_api.php

+ 6 - 0
data/web/json_api.php

@@ -47,6 +47,12 @@ function api_log($_data) {
   }
 }
 
+// Block requests not intended for direct API use by checking the 'Sec-Fetch-Dest' header.
+if (isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] !== 'empty') {
+  header('HTTP/1.1 403 Forbidden');
+  exit;
+}
+
 if (isset($_GET['query'])) {
 
   $query = explode('/', $_GET['query']);