X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=blobdiff_plain;f=includes%2FTemplateParser.php;h=2759ff9baa8d9b91240e061dd9939916324f3c85;hb=0a176a1e01d67d6a15dc9435a57018d5082e1b35;hp=f581a80fbb11aaaa81b683d8a334dfe4b26c2ebe;hpb=5b753f715ff4bb9c10c573c3ab5f911c085defef;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/TemplateParser.php b/includes/TemplateParser.php index f581a80fbb..2759ff9baa 100644 --- a/includes/TemplateParser.php +++ b/includes/TemplateParser.php @@ -102,27 +102,27 @@ class TemplateParser { $key = $cache->makeKey( 'template', $templateName, $fastHash ); $code = $this->forceRecompile ? null : $cache->get( $key ); - if ( !$code ) { - $code = $this->compileForEval( $fileContents, $filename ); - - // Prefix the cached code with a keyed hash (64 hex chars) as an integrity check - $cache->set( $key, hash_hmac( 'sha256', $code, $secretKey ) . $code ); - } else { + if ( $code ) { // Verify the integrity of the cached PHP code $keyedHash = substr( $code, 0, 64 ); $code = substr( $code, 64 ); if ( $keyedHash !== hash_hmac( 'sha256', $code, $secretKey ) ) { - // Generate a notice if integrity check fails - trigger_error( "Template failed integrity check: {$filename}" ); + // If the integrity check fails, don't use the cached code + // We'll update the invalid cache below + $code = null; } } + if ( !$code ) { + $code = $this->compileForEval( $fileContents, $filename ); + + // Prefix the cached code with a keyed hash (64 hex chars) as an integrity check + $cache->set( $key, hash_hmac( 'sha256', $code, $secretKey ) . $code ); + } // If there is no secret key available, don't use cache } else { $code = $this->compileForEval( $fileContents, $filename ); } - echo "About to eval:\n"; - echo $code; $renderer = eval( $code ); if ( !is_callable( $renderer ) ) { throw new RuntimeException( "Requested template, {$templateName}, is not callable" );