public function getOrigin($isInternal = true)
    {
        $origin = null;

        if ($this->_headers->has('Origin'))
        {
            try {
                $origin = $this->getObject('lib:http.url', [
                    'url' => $this->getObject('lib:filter.url')->sanitize($this->_headers->get('Origin'))
                ]);

                if($isInternal)
                {
                    $target_origin = $this->getUrl()->getHost();
                    $source_origin = $origin->getHost();

                    // Check if the source matches the target
                    if($target_origin !== $source_origin)
                    {
                        // Special case: check if the source is a subdomain of the target origin
                        if ('.'.$target_origin !== substr($source_origin, -1 * (strlen($target_origin)+1))) {
                            $origin = null;
                        }
                    }
                }
            }
            catch (\UnexpectedValueException $e) {}
        }

        return $origin;
    }