{"record":{"id":"c246d43c684e4d38","repo":"getgrav/grav","slug":"failed-to-write-nonce-key-file","errorCode":null,"errorMessage":"Failed to write nonce key file","messagePattern":"Failed to write nonce key file","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Common/Security.php","lineNumber":2022,"sourceCode":"        self::writeNonceKey($privateFile, $generated);\n\n        return self::$nonceKey = $generated;\n    }\n\n    private static function writeNonceKey(string $path, string $value): void\n    {\n        $escaped = var_export($value, true);\n        $contents = \"<?php\\n\\n// Auto-generated private secret. Do NOT commit to version control.\\n// Used for CSRF nonce signing and admin rate-limit hashing. Regenerate by\\n// deleting this file; the next request will write a new value.\\n\\nreturn {$escaped};\\n\";\n\n        $dir = dirname($path);\n        if (!is_dir($dir)) {\n            Folder::create($dir);\n        }\n\n        // Atomic write: stage to a temp file, fsync via rename.\n        $tmp = $path . '.tmp';\n        if (@file_put_contents($tmp, $contents, LOCK_EX) === false) {\n            throw new RuntimeException('Failed to write nonce key file');\n        }\n        @chmod($tmp, 0600);\n        if (!@rename($tmp, $path)) {\n            @unlink($tmp);\n            throw new RuntimeException('Failed to commit nonce key file');\n        }\n    }\n}\n","sourceCodeStart":2004,"sourceCodeEnd":2031,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Common/Security.php#L2004-L2031","documentation":"Error \"Failed to write nonce key file\" thrown in getgrav/grav.","triggerScenarios":"Thrown at system/src/Grav/Common/Security.php:2022 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}