Skip to content

Commit b33b64e

Browse files
Merge pull request #537 from OpenTouryoProject/3rd_agent
3rd agent
2 parents 28d062e + 24e4e8a commit b33b64e

12 files changed

Lines changed: 532 additions & 3 deletions

File tree

GitHubUsage.md

Lines changed: 314 additions & 0 deletions
Large diffs are not rendered by default.

root/programs/CS/Frameworks/Infrastructure/Framework/Util/FxCmnFunction.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
//* 2018/01/31 西野 大介 ネストしたユーザ コントロールに対応(senderで親UCを確認する)
5656
//* 2018/03/29 西野 大介 .NET Standard対応で、削除機能に関連するメソッドを削除
5757
//* 2018/03/29 西野 大介 .NET Standard対応で、HttpCookieのポーティング
58+
//* 2026/08/10 玄人 幸道 Cookie に Secure 属性を設定(HTTPS のときのみ。CodeQL 対応)
5859
//**********************************************************************************
5960

6061
using Touryo.Infrastructure.Framework.Exceptions;
@@ -964,6 +965,11 @@ public static void CreateCookieForSessionTimeoutDetection()
964965
// HttpOnly属性を設定
965966
cookieOptions.HttpOnly = true;
966967

968+
// Secure属性を設定(CodeQL: Cookie 'Secure' attribute is not set to true)
969+
// HTTPSのときだけ立てる。無条件にtrueにすると、HTTPで動かす
970+
// 開発環境やサンプルでブラウザがCookieを保存しなくなるため。
971+
cookieOptions.Secure = MyHttpContext.Current.Request.IsHttps;
972+
967973
// 設定
968974
responseCookies.Set(
969975
FxHttpCookieIndex.SESSION_TIMEOUT,
@@ -998,6 +1004,11 @@ public static void DeleteCookieForSessionTimeoutDetection()
9981004
// HttpOnly属性を設定
9991005
cookieOptions.HttpOnly = true;
10001006

1007+
// Secure属性を設定(CodeQL: Cookie 'Secure' attribute is not set to true)
1008+
// HTTPSのときだけ立てる。無条件にtrueにすると、HTTPで動かす
1009+
// 開発環境やサンプルでブラウザがCookieを保存しなくなるため。
1010+
cookieOptions.Secure = MyHttpContext.Current.Request.IsHttps;
1011+
10011012
// 設定
10021013
responseCookies.Set(FxHttpCookieIndex.SESSION_TIMEOUT, "", cookieOptions);
10031014
}
@@ -1032,6 +1043,11 @@ HttpCookie newCookie
10321043
// HttpOnly属性を設定
10331044
newCookie.HttpOnly = true;
10341045

1046+
// Secure属性を設定(CodeQL: Cookie 'Secure' attribute is not set to true)
1047+
// HTTPSのときだけ立てる。無条件にtrueにすると、HTTPで動かす
1048+
// 開発環境やサンプルでブラウザがCookieを保存しなくなるため。
1049+
newCookie.Secure = HttpContext.Current.Request.IsSecureConnection;
1050+
10351051
// セッションタイムアウト検出用Cookie(データ有)
10361052
return newCookie;
10371053
}
@@ -1066,6 +1082,11 @@ HttpCookie newCookie
10661082
// HttpOnly属性を設定
10671083
newCookie.HttpOnly = true;
10681084

1085+
// Secure属性を設定(CodeQL: Cookie 'Secure' attribute is not set to true)
1086+
// HTTPSのときだけ立てる。無条件にtrueにすると、HTTPで動かす
1087+
// 開発環境やサンプルでブラウザがCookieを保存しなくなるため。
1088+
newCookie.Secure = HttpContext.Current.Request.IsSecureConnection;
1089+
10691090
// セッションタイムアウト検出用Cookie(データ空)
10701091
return newCookie;
10711092
}

root/programs/CS/Frameworks/Infrastructure/Public/Security/EnumSymmetricAlgorithm.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
//* 日時 更新者 内容
2929
//* ---------- ---------------- -------------------------------------------------
3030
//* 2018/10/30 西野 大介 新規作成(分離)
31+
//* 2026/08/10 玄人 幸道 CipherMode_ECB を非推奨化(CodeQL: Encryption using ECB)
3132
//**********************************************************************************
3233

3334
using System;
@@ -90,6 +91,12 @@ public enum EnumSymmetricAlgorithm
9091
/// <summary>CipherMode.CTS</summary>
9192
CipherMode_CTS = 1 << 10,
9293
/// <summary>CipherMode.ECB</summary>
94+
/// <remarks>
95+
/// ECB は各ブロックを独立に暗号化するため、同じ平文ブロックが常に同じ暗号文ブロックになる。
96+
/// 平文のパターンが暗号文に透け、ブロックの入れ替え・削除・再利用にも耐えない。
97+
/// 指定しなければ .NET の既定である CBC が使われる。
98+
/// </remarks>
99+
[Obsolete("CipherMode_ECB is deprecated, please use CipherMode_CBC instead.")]
93100
CipherMode_ECB = 1 << 11,
94101
/// <summary>CipherMode.OFB</summary>
95102
CipherMode_OFB = 1 << 12,

root/programs/CS/Frameworks/Infrastructure/Public/Security/SymmetricCryptography.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//**********************************************************************************
1+
//**********************************************************************************
22
//* Copyright (C) 2007,2016 Hitachi Solutions,Ltd.
33
//**********************************************************************************
44

@@ -41,6 +41,7 @@
4141
//* 2018/10/30 西野 大介 各種プロバイダのサポートを追加
4242
//* 2018/10/30 西野 大介 CipherMode, PaddingMode指定の追加(CipherModeによってはIVを無視する)。
4343
//* 2018/11/09 西野 大介 インスタンス・メソッド化
44+
//* 2026/08/10 玄人 幸道 CipherMode_ECB 非推奨化に伴う CS0618 の抑止(CodeQL 対応)
4445
//**********************************************************************************
4546

4647
using System;
@@ -282,10 +283,14 @@ private SymmetricAlgorithm CreateSymmetricAlgorithm(EnumSymmetricAlgorithm esa)
282283
{
283284
cm = CipherMode.CTS;
284285
}
286+
// CipherMode_ECB は非推奨だが、指定された場合は従来どおり動作させる(下位互換)。
287+
// 参照するだけで CS0618 が出るため、この分岐に限って抑止する。
288+
#pragma warning disable CS0618
285289
else if (esa.HasFlag(EnumSymmetricAlgorithm.CipherMode_ECB))
286290
{
287291
cm = CipherMode.ECB;
288292
}
293+
#pragma warning restore CS0618
289294
else if (esa.HasFlag(EnumSymmetricAlgorithm.CipherMode_OFB))
290295
{
291296
cm = CipherMode.OFB;

root/programs/CS/Frameworks/Infrastructure/ServiceInterface/ASPNETWebService/Web.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,13 @@
188188
</dependentAssembly>
189189
</assemblyBinding>
190190
</runtime>
191+
<system.webServer>
192+
<httpProtocol>
193+
<customHeaders>
194+
<!-- クリックジャッキング対策(CodeQL: Missing X-Frame-Options HTTP header)。
195+
SOAP の Web サービスであり、フレームに表示する用途がないため DENY。 -->
196+
<add name="X-Frame-Options" value="DENY" />
197+
</customHeaders>
198+
</httpProtocol>
199+
</system.webServer>
191200
</configuration>

root/programs/CS/Samples/WebApp_sample/MVC_Sample/MVC_Sample/Web.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@
142142
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61.aspx
143143
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61(VS.80).aspx
144144
-->
145+
<!-- **本番では、下の requireSSL="false" の行をコメントアウトし、
146+
この requireSSL="true" の行のコメントアウトを外すこと。**
147+
認証 Cookie が HTTPS でのみ送信されるようになる
148+
(CodeQL: 'requireSSL' attribute is not set to true)。
149+
サンプルは HTTP で動かすため、既定は false のままにしてある。
150+
<forms name="formauth" loginUrl="Home/Login" defaultUrl="Home" timeout="10" protection="All" path="/" domain="" requireSSL="true" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile"/>
151+
-->
145152
<forms name="formauth" loginUrl="Home/Login" defaultUrl="Home" timeout="10" protection="All" path="/" domain="" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile"/>
146153
</authentication>
147154
<!--
@@ -210,6 +217,15 @@
210217
</system.web>
211218
</location>
212219
<system.webServer>
220+
<httpProtocol>
221+
<customHeaders>
222+
<!-- クリックジャッキング対策(CodeQL: Missing X-Frame-Options HTTP header)。
223+
MVC 版の Scripts/touryo/common.js は iframe を使わないため DENY でよい。
224+
WebForms 版は擬似ダイアログ(FxIFrame)で同一オリジンの iframe を使うので
225+
そちらだけ SAMEORIGIN にしてある。 -->
226+
<add name="X-Frame-Options" value="DENY" />
227+
</customHeaders>
228+
</httpProtocol>
213229
<validation validateIntegratedModeConfiguration="false"/>
214230
<handlers>
215231
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>

root/programs/CS/Samples/WebApp_sample/WebForms_Sample/WebForms_Sample/Scripts/touryo/common.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,46 @@ function Fx_InitPseudoDialog() {
585585

586586
}
587587

588+
// ---------------------------------------------------------------
589+
// 擬似DialogのiframeへURLを設定してよいかを判定
590+
// ---------------------------------------------------------------
591+
// 引数 url
592+
// 戻り値 true : 設定してよい / false : 設定しない
593+
// ---------------------------------------------------------------
594+
// このURLはフレームワーク(ShowModalScreen)が組み立てており、
595+
// 利用者の入力は入ってこない。AppScanのテストもクリアしている。
596+
// ここでの検証は、サンプルを手本にしたコードが動的なURLを
597+
// 流し込んだ場合に備える多層防御である。
598+
// ・javascript: / data: / vbscript: … スクリプト実行を防ぐ
599+
// ・//evil.example.com … 別オリジンの表示を防ぐ
600+
// 相対URL(Aspx/... や /App/... )だけを通す。
601+
// ---------------------------------------------------------------
602+
function Fx_IsSafeDialogUrl(url) {
603+
604+
if (typeof url !== "string" || url === "") {
605+
return false;
606+
}
607+
608+
// 前後の空白と制御文字を除いてから判定する
609+
// ("java\tscript:" のような細工を防ぐ)。
610+
var u = url.replace(/[\u0000-\u0020]/g, "");
611+
612+
// スキーム付きは、http / https だけを通す。
613+
var scheme = u.match(/^([A-Za-z][A-Za-z0-9+.-]*):/);
614+
if (scheme) {
615+
var s = scheme[1].toLowerCase();
616+
return (s === "http" || s === "https");
617+
}
618+
619+
// "//host/path" はプロトコル相対=別オリジンになり得るので通さない。
620+
if (u.indexOf("//") === 0) {
621+
return false;
622+
}
623+
624+
// ここまで来たものは相対URL。
625+
return true;
626+
}
627+
588628
// ---------------------------------------------------------------
589629
// Pseudo Dialog表示
590630
// ---------------------------------------------------------------
@@ -606,7 +646,16 @@ function Fx_DisplayPseudoDialog(ajaxPseudoDialog, url) {
606646
for (var i = 0; i < elementChildren.length; i++) {
607647
if (elementChildren[i].id === "FxIFrame")
608648
{
609-
elementChildren[i].src = url;
649+
// URLを検証してから設定する(CodeQL: DOM text reinterpreted as HTML)。
650+
if (Fx_IsSafeDialogUrl(url)) {
651+
elementChildren[i].src = url;
652+
}
653+
else {
654+
// 通さなかったことが分かるようにする(画面は空のままになる)。
655+
if (window.console && window.console.error) {
656+
window.console.error("Fx_DisplayPseudoDialog: unsafe url was blocked.");
657+
}
658+
}
610659
}
611660
}
612661

root/programs/CS/Samples/WebApp_sample/WebForms_Sample/WebForms_Sample/Web.config

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@
136136
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61.aspx
137137
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61(VS.80).aspx
138138
-->
139+
<!-- **本番では、下の requireSSL="false" の行をコメントアウトし、
140+
この requireSSL="true" の行のコメントアウトを外すこと。**
141+
認証 Cookie が HTTPS でのみ送信されるようになる
142+
(CodeQL: 'requireSSL' attribute is not set to true)。
143+
サンプルは HTTP で動かすため、既定は false のままにしてある。
144+
<forms name="formauth" loginUrl="Aspx/Start/login.aspx" defaultUrl="Aspx/Start/menu.aspx" timeout="10" protection="All" path="/" domain="" requireSSL="true" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" />
145+
-->
139146
<forms name="formauth" loginUrl="Aspx/Start/login.aspx" defaultUrl="Aspx/Start/menu.aspx" timeout="10" protection="All" path="/" domain="" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" />
140147
</authentication>
141148
<!--
@@ -417,4 +424,14 @@
417424
</dependentAssembly>
418425
</assemblyBinding>
419426
</runtime>
427+
<system.webServer>
428+
<httpProtocol>
429+
<customHeaders>
430+
<!-- クリックジャッキング対策(CodeQL: Missing X-Frame-Options HTTP header)。
431+
**DENY ではなく SAMEORIGIN。** 擬似ダイアログが同一オリジンの iframe を使う
432+
(Scripts/touryo/common.js の FxIFrame)。DENY にすると動作しなくなる。 -->
433+
<add name="X-Frame-Options" value="SAMEORIGIN" />
434+
</customHeaders>
435+
</httpProtocol>
436+
</system.webServer>
420437
</configuration>

root/programs/VB/Frameworks/Infrastructure/ServiceInterface/ASPNETWebService/ASPNETWebService/Web.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,13 @@
188188
</dependentAssembly>
189189
</assemblyBinding>
190190
</runtime>
191+
<system.webServer>
192+
<httpProtocol>
193+
<customHeaders>
194+
<!-- クリックジャッキング対策(CodeQL: Missing X-Frame-Options HTTP header)。
195+
SOAP の Web サービスであり、フレームに表示する用途がないため DENY。 -->
196+
<add name="X-Frame-Options" value="DENY" />
197+
</customHeaders>
198+
</httpProtocol>
199+
</system.webServer>
191200
</configuration>

root/programs/VB/Samples/WebApp_sample/MVC_Sample/MVC_Sample/Web.config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@
146146
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61.aspx
147147
http://msdn2.microsoft.com/ja-jp/library/1d3t3c61(VS.80).aspx
148148
-->
149+
<!-- **本番では、下の requireSSL="false" の行をコメントアウトし、
150+
この requireSSL="true" の行のコメントアウトを外すこと。**
151+
認証 Cookie が HTTPS でのみ送信されるようになる
152+
(CodeQL: 'requireSSL' attribute is not set to true)。
153+
サンプルは HTTP で動かすため、既定は false のままにしてある。
154+
<forms name="formauth" loginUrl="Home/Login" defaultUrl="Home" timeout="10" protection="All" path="/" domain="" requireSSL="true" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" />
155+
-->
149156
<forms name="formauth" loginUrl="Home/Login" defaultUrl="Home" timeout="10" protection="All" path="/" domain="" requireSSL="false" slidingExpiration="true" enableCrossAppRedirects="false" cookieless="UseDeviceProfile" />
150157
</authentication>
151158
<!--
@@ -214,6 +221,15 @@
214221
</system.web>
215222
</location>
216223
<system.webServer>
224+
<httpProtocol>
225+
<customHeaders>
226+
<!-- クリックジャッキング対策(CodeQL: Missing X-Frame-Options HTTP header)。
227+
MVC 版の Scripts/touryo/common.js は iframe を使わないため DENY でよい。
228+
WebForms 版は擬似ダイアログ(FxIFrame)で同一オリジンの iframe を使うので
229+
そちらだけ SAMEORIGIN にしてある。 -->
230+
<add name="X-Frame-Options" value="DENY" />
231+
</customHeaders>
232+
</httpProtocol>
217233
<validation validateIntegratedModeConfiguration="false" />
218234
<handlers>
219235
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />

0 commit comments

Comments
 (0)