{"record":{"id":"68220da3e9a077b2","repo":"ratchetphp/Ratchet","slug":"you-must-add-a-domain-through-addallowedaccess","errorCode":null,"errorMessage":"You must add a domain through addAllowedAccess()","messagePattern":"You must add a domain through addAllowedAccess\\(\\)","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Server/FlashPolicy.php","lineNumber":157,"sourceCode":"    /**\n     * Builds the crossdomain file based on the template policy\n     *\n     * @throws \\UnexpectedValueException\n     * @return \\SimpleXMLElement\n     */\n    public function renderPolicy() {\n        $policy = new \\SimpleXMLElement($this->_policy);\n\n        $siteControl = $policy->addChild('site-control');\n\n        if ($this->_siteControl == '') {\n            $this->setSiteControl();\n        }\n\n        $siteControl->addAttribute('permitted-cross-domain-policies', $this->_siteControl);\n\n        if (empty($this->_access)) {\n            throw new \\UnexpectedValueException('You must add a domain through addAllowedAccess()');\n        }\n\n        foreach ($this->_access as $access) {\n            $tmp = $policy->addChild('allow-access-from');\n            $tmp->addAttribute('domain', $access[0]);\n            $tmp->addAttribute('to-ports', $access[1]);\n            $tmp->addAttribute('secure', ($access[2] === true) ? 'true' : 'false');\n        }\n\n        return $policy;\n    }\n\n    /**\n     * Make sure the proper site control was passed\n     *\n     * @param string $permittedCrossDomainPolicies\n     * @return bool\n     */","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Server/FlashPolicy.php#L139-L175","documentation":"Thrown by FlashPolicy::renderPolicy() when generating the crossdomain.xml policy while the internal access list ($_access) is empty. A Flash cross-domain policy with no <allow-access-from> entries would deny every connection, so the renderer treats a policy with zero allowed domains as an invalid/incomplete configuration rather than emitting a useless document. It fires when the developer configured a FlashPolicy object (and possibly site-control) but never called addAllowedAccess() before rendering.","triggerScenarios":"Thrown at src/Ratchet/Server/FlashPolicy.php:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call addAllowedAccess($domain, $ports) at least once before invoking renderPolicy(), e.g. $policy->addAllowedAccess('*', '*') to permit all domains while testing.","Check whether the code path that populates allowed domains ran (e.g. config loaded from a file or request parameters) and add a default allow entry when it did not.","If an empty policy is legitimate for your use case, catch \\UnexpectedValueException around renderPolicy() and handle the empty-policy case explicitly."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e621c6c40bf684bbbb877102416ad5303d05a9cc","analyzedAt":"2026-09-16T00:13:27.878Z","contentChangedAt":"2026-09-16T00:13:27.878Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}