diff -r e53cf8b1d942 -r 75df0b2c596c includes/functions.php --- a/includes/functions.php Sat Jun 07 12:43:57 2008 -0400 +++ b/includes/functions.php Sat Jun 07 12:46:18 2008 -0400 @@ -391,6 +391,91 @@ } +/** + * Generates a confirmation form if a CSRF check fails. Will terminate execution. + */ + +function csrf_confirm_form() +{ + global $db, $session, $paths, $template, $plugins; // Common objects + global $lang; + + // If the token was overridden with the correct one, the user confirmed the action using this form. Continue exec. + if ( isset($_POST['cstok']) || isset($_GET ['cstok']) ) + { + // using the if() check makes sure that the token isn't in a cookie, since $_REQUEST includes $_COOKIE. + $token_check =& $_REQUEST['cstok']; + if ( $token_check === $session->csrf_token ) + { + // overridden token matches, continue exec + return true; + } + } + + $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($lang->get('user_csrf_confirm_title')); + $template->header(); + + // initial info + echo '
' . $lang->get('user_csrf_confirm_body') . '
'; + + // start form + $form_method = ( empty($_POST) ) ? 'get' : 'post'; + echo ''; + + $template->footer(); + + exit; +} + +function csrf_confirm_get_recursive($_inner = false, $pfx = false, $data = false) +{ + // make posted arrays work right + if ( !$data ) + ( $_inner == 'post' ) ? $data =& $_POST : $data =& $_GET; + foreach ( $data as $key => $value ) + { + $pfx_this = ( empty($pfx) ) ? $key : "{$pfx}[{$key}]"; + if ( is_array($value) ) + { + csrf_confirm_get_recursive(true, $pfx_this, $value); + } + else if ( empty($value) ) + { + echo htmlspecialchars($pfx_this . " =