diff --git a/plugin/social/includes/functions.php b/plugin/social/includes/functions.php index 1ba329735..2234ca597 100644 --- a/plugin/social/includes/functions.php +++ b/plugin/social/includes/functions.php @@ -549,6 +549,18 @@ function social_check_login_before($p_service=''){ if( $mylink ){ + // CSRF 토큰 검증 (popup.php에서 설정한 세션 토큰 확인) + $mylink_token = get_session('ss_social_mylink_token'); + set_session('ss_social_mylink_token', ''); + if (!$mylink_token) { + if ($use_popup == 1 || !$use_popup) { + alert_close('올바른 방법으로 이용해 주십시오.'); + } else { + alert('올바른 방법으로 이용해 주십시오.'); + } + exit; + } + social_user_profile_replace($member['mb_id'], $provider_name, $user_profile); if( is_object( $adapter ) ){ //연결한것은 인증 받은 즉시 로그아웃한다. diff --git a/plugin/social/popup.php b/plugin/social/popup.php index 0dd56d2d4..732dacaeb 100644 --- a/plugin/social/popup.php +++ b/plugin/social/popup.php @@ -17,6 +17,29 @@ if( !$provider_name ){ alert('서비스 이름이 넘어오지 않았습니다.'); } +// 소셜 계정 연결(mylink) CSRF 방어 +if (isset($_REQUEST['mylink']) && !empty($_REQUEST['mylink'])) { + if (!$is_member) { + alert('로그인 후 이용해 주십시오.'); + } + + // 최초 진입(redirect_to_idp 없음) 시에만 Referer 검증 및 세션 토큰 설정 + if (!isset($_REQUEST['redirect_to_idp'])) { + $referer = isset($_SERVER['HTTP_REFERER']) ? trim($_SERVER['HTTP_REFERER']) : ''; + $ref_host = $referer ? @parse_url($referer, PHP_URL_HOST) : ''; + $site_host = defined('G5_URL') ? @parse_url(G5_URL, PHP_URL_HOST) : ''; + + if ($ref_host) $ref_host = preg_replace('/^www\./i', '', $ref_host); + if ($site_host) $site_host = preg_replace('/^www\./i', '', $site_host); + + if (!$ref_host || !$site_host || strcasecmp($ref_host, $site_host) !== 0) { + alert_close('올바른 방법으로 이용해 주십시오.'); + } + + set_session('ss_social_mylink_token', md5(uniqid(rand(), true))); + } +} + if( isset( $_REQUEST["redirect_to_idp"] ) ){ $content = social_check_login_before();