{"record":{"id":"3351453f0f119a89","repo":"symfony/http-foundation","slug":"invalid-argument-savepath-s","errorCode":null,"errorMessage":"Invalid argument $savePath '%s'.","messagePattern":"Invalid argument \\$savePath '(.+?)'\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Session/Storage/Handler/NativeFileSessionHandler.php","lineNumber":40,"sourceCode":"    private const SESSION_FILE_PREFIX = 'sess_';\n\n    /**\n     * @param string|null $savePath Path of directory to save session files\n     *                              Default null will leave setting as defined by PHP.\n     *                              '/path', 'N;/path', or 'N;octal-mode;/path\n     *\n     * @see https://php.net/session.configuration#ini.session.save-path for further details.\n     *\n     * @throws \\InvalidArgumentException On invalid $savePath\n     * @throws \\RuntimeException         When failing to create the save directory\n     */\n    public function __construct(?string $savePath = null)\n    {\n        $baseDir = $savePath ??= \\ini_get('session.save_path');\n\n        if ($count = substr_count($savePath, ';')) {\n            if ($count > 2) {\n                throw new \\InvalidArgumentException(\\sprintf('Invalid argument $savePath \\'%s\\'.', $savePath));\n            }\n\n            // characters after last ';' are the path\n            $baseDir = ltrim(strrchr($savePath, ';'), ';');\n        }\n\n        if ($baseDir && !is_dir($baseDir) && !@mkdir($baseDir, 0o777, true) && !is_dir($baseDir)) {\n            throw new \\RuntimeException(\\sprintf('Session Storage was not able to create directory \"%s\".', $baseDir));\n        }\n\n        if ($savePath !== \\ini_get('session.save_path')) {\n            ini_set('session.save_path', $savePath);\n        }\n        if ('files' !== \\ini_get('session.save_handler')) {\n            ini_set('session.save_handler', 'files');\n        }\n    }\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/Session/Storage/Handler/NativeFileSessionHandler.php#L22-L58","documentation":"NativeFileSessionHandler accepts an optional $savePath which may use PHP's N;-mode;depth;/path format with at most two semicolons (mode and depth). If the string contains more than two ';' separators, it is not a valid save path, and an InvalidArgumentException is thrown.","triggerScenarios":"Passing a $savePath string with more than 2 semicolons to the constructor, or an ini_get('session.save_path') value malformed in the same way (e.g. '0666;2;/tmp/sess;extra').","commonSituations":"Misconfigured php.ini session.save_path; concatenating path segments containing ';' (e.g. PATH-style values or Windows drive letters used incorrectly); hand-built save path strings with typos.","solutions":["Correct the $savePath to contain at most two semicolons, using the 'mode;depth;/path' format (e.g. '2;/tmp/sessions' or '0660;1;/var/lib/php/sessions').","Fix the session.save_path php.ini value if the path comes from ini_get().","Sanitize or validate user/env-supplied save paths before passing them to the handler."],"exampleFix":"// before\n$handler = new NativeFileSessionHandler('0666;2;/tmp/sessions;extra');\n\n// after\n$handler = new NativeFileSessionHandler('0666;2;/tmp/sessions');","handlingStrategy":"validation","validationCode":"$path = $savePath ?? ini_get('session.save_path');\nif (substr_count($path, ';') > 2) {\n    throw new \\InvalidArgumentException(\"Invalid session save_path: $path\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $handler = new NativeFileSessionHandler($savePath);\n} catch (\\InvalidArgumentException $e) {\n    // fall back to a known-good default save path\n}","preventionTips":["Never pass PATH-style or user-input strings containing ';' as save paths.","Use the documented 'mode;depth;/path' format when specifying mode/depth.","Validate ini_get('session.save_path') in smoke tests."],"tags":["sessions","php","configuration","invalid-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}