界: Code Quality

コードの質が低いと、予測できない動作につながります。ユーザーの視点には、それがしばしば使い勝手の悪さとなって現れます。攻撃者にとっては、予期せぬ方法でシステムにストレスを与える機会となります。

93 見つかった項目
脆弱性
Abstract
プログラムは管理対象外のシステムリソースを使用する管理対象オブジェクトを適切に処理できません。
Explanation
プログラムは管理対象外のシステムリソースを使用する管理対象オブジェクトを適切に処理できません。
管理対象外のシステムリソースを使用する管理対象オブジェクトを適切に処理できない場合には、少なくとも 2 つの原因があります。

- エラー条件などの例外的状況。
- プログラムのどの部分がリソースを解放するかに関する混乱。

管理対象 .NET オブジェクトの小さなサブセットは、管理対象外のシステムリソースを使用します。.NET のガベージコレクタは、予測できる方法で、元の管理対象オブジェクトを解放しない場合があります。この場合、ガベージコレクタが管理対象外のリソースにより消費されるメモリを認識しないため、アプリケーションが利用可能なメモリをすべて消費してしまう可能性があります。管理対象外のリソース リークの問題点の大半は、一般にソフトウェアの信頼性の問題をもたらします。しかし攻撃者による意図的な管理対象外のリソース リークが可能な場合、攻撃者は管理対象外のリソース プールを枯渇させることにより、Denial of Service 攻撃を開始する可能性があります。

例 1: 次のメソッドでは、受信したストリーム incomingStream から管理対象の Bitmap オブジェクトを作成しています。この Bitmap は処理され、送信ストリーム outgoingStream に残ります。incomingBitmap および outgoingBitmapDispose() メソッドは明示的にコールされていません。

通常は、管理対象外のシステムリソースを使用しない管理対象オブジェクトについては、ガベージコレクタを信頼して、安全にこの処理を実行させることができます。ガベージ コレクタは、Bitmap を見つけると、Bitmap.Dispose() をコールします。しかし、この Bitmap オブジェクトは、まれな、管理対象外のシステム リソースを使用しています。そのため、ガベージ コレクタは、Dispose() をコールできずに、管理対象外のリソース プールが枯渇してしまう可能性があります。


private void processBitmap(Stream incomingStream, Stream outgoingStream, int thumbnailSize)
{
Bitmap incomingBitmap = (Bitmap)System.Drawing.Image.FromStream(incomingStream);

bool validBitmap = validateBitmap(incomingBitmap);
if (!validBitmap)
throw new ValidationException(incomingBitmap);

Bitmap outgoingBitmap = new Bitmap(incomingBitmap, new Size(thumbnailSize, thumbnailSize));
outgoingBitmap.Save(outgoingStream, ImageFormat.Bmp);
}
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 3
[3] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[4] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[5] Standards Mapping - Common Weakness Enumeration CWE ID 772
[6] Standards Mapping - Common Weakness Enumeration Top 25 2019 [21] CWE ID 772
[7] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[8] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[9] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[10] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[11] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.9
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.6
[13] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.6
[14] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.6
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.6
[16] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[17] Standards Mapping - Payment Card Industry Software Security Framework 1.0 Control Objective 4.2 - Critical Asset Protection
[18] Standards Mapping - Payment Card Industry Software Security Framework 1.1 Control Objective 4.2 - Critical Asset Protection
[19] Standards Mapping - Payment Card Industry Software Security Framework 1.2 Control Objective 4.2 - Critical Asset Protection, Control Objective C.3.3 - Web Software Attack Mitigation
[20] Standards Mapping - SANS Top 25 2009 Risky Resource Management - CWE ID 404
[21] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[34] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[35] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[36] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[37] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[38] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[39] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[40] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[41] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[42] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[43] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.controlflow.dotnet.unreleased_resource_unmanaged_object
Abstract
メモリを解放した後で参照するとプログラムのクラッシュを引き起こす可能性があります。
Explanation
ポインタを解放した後で、プログラムがそのポインタを使用し続ける場合に、Use After Free エラーが発生します。Double Free エラーや Memory Leak と同様に、Use After Free エラーには 2 つの一般的な原因があり、これらが重なっていることもあります。

- エラー条件などの例外的状況。

- プログラムのどの部分でメモリを解放するかに関して混乱が発生している。

Use After Free エラーは、何も影響を生じないこともありますが、プログラムをクラッシュさせることがあります。技術的には、解放されたメモリの再割り当てが可能であり、この再割り当てを使用した Buffer Overflow 攻撃も可能ですが、このタイプの攻撃に基づく悪用には気が付きません。

例: 次のコードは Use After Free エラーの例です。


char* ptr = (char*)malloc (SIZE);
...
if (err) {
abrt = 1;
free(ptr);
}
...
if (abrt) {
logError("operation aborted before commit", ptr);
}
desc.controlflow.cpp.use_after_free