Skip to content

Commit 100cb46

Browse files
authored
Update espidf.py
1 parent fab8a32 commit 100cb46

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

builder/frameworks/espidf.py

Lines changed: 30 additions & 10 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,15 +232,20 @@ 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:
223-
try:
224-
response = requests.get(file_entry.split(" ")[0])
225-
if response.ok:
226-
return response.content.decode('utf-8')
227-
except requests.RequestException as e:
228-
print(f"Error downloading {file_entry}: {e}")
229-
except UnicodeDecodeError as e:
230-
print(f"Error decoding response from {file_entry}: {e}")
231-
return ""
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:
240+
try:
241+
response = requests.get(file_entry.split(" ")[0], timeout=10)
242+
if response.ok:
243+
return response.content.decode('utf-8')
244+
except requests.RequestException as e:
245+
print(f"Error downloading {file_entry}: {e}")
246+
except UnicodeDecodeError as e:
247+
print(f"Error decoding response from {file_entry}: {e}")
248+
return ""
232249

233250
# Handle local files
234251
if "file://" in file_entry:
@@ -301,14 +318,17 @@ def add_flash_configuration(config_flags):
301318
return config_flags
302319

303320
def write_sdkconfig_file(idf_config_flags, checksum_source):
321+
if "arduino" not in env.subst("$PIOFRAMEWORK"):
322+
print("Error: Arduino framework required for sdkconfig processing")
323+
return
304324
"""Write the final sdkconfig.defaults file with checksum."""
305325
sdkconfig_src = join(arduino_libs_mcu, "sdkconfig")
306326
sdkconfig_dst = join(PROJECT_DIR, "sdkconfig.defaults")
307327

308328
# Generate checksum for validation (maintains original logic)
309329
checksum = get_MD5_hash(checksum_source.strip() + mcu)
310330

311-
with open(sdkconfig_src, 'r') as src, open(sdkconfig_dst, 'w') as dst:
331+
with open(sdkconfig_src, 'r', encoding='utf-8') as src, open(sdkconfig_dst, 'w', encoding='utf-8') as dst:
312332
# Write checksum header (critical for compilation decision logic)
313333
dst.write(f"# TASMOTA__{checksum}\n")
314334

0 commit comments

Comments
 (0)