{"record":{"id":"6ec1daafe6d6a6f9","repo":"phalcon/cphalcon","slug":"a-dependency-injection-container-is-required-to-ac-6ec1da","errorCode":null,"errorMessage":"A dependency injection container is required to access the 'filter' service","messagePattern":"A dependency injection container is required to access the 'filter' service","errorType":"exception","errorClass":"Phalcon\\Http\\Cookie\\Exceptions\\FilterServiceUnavailable","httpStatus":null,"severity":"error","filePath":"phalcon/Http/Cookie.zep","lineNumber":253,"sourceCode":"                }\n            } else {\n                let decryptedValue = value;\n            }\n\n            /**\n             * Update the decrypted value\n             */\n            let this->value = decryptedValue;\n\n            if filters !== null {\n                let filter = this->filter;\n\n                if typeof filter != \"object\" {\n                    if container === null {\n                        let container = <DiInterface> this->container;\n\n                        if container === null {\n                            throw new FilterServiceUnavailable();\n                        }\n                    }\n\n                    let filter = <FilterInterface> container->getShared(\"filter\"),\n                        this->filter = filter;\n                }\n\n                return filter->sanitize(decryptedValue, filters);\n            }\n\n            /**\n             * Return the value without filtering\n             */\n            return decryptedValue;\n        }\n\n        return this->value;\n    }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Http/Cookie.zep#L235-L271","documentation":"When Http\\Cookie::getValue() is called with a non-null $filters argument and no FilterInterface object has been set on the cookie, it resolves the 'filter' service from the DI container. If no container is attached, FilterServiceUnavailable is thrown — the same injection-aware failure as the crypt variant, but on the sanitization path.","triggerScenarios":"$cookie->getValue('string') (any non-null filter name) on a cookie whose setFilter() was never called and whose DI container was never attached via setDI(); reading and filtering cookies in CLI workers or tests that bypass full bootstrap.","commonSituations":"Background jobs and test harnesses constructing Cookie directly; early bootstrap code that filters cookies before the container exists; omitting setFilter() when the cookie is used outside the HTTP lifecycle.","solutions":["Attach the container before reading: $cookie->setDI(Di::getDefault())","Or set the filter explicitly: $cookie->setFilter($di->getShared('filter'))","If sanitization happens elsewhere, call getValue() with no filters"],"exampleFix":"// before\n$cookie = new Cookie('session_id');\n$clean = $cookie->getValue('alnum'); // FilterServiceUnavailable\n\n// after\n$cookie = new Cookie('session_id');\n$cookie->setDI(Di::getDefault());\n$clean = $cookie->getValue('alnum');","handlingStrategy":"validation","validationCode":"if ($filters !== null) {\n    if (!is_object($cookie->getFilter() ?? null) && null === Di::getDefault()) {\n        throw new \\RuntimeException(\n            \"A DI container with a 'filter' service is required to filter cookie values\"\n        );\n    }\n}\n\n$value = $cookie->getValue($filters);","typeGuard":null,"tryCatchPattern":"try {\n    $value = $cookie->getValue('string');\n} catch (\\Phalcon\\Http\\Cookie\\Exceptions\\FilterServiceUnavailable $e) {\n    // attach the container and retry\n    $cookie->setDI(Di::getDefault());\n    $value = $cookie->getValue('string');\n}","preventionTips":["Call setDI() on standalone Cookie instances whenever getValue() uses filters","Alternatively inject the filter directly: $cookie->setFilter($di->getShared('filter'))","Bootstrap the DI container before any cookie reads in workers, tests, and early request hooks"],"tags":["phalcon","http","cookie","dependency-injection","filter"],"backgroundTag":"missing-di-container","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}