" . $column . " -> " . $ref; } // Extract signature if already one present $purecode = $code; if (substr($code, 0, 5) == "//SIG") { $purecode = trim(substr($code, strpos($code, "\n") + 1)); } if (trim(eval_check_signed($code)) !== trim($purecode)) { // Code is not signed. // Needs signing. Confirm it's safe. if ($confirm) { if (!$output_changes_only) { echo " needs signing\n-----------------------------\n"; echo $purecode; echo "\n-----------------------------\nIs this code safe? (y/n)"; ob_flush(); $line = fgets(STDIN); if (trim($line) != "y") { exit(); } } else { echo $table . " -> " . $column . " -> " . $ref . "\n" . $code . "\n\n"; } } $code = trim($code); $code = "//SIG" . sign_code($code) . "\n" . $code; if (!$output_changes_only) { ps_query("update `$table` set `$column`=? where ref=?", array("s",$code,"i",$ref)); } } else { if ($output && !$output_changes_only) { echo " is OK\n"; } } } } // Clear the cache so the code uses the updated signed code. if (!$output_changes_only) { clear_query_cache("schema"); set_sysvar("code_sign_required", ""); } } /** * Used to compare the user's provided token with the expected value derived from the given identifier * * Used by isValidCSRFToken() * Also used on upload_batch to validate an upload session when user cookie not available (i.e. companion uploads) * * @uses rsDecrypt() * * @param string $token_data Encrypted token data * @param string $id Identifier * * @return bool * */ function rs_validate_token($token_data, $id) { if (trim($token_data) === "") { debug("rs_validate_token(): INVALID - no token data"); return false; } $plaintext = rsDecrypt($token_data, $id); if ($plaintext === false) { debug("rs_validate_token(): INVALID - unable to decrypt token data"); return false; } $csrf_data = json_decode($plaintext, true); if (is_null($csrf_data)) { debug("rs_validate_token(): INVALID - unable to decode token data"); return false; } if ($csrf_data["session"] === $id) { return true; } debug("rs_validate_token(): INVALID - decoded value does not match"); return false; }