Security: server-side file save roots, image URL SSRF protection, extension allowlist

This commit is contained in:
oobabooga 2026-03-17 22:24:36 -07:00
parent 08ff3f0f90
commit c8bb2129ba
6 changed files with 60 additions and 21 deletions

View file

@ -47,6 +47,10 @@ def save_file(fname, contents):
logger.error(f'Invalid file path: \"{fname}\"')
return
if Path(abs_path_str).suffix.lower() not in ('.yaml', '.yml', '.json', '.txt', '.gbnf'):
logger.error(f'Refusing to save file with disallowed extension: \"{fname}\"')
return
with open(abs_path_str, 'w', encoding='utf-8') as f:
f.write(contents)