Skip to content

Commit 0c445ba

Browse files
committed
Update README.md
1 parent 4282bd9 commit 0c445ba

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

Path Manipulation/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Path Manipulation
22

3+
I have written a detailed blog for Path Manipulation, you can check it [here](https://sahildari.medium.com/sast-series-part-1-a7cf18df0022)
4+
35
## Definition as per OWASP
46
**Path Manipulation** attack also known as **Path Traversal** attack, aims to access files and directories that are stored outside the web root folder. By manipulating variables that reference files with “dot-dot-slash (../)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system including application source code or configuration and critical system files. It should be noted that access to files is limited by system operational access control (such as in the case of locked or in-use files on the Microsoft Windows operating system).
57

Privacy Violation - Heap Inspection/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Privacy Violation: Heap Inspection
22

3+
I have written a detailed blog for Privacy Violation: Heap Inspection, you can check it [here](https://sahildari.medium.com/sast-series-part-2-ecbaca2b9c97)
4+
35
__Privacy Violation: Heap Inspection__ is a source code security issue that occurs mostly in C#, Java, and Swift applications. Strings are immutable in these languages, meaning that if they are used to store sensitive information such as passwords, credit card numbers, secrets, or tokens, these values will remain in memory until the JVM garbage collector (in Java) or ARC (Automatic Reference Counting) (in Swift) removes them.
46

57
There is no guarantee as to when garbage collection will take place. In the event of an application crash, a memory dump might reveal sensitive data, making it accessible to anyone inspecting the heap before garbage collection occurs.
@@ -20,12 +22,11 @@ StringBuffer password = new StringBuffer("SecurePassword");
2022

2123
## Mitigation
2224

23-
To mitigate the Privacy Violation: Heap Inspection issue in Java, C#, and Swift applications:
24-
25-
:white_check_mark: Use character arrays (char[]) instead of strings to store sensitive information.
26-
27-
:white_check_mark: Manually clear arrays after use (e.g., overwriting with '\0').
28-
29-
:white_check_mark: Ensure cleanup happens in a finally block to guarantee execution.
30-
31-
By following these best practices, you reduce the risk of exposing sensitive data in memory dumps.
25+
🔒 Best Practices for Secure Coding
26+
1️⃣ Never store sensitive information in immutable strings 🚫
27+
2️⃣ Understand how Garbage Collection (GC) works in your programming language 🧐
28+
3️⃣ Use Secret Managers or Vaults to store sensitive information 🔐
29+
4️⃣ Use prebuilt Secure Strings to handle sensitive information
30+
Java: Use GuardedString (from Java's security libraries)
31+
C#: Use SecureString to handle sensitive data securely 
32+
5️⃣ When no prebuilt library exists, store passwords in char[] and overwrite the array after usage to ensure it doesn't linger in memory.

Privacy Violation - Heap Inspection/java/HeapInspectionGuardedStringExample.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ private static void overwriteString(String str) {
5454
}
5555
}
5656

57-
public static void usePasswordSecurely(GuardedString guardedPassword) {
57+
private static void clearSensitiveData(StringBuffer sb){
58+
sb.delete(0, sb.length());
59+
sb = null;
60+
}
61+
62+
public static GuardedString usePasswordSecurely(GuardedString guardedPassword) {
5863
// Securely access the password value
5964
guardedPassword.access(chars -> {
6065
// Construct the connection string securely
@@ -63,9 +68,12 @@ public static void usePasswordSecurely(GuardedString guardedPassword) {
6368
.append(";columnEncryptionSetting=Enabled;");
6469

6570
System.out.println("Connection String: " + connectionString);
66-
67-
// Overwrite the password in memory after use
68-
overwriteCharArray(chars);
71+
// Perform operations with the connection string here
72+
73+
// After performing operations, clear the sensitive data
74+
75+
overwriteByteArray(chars); // Overwrite the password in memory
76+
clearSensitiveData(connectionString); // Clear the connection string from memory
6977
});
7078
}
7179

0 commit comments

Comments
 (0)