Skip to content

Commit

Permalink
どんぐりクッキー削除してない専ブラ向け緩和措置
Browse files Browse the repository at this point in the history
そんなブラウザが存在するかはともかく。どんぐりが枯れた次のレス投稿時にacornクッキーを送信しないようにする
  • Loading branch information
onihusube committed Apr 16, 2024
1 parent 9421099 commit c38805a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
39 changes: 34 additions & 5 deletions 2chAPIProxy/DatProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -891,18 +891,43 @@ private void ResPost(Session oSession, bool is2ch)
Write.Referer = referer;

if (string.IsNullOrEmpty(Proxy) == false) Write.Proxy = new WebProxy(Proxy);

Write.CookieContainer = new CookieContainer();
//送信されてきたクッキーを抽出
foreach (Match mc in Regex.Matches(oSession.oRequest.headers["Cookie"], @"(?:\s+|^)((.+?)=(?:|.+?)(?:;|$))"))

// どんぐり枯れレスポンスを検知するマーカー
const string mark_acorn_dride_up = "ignore next acorn";
// どんぐりクッキー名
const string acorn_cookie = "acorn";

{
Cookie[mc.Groups[2].Value] = mc.Groups[1].Value;
bool ignore_acorn = false;

// どんぐりが枯れた次のレス投稿の場合、acornを送らない
if (Cookie.ContainsKey(acorn_cookie) && Cookie[acorn_cookie] == mark_acorn_dride_up)
{
ignore_acorn = true;
Cookie[acorn_cookie] = "";
}

//送信されてきたクッキーを抽出
foreach (Match mc in Regex.Matches(oSession.oRequest.headers["Cookie"], @"(?:\s+|^)((.+?)=(?:|.+?)(?:;|$))"))
{
Cookie[mc.Groups[2].Value] = mc.Groups[1].Value;
}

// acornクッキーを削除し、送らないようにする
if (ignore_acorn)
{
Cookie.Remove(acorn_cookie);
}
}

Cookie.Remove("sid");
Cookie.Remove("SID");

// TAKO=ODORIを消す
Cookie.Remove("TAKO");


//送信クッキーのセット
String domain = CheckWriteuri.Match(oSession.fullUrl).Groups[1].Value;
foreach (var cook in Cookie.Where(c => string.IsNullOrEmpty(c.Value) == false))
Expand All @@ -917,6 +942,7 @@ private void ResPost(Session oSession, bool is2ch)
continue;
}
}

//浪人を無効化
if (ViewModel.Setting.PostRoninInvalid && ReqBody.Contains("sid="))
{
Expand Down Expand Up @@ -950,6 +976,8 @@ private void ResPost(Session oSession, bool is2ch)
}

HttpWebResponse wres = (HttpWebResponse)Write.GetResponse();

// Set-Cookieの抽出
if (wres.Cookies.Count > 0)
{
var cul = new System.Globalization.CultureInfo("en-US");
Expand All @@ -970,7 +998,8 @@ private void ResPost(Session oSession, bool is2ch)
if (wres.Headers["X-Chx-Error"].Contains("1930"))
{
// どんぐり枯れを検知したら、acornクッキーを削除する
Cookie["acorn"] = "";
// 本当に削除するのは、次の投稿時
Cookie[acorn_cookie] = mark_acorn_dride_up;
}
ViewModel.OnModelNotice("X-Chx-Error : " + wres.Headers["X-Chx-Error"]);
}
Expand Down
2 changes: 1 addition & 1 deletion 2chAPIProxy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:_2chAPIProxy" mc:Ignorable="d" x:Class="_2chAPIProxy.MainWindow"
Title="2chAPIProxy Ver:2024.04.16 nonAPI test" Height="480" Width="640"
Title="2chAPIProxy Ver:2024.04.17 nonAPI test" Height="480" Width="640"
Icon="icon3.ico" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="White" d:DataContext="{d:DesignInstance {x:Type local:ViewModel}}">
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+S" Command="{Binding SaveSetting}"/>
Expand Down

1 comment on commit c38805a

@onihusube
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#14

Please sign in to comment.