aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/get_remote_object_authenticated.php
diff options
context:
space:
mode:
authorwinter2024-12-17 18:39:18 +0000
committerwinter2024-12-17 18:39:18 +0000
commit085762ec174eae1c519ec14db632f5ba197ed3c7 (patch)
tree9ad49bc839b5f72ded47c119ff01a09dfa0b934a /misc/get_remote_object_authenticated.php
parentbc2cd99b108b8755a648c3915714e7c0e0771548 (diff)
hopefully implement push!
again i can't really test this yet because i don't have two https instances that can talk to each other. soon i will set that up and test all these recent commits
Diffstat (limited to 'misc/get_remote_object_authenticated.php')
-rw-r--r--misc/get_remote_object_authenticated.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/misc/get_remote_object_authenticated.php b/misc/get_remote_object_authenticated.php
index ba67473..49aaa59 100644
--- a/misc/get_remote_object_authenticated.php
+++ b/misc/get_remote_object_authenticated.php
@@ -1,5 +1,6 @@
<?php
+use Digitigrade\GlobalConfig;
use Digitigrade\Model\Instance;
/**
@@ -8,13 +9,19 @@ use Digitigrade\Model\Instance;
* @param bool $dontLookUpInstance if true, will skip looking up the Instance, and consequently the auth token
* @return false|string the response data, or false if it failed
*/
-function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = false) {
+function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = false): false|string {
if (!str_starts_with($uri, 'https://'))
return false;
+ $remoteHost = hostname_from_uri($uri);
+ if ($remoteHost == GlobalConfig::getInstance()->getCanonicalHost()) {
+ // refuse to fetch objects from ourself. that's silly
+ return false;
+ }
+
$instance = null;
if (!$dontLookUpInstance) {
- $instance = Instance::findByDomain(explode('/', $uri)[2]);
+ $instance = Instance::findByHostname($remoteHost);
}
if ($instance?->auth?->outboundToken == null) {