Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
오픈 리다이렉트 유저 패스워드 Leak 취약점 수정 adm1nkyj@UpRoot님이 알려주심
Browse files Browse the repository at this point in the history
  • Loading branch information
thisgun committed Sep 11, 2017
1 parent 69654a6 commit f39ac3c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/common.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3003,15 +3003,32 @@ function check_url_host($url, $msg='', $return_url=G5_URL)

$p = @parse_url($url);
$host = preg_replace('/:[0-9]+$/', '', $_SERVER['HTTP_HOST']);
$is_host_check = false;

if(stripos($url, 'http:') !== false) {
if(!isset($p['scheme']) || !$p['scheme'] || !isset($p['host']) || !$p['host'])
alert('url 정보가 올바르지 않습니다.', $return_url);
}

if ((isset($p['scheme']) && $p['scheme']) || (isset($p['host']) && $p['host'])) {
//php 5.6.29 이하 버전에서는 parse_url 버그가 존재함
if ( (isset($p['host']) && $p['host']) && version_compare(PHP_VERSION, '5.6.29') < 0) {
$bool_ch = false;
foreach( array('user','host') as $key) {
if ( isset( $p[ $key ] ) && strpbrk( $p[ $key ], ':/?#@' ) ) {
$bool_ch = true;
}
}
if( $bool_ch ){
$regex = '/https?\:\/\/'.$host.'/i';
if( ! preg_match($regex, $url) ){
$is_host_check = true;
}
}
}

if ((isset($p['scheme']) && $p['scheme']) || (isset($p['host']) && $p['host']) || $is_host_check) {
//if ($p['host'].(isset($p['port']) ? ':'.$p['port'] : '') != $_SERVER['HTTP_HOST']) {
if ($p['host'] != $host) {
if ( ($p['host'] != $host) || $is_host_check ) {
echo '<script>'.PHP_EOL;
echo 'alert("url에 타 도메인을 지정할 수 없습니다.");'.PHP_EOL;
echo 'document.location.href = "'.$return_url.'";'.PHP_EOL;
Expand Down

0 comments on commit f39ac3c

Please sign in to comment.