계: Code Quality

코드 품질이 낮으면 예측할 수 없는 동작이 발생합니다. 사용자 입장에서는 사용 편의성이 떨어지는 것으로 나타나는 경우가 많습니다. 공격자에게는 예상치 못한 방법으로 시스템에 부담을 줄 수 있는 기회가 됩니다.

93 개 항목 찾음
취약점
Abstract
스택 버퍼를 해제하면 예상치 않은 프로그램 동작이 발생합니다.
Explanation
스택 메모리를 명시적으로 할당 해제합니다. 스택 버퍼를 정의하는 함수는 함수가 반환할 때 버퍼를 자동으로 할당 제거합니다.
예제:

void clean_up()
{
char tmp[256];
...
free(tmp);
return;
}


명시적으로 스택 메모리를 해제하면 메모리 할당 데이터 구조를 손상시킬 수 있습니다. 비정상적으로 프로그래밍 종료되거나 데이터가 더 크게 손상될 수 있습니다.
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[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 730
[6] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[7] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 22.2
[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 - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[13] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[14] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[15] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[16] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[17] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[33] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[34] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.controlflow.cpp.code_correctness_memory_free_on_stack_variable
Abstract
이는 일반 .NET 메서드를 덮어쓰려는 것처럼 보이지만 의도한 효과는 나타나지 않습니다.
Explanation
이 메서드의 이름은 일반 .NET 메서드 이름과 비슷하지만 철자가 틀렸거나 인수 목록이 의도한 메서드를 덮어쓰게 만듭니다.

예제 1: 다음 메서드는 System.Object.Equals()를 오버라이드합니다.


public boolean Equals(string obj) {
...
}
System.Object.Equals()object 유형의 인수를 받기 때문에 해당 메서드는 호출되지 않습니다.
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 2
[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 398
desc.structural.dotnet.code_correctness_misleading_method_signature
Abstract
이는 일반 Java 메서드를 덮어쓰려는 것처럼 보이지만 의도한 효과는 나타나지 않을 수 있습니다.
Explanation
이 메서드의 이름은 일반 Java 메서드 이름과 비슷하지만 철자가 틀렸거나 인수 목록이 의도한 메서드를 덮어쓰게 만듭니다.

예제 1: 다음 메서드는 Object.equals()를 오버라이드합니다.


public boolean equals(Object obj1, Object obj2) {
...
}
Object.equals()가 하나의 인수만 받기 때문에 Example 1의 메서드는 호출되지 않습니다.
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 2
[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 398
desc.structural.java.code_correctness_misleading_method_signature
Abstract
ISerializable 인터페이스를 구현하지만 [Serializable] 속성을 선언하지 않는 클래스는 직렬화되지 않습니다.
Explanation
.NET 런타임은 [Serializable] 속성을 선언하는 모든 개체의 serialization을 허용합니다. .NET 프레임워크에 의해 정의된 기본 serialization 메서드를 사용하여 클래스를 직렬화할 수 있으면 개체를 정확하게 직렬화해야 할 필요와 직렬화하기 위한 충분한 조건이 충족됩니다. 클래스가 사용자 지정 serialization 메서드를 사용해야 하는 경우 ISerializable 인터페이스도 구현해야 합니다. 그러나, 이 경우에도 클래스는 [Serializable] 속성을 선언해야 합니다.

예제 1:CustomStorage 클래스는 ISerializable 인터페이스를 구현합니다. 그러나, [Serializable] 속성의 선언이 실패하므로 직렬화되지 않습니다.


public class CustomStorage: ISerializable {
...
}
References
[1] CA2237: Mark ISerializable types with SerializableAttribute Microsoft Corporation
[2] Piet Obermeyer and Jonathan Hawkins MSDN Library: Object Serialization in the .NET Framework
[3] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[4] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[5] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[6] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[7] Standards Mapping - Common Weakness Enumeration CWE ID 730
[8] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[9] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[10] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[11] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.9
[13] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[14] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[15] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[16] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[17] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[34] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[35] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.structural.dotnet.code_correctness_missing_serializable_attribute
Abstract
java.io.Serializable을 구현하는 inner class를 사용하면 outer class에서 문제가 발생하고 정보가 누출될 수 있습니다.
Explanation
inner class의 serialization을 수행하면 outer class도 serialization될 수 있어 정보가 누출될 수 있으며, outer class가 serializable이 아닌 경우에는 런타임 오류가 발생할 수 있습니다. 뿐만 아니라 inner class를 serialize하면 플랫폼 dependency가 발생할 수 있습니다. Java 컴파일러는 inner class를 구현하기 위해 가상 필드를 만드는데, 이러한 필드는 구현에 따라 다르며 컴파일러별로도 다를 수 있기 때문입니다.

예제 1: 다음 코드는 inner class의 serialization을 허용합니다.


...
class User implements Serializable {
private int accessLevel;
class Registrator implements Serializable {
...
}
}

Example 1에서 inner class Registrator를 serialize하면 outer class UseraccessLevel 필드도 serialize됩니다.
References
[1] SER05-J. Do not serialize instances of inner classes CERT
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 398
desc.structural.java.code_correctness_non_static_inner_class_implements_serializable
Abstract
Synchronized 메서드는 비 syncrhonized 메서드로 오버라이드되어서는 안 됩니다.
Explanation
상위 클래스는 synchronized 메서드를 선언했고 여러 스레드가 동일한 인스턴스에 접근할 때 올바른 동작을 보장합니다. 또한 모든 오버라이드 메서드는 synchronized로 선언되어야 합니다. 그렇지 않으면 예기치 못한 동작이 발생할 수도 있습니다.

예제 1: 다음 코드에서 Foo 클래스는 Bar 클래스를 오버라이드하지만 synchronizedMethod 메서드를 synchronized로 선언하지 않습니다.


public class Bar {
public synchronized void synchronizedMethod() {
for (int i=0; i<10; i++) System.out.print(i);
System.out.println();
}
}

public class Foo extends Bar {
public void synchronizedMethod() {
for (int i=0; i<10; i++) System.out.print(i);
System.out.println();
}
}


이 경우 Foo의 인스턴스가 Bar 유형으로 배정될 수 있습니다. 같은 인스턴스를 서로 다른 두 스레드에 지정하고 synchronizedMethod를 반복 실행하면 동작을 예측할 수 없게 됩니다.
References
[1] Sun Microsystems, Inc. Bug ID: 4294756 Javac should warn if synchronized method is overridden with a non synchronized
[2] TSM00-J. Do not override thread-safe methods with methods that are not thread-safe CERT
[3] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[4] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 2
[5] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[6] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
desc.structural.java.code_correctness_non_synchronized_method_overrides
Abstract
obj.Equals(null)는 항상 false가 됩니다.
Explanation
프로그램은 Equals() 메서드를 사용하여 개체를 null과 비교합니다. Equals() 메서드의 약정이 항상 false로 반환되도록 비교해야 합니다.
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[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 398, CWE ID 754
[6] Standards Mapping - OWASP Application Security Verification Standard 4.0 11.1.7 Business Logic Security Requirements (L2 L3)
[7] Standards Mapping - SANS Top 25 2010 Risky Resource Management - CWE ID 754
desc.structural.dotnet.code_correctness_null_argument_to_equivalence_method
Abstract
obj.equals(null)는 항상 false가 됩니다.
Explanation
프로그램은 equals() 메서드를 사용하여 개체를 null과 비교합니다. 이 비교는 개체가 null이 아니기 때문에 항상 false를 반환합니다. (개체가 null이면 프로그램에 NullPointerException이 발생합니다).
References
[1] JavaDoc for Object Sun Microsystems
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 398, CWE ID 754
[7] Standards Mapping - OWASP Application Security Verification Standard 4.0 11.1.7 Business Logic Security Requirements (L2 L3)
[8] Standards Mapping - SANS Top 25 2010 Risky Resource Management - CWE ID 754
desc.structural.java.code_correctness_null_argument_to_equivalence_method
Abstract
스레드가 생성되기 전에 상위 프로세스가 정상적으로 실행이 완료된 경우, 스레드가 비정상적으로 조기 종료될 수 있습니다.
Explanation
상위 프로세스의 main() 함수에서 pthread_create()를 호출하여 생성된 스레드는 해당 스레드가 pthread_exit()을 호출하기 전에 상위 프로세스의 실행이 완료되면 비정상적으로 조기 종료됩니다. pthread_exit()를 호출하면 상위 프로세스가 모든 해당 스레드의 실행이 완료될 때까지 그대로 유지됩니다. 또는 상위 프로세스가 모든 하위 스레드에서 pthread_join을 호출할 수 있으며 프로세스가 끝나기 전에 완료할 수 있도록 합니다.

예제 1: 다음 코드는 pthread_create()를 사용하여 스레드를 생성하고 정상적으로 종료되도록 합니다. 하위 스레드가 main() 함수가 반환될 때 까지 해당 실행을 완료하지 않는 경우, 비정상적인 조기 종료가 발생합니다.


void *Simple(void *threadid)
{
...
pthread_exit(NULL);
}

int main(int argc, char *argv[]) {
int rc;
pthread_t pt;
rc = pthread_create(&pt, NULL, Simple, (void *)t);
if (rc){
exit(-1);
}
}
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[3] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[4] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[5] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 1.3
desc.controlflow.cpp.code_correctness_premature_thread_termination