Skip to content

Commit d0cb8f9

Browse files
committed
禁止ホストの時はお絵かきコメントの入力欄を表示しない。IPv4の時にのみ逆引き不可ホストを拒絶。
1 parent 345a1a8 commit d0cb8f9

5 files changed

Lines changed: 20 additions & 16 deletions

File tree

petitnote/functions.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ function aikotoba(): void {
3030
check_same_origin();
3131

3232
session_sta();
33-
if(!$aikotoba || $aikotoba!==(string)filter_input_data('POST','aikotoba')){
33+
if(!$aikotoba || !hash_equals($aikotoba,(string)filter_input_data('POST','aikotoba'))){
3434
if(isset($_SESSION['aikotoba'])){
3535
unset($_SESSION['aikotoba']);
3636
}
3737
if((string)filter_input_data('COOKIE','aikotoba')){
3838
setcookie('aikotoba', '', time() - 3600);//クッキーを削除
3939
}
40-
error($en?'The secret word is wrong':'合言葉が違います。');
40+
error($en?'The secret word is wrong.':'合言葉が違います。');
4141
}
4242
if($keep_aikotoba_login_status){
4343
setcookie("aikotoba",$aikotoba, time()+(86400*30),"","",false,true);//1ヶ月
@@ -253,15 +253,15 @@ function admindel_valid(): bool {
253253
}
254254
function userdel_valid(): bool {
255255
session_sta();
256-
return isset($_SESSION['userdel'])&&($_SESSION['userdel']==='userdel_mode');
256+
return isset($_SESSION['userdel'])&& hash_equals($_SESSION['userdel'],'userdel_mode');
257257
}
258258
//合言葉の確認
259259
function aikotoba_valid(): bool {
260260
global $keep_aikotoba_login_status,$aikotoba;
261261
session_sta();
262-
$keep=$keep_aikotoba_login_status ? ($aikotoba && ($aikotoba===(string)filter_input_data('COOKIE','aikotoba'))
262+
$keep=$keep_aikotoba_login_status ? ($aikotoba && hash_equals($aikotoba,(string)filter_input_data('COOKIE','aikotoba'))
263263
) : false;
264-
return ($keep||isset($_SESSION['aikotoba'])&&($_SESSION['aikotoba']==='aikotoba'));
264+
return ($keep||isset($_SESSION['aikotoba'])&& hash_equals($_SESSION['aikotoba'],'aikotoba'));
265265
}
266266

267267
//センシティブコンテンツ
@@ -970,6 +970,11 @@ function check_same_origin(): void {
970970
function check_badhost(): void {
971971
global $en;
972972
if(is_badhost()){
973+
//禁止ホストの管理者ログインを解除
974+
unset($_SESSION['adminpost']);
975+
unset($_SESSION['admindel']);
976+
//編集・削除モードを解除
977+
unset($_SESSION['userdel']);
973978
error($en? 'Rejected.' : '拒絶されました。');
974979
}
975980
}
@@ -1183,6 +1188,7 @@ function is_badhost(): bool {
11831188
$use_badhost_session_cache = $use_badhost_session_cache ?? false;
11841189

11851190
session_sta();
1191+
11861192
$session_is_badhost = $_SESSION['is_badhost'] ?? false; //SESSIONに保存された値を取得
11871193
if($use_badhost_session_cache && $session_is_badhost){//禁止ホストフラグがSESSIONに保存されていたら拒絶
11881194
return true;
@@ -1193,7 +1199,7 @@ function is_badhost(): bool {
11931199

11941200
if($host === $userip){//ホスト名がipアドレスになる場合は
11951201
if($reject_if_no_reverse_dns){
1196-
if(filter_var($userip, FILTER_VALIDATE_IP,FILTER_FLAG_IPV4)){//IPv4アドレスなら
1202+
if(!$host || filter_var($userip, FILTER_VALIDATE_IP,FILTER_FLAG_IPV4)){//IPv4アドレスなら
11971203
$_SESSION['is_badhost'] = true;
11981204
return true; //リバースDNSがない場合は拒絶
11991205
}

petitnote/index.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
//Petit Note (c)さとぴあ @satopian 2021-2025
33
//1スレッド1ログファイル形式のスレッド式画像掲示板
4-
$petit_ver='v1.92.0';
4+
$petit_ver='v1.92.2';
55
$petit_lot='lot.20250614';
66

77
$lang = ($http_langs = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '')
@@ -1065,6 +1065,8 @@ function paintcom(): void {
10651065
}
10661066
}
10671067
$aikotoba = $use_aikotoba ? aikotoba_valid() : true;
1068+
//禁止ホストにはコメント入力欄を表示しない
1069+
$aikotoba = is_badhost() ? false : $aikotoba;
10681070

10691071
$namec=h((string)filter_input_data('COOKIE','namec'));
10701072
$pwdc=h((string)filter_input_data('COOKIE','pwdc'));
@@ -2052,10 +2054,10 @@ function edit(): void {
20522054
function del(): void {
20532055
global $en;
20542056

2055-
//投稿間隔をチェック
2056-
check_submission_interval();
20572057
//禁止ホストをチェック
20582058
check_badhost();
2059+
//投稿間隔をチェック
2060+
check_submission_interval();
20592061

20602062
check_csrf_token();
20612063

@@ -2435,8 +2437,6 @@ function view(): void {
24352437
$select_app=($count_arr_apps>1);
24362438
$app_to_use=($count_arr_apps===1) ? $arr_apps[0] : '';
24372439

2438-
$use_paint = $is_badhost ? false : $use_paint; //禁止ホストの時はペイントアプリを使用しない
2439-
24402440
//token
24412441
$token=get_csrf_token();
24422442

@@ -2650,8 +2650,6 @@ function res (): void {
26502650
$select_app=($count_arr_apps>1);
26512651
$app_to_use=($count_arr_apps===1) ? $arr_apps[0] : '';
26522652

2653-
$use_paint = $is_badhost ? false : $use_paint; //禁止ホストの時はペイントアプリを使用しない
2654-
26552653
//token
26562654
$token=get_csrf_token();
26572655

petitnote/template/basic/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h1 class="title"><a href="./"><?=h($boardname)?></a></h1>
3737
<span>
3838
<?php if($userdel || $admindel):?>
3939
[<a href="./?mode=logout" rel="nofollow"><?php if($en):?>Exit edit mode<?php else:?>編集モード終了<?php endif;?></a>]
40-
<?php elseif($resform):?>
40+
<?php elseif(!$is_badhost):?>
4141
[<a href="./?mode=userdel" rel="nofollow"><?php if($en):?>Edit<?php else:?>編集<?php endif;?></a>]
4242
<?php endif;?>
4343
<?php endif;?>

petitnote/template/basic/parts/threads_loop.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h3 class="imginfo_wrap">
123123
<?php if($aikotoba && !$deny_all_posts && (((!isset($res['not_deleted'])||$res['not_deleted']) && $userdel) || $admindel)):?>
124124
<div class="edit_button">
125125
<!-- 編集削除のためのボタン -->
126-
<?php if($res['check_elapsed_days']&&!$is_badhost||$admindel):?>
126+
<?php if($res['check_elapsed_days']||$admindel):?>
127127
<form action="./" method="POST" class="aikotoba">
128128
<input type="hidden" name="mode" value="before_del">
129129
<input type="hidden" name="edit_mode" value="editmode">

petitnote/template/basic/res.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1 class="title"><a href="./"><?=h($boardname)?></a></h1>
4848
<span>
4949
<?php if($userdel || $admindel):?>
5050
[<a href="./?mode=logout" rel="nofollow"><?php if($en):?>Exit edit mode<?php else:?>編集モード終了<?php endif;?></a>]
51-
<?php elseif($resform):?>
51+
<?php elseif(!$is_badhost):?>
5252
[<a href="./?mode=userdel" rel="nofollow"><?php if($en):?>Edit<?php else:?>編集<?php endif;?></a>]
5353
<?php endif;?>
5454
<?php endif;?>

0 commit comments

Comments
 (0)