Skip to content

Commit 1ff223a

Browse files
authored
add path_traversal detection for sdkconfig URL
1 parent dbc55c4 commit 1ff223a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

builder/frameworks/espidf.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ def create_silent_action(action_func):
187187
os.path.join(PROJECT_DIR, "sdkconfig.%s" % env.subst("$PIOENV")),
188188
))
189189

190+
def contains_path_traversal(url):
191+
"""Check for Path Traversal patterns"""
192+
dangerous_patterns = [
193+
'../', '..\\', # Standard Path Traversal
194+
'%2e%2e%2f', '%2e%2e%5c', # URL-encoded
195+
'..%2f', '..%5c', # Mixed
196+
'%252e%252e%252f', # Double encoded
197+
]
198+
199+
url_lower = url.lower()
200+
return any(pattern in url_lower for pattern in dangerous_patterns)
201+
190202
#
191203
# generate modified Arduino IDF sdkconfig, applying settings from "custom_sdkconfig"
192204
#
@@ -220,6 +232,11 @@ def load_custom_sdkconfig_file():
220232
for file_entry in sdkconfig_entries:
221233
# Handle HTTP/HTTPS URLs
222234
if "http" in file_entry and "://" in file_entry:
235+
url = file_entry.split(" ")[0]
236+
# Path Traversal protection
237+
if contains_path_traversal(url):
238+
print(f"Path Traversal detected: {url} check your URL path")
239+
else:
223240
try:
224241
response = requests.get(file_entry.split(" ")[0])
225242
if response.ok:

0 commit comments

Comments
 (0)