ratchetphp/Ratchet · error · UnexpectedValueException
You must add a domain through addAllowedAccess()
Error message
You must add a domain through addAllowedAccess()
What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/Ratchet/Server/FlashPolicy.php:157 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ratchetphp/Ratchet@e621c6c40b (2026-09-16).
Data as JSON: /api/errors/68220da3e9a077b2.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ratchet/Server/FlashPolicy.php:157
/**
* Builds the crossdomain file based on the template policy
*
* @throws \UnexpectedValueException
* @return \SimpleXMLElement
*/
public function renderPolicy() {
$policy = new \SimpleXMLElement($this->_policy);
$siteControl = $policy->addChild('site-control');
if ($this->_siteControl == '') {
$this->setSiteControl();
}
$siteControl->addAttribute('permitted-cross-domain-policies', $this->_siteControl);
if (empty($this->_access)) {
throw new \UnexpectedValueException('You must add a domain through addAllowedAccess()');
}
foreach ($this->_access as $access) {
$tmp = $policy->addChild('allow-access-from');
$tmp->addAttribute('domain', $access[0]);
$tmp->addAttribute('to-ports', $access[1]);
$tmp->addAttribute('secure', ($access[2] === true) ? 'true' : 'false');
}
return $policy;
}
/**
* Make sure the proper site control was passed
*
* @param string $permittedCrossDomainPolicies
* @return bool
*/View on GitHub (pinned to e621c6c40b)