@@ -187,6 +187,18 @@ def create_silent_action(action_func):
187
187
os .path .join (PROJECT_DIR , "sdkconfig.%s" % env .subst ("$PIOENV" )),
188
188
))
189
189
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
+
190
202
#
191
203
# generate modified Arduino IDF sdkconfig, applying settings from "custom_sdkconfig"
192
204
#
@@ -220,15 +232,20 @@ def load_custom_sdkconfig_file():
220
232
for file_entry in sdkconfig_entries :
221
233
# Handle HTTP/HTTPS URLs
222
234
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 ""
232
249
233
250
# Handle local files
234
251
if "file://" in file_entry :
@@ -301,14 +318,17 @@ def add_flash_configuration(config_flags):
301
318
return config_flags
302
319
303
320
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
304
324
"""Write the final sdkconfig.defaults file with checksum."""
305
325
sdkconfig_src = join (arduino_libs_mcu , "sdkconfig" )
306
326
sdkconfig_dst = join (PROJECT_DIR , "sdkconfig.defaults" )
307
327
308
328
# Generate checksum for validation (maintains original logic)
309
329
checksum = get_MD5_hash (checksum_source .strip () + mcu )
310
330
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 :
312
332
# Write checksum header (critical for compilation decision logic)
313
333
dst .write (f"# TASMOTA__{ checksum } \n " )
314
334
0 commit comments