Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion dtable_events/dtable_io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dtable_events.utils.geo_location_parser import parse_geolocation_from_tree
from dtable_events.utils.dtable_db_api import DTableDBAPI
from dtable_events.utils.dtable_server_api import DTableServerAPI
from dtable_events.dtable_io.utils import clear_tmp_file, save_file_by_path, get_csv_file, \
from dtable_events.dtable_io.utils import is_plain_file_name, clear_tmp_file, save_file_by_path, get_csv_file, \
upload_excel_json_add_table_to_dtable_server, append_rows_by_dtable_server, get_related_nicknames_from_dtable, \
extract_select_options, upload_excel_json_to_dtable_server, get_rows_from_dtable_db, update_rows_by_dtable_db, \
get_nicknames_from_dtable, get_table_names_by_dtable_server, get_non_duplicated_name, filter_imported_tables
Expand Down Expand Up @@ -629,6 +629,9 @@ def parse_excel_csv_to_json(username, repo_id, file_name, file_type, parse_type,


def import_excel_csv_by_dtable_server(username, repo_id, dtable_uuid, dtable_name, included_tables, lang):
if not is_plain_file_name(dtable_name):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] 后台拒绝非法任务缺少回归保护

影响:四个 JSON 导入、追加及更新 worker 已新增前置校验,但没有提交相应测试。尤其是升级前已入队的任务,不会再经过新版 Web 校验;现有 CI 只运行 SQL 与 webhook 测试,无法证明后续改动仍会在读文件和清理前拒绝它们。

建议修复:为四个 worker 增加非法任务参数用例,断言抛出 ValueError 且 open、清理和远端写入均未调用,同时覆盖合法文件正常消费;在 tests/test.sh 中显式执行这组测试。

raise ValueError('dtable_name invalid.')

# get json file
tmp_file_path = os.path.join(EXCEL_IMPORT_DIR, repo_id, dtable_name + '.json')
with open(tmp_file_path, 'r') as f:
Expand All @@ -647,6 +650,9 @@ def import_excel_csv_by_dtable_server(username, repo_id, dtable_uuid, dtable_nam


def import_excel_csv_add_table_by_dtable_server(username, dtable_uuid, dtable_name, included_tables, lang):
if not is_plain_file_name(dtable_name):
raise ValueError('dtable_name invalid.')

# get json file
tmp_file_path = os.path.join(EXCEL_IMPORT_DIR, dtable_uuid, dtable_name + '.json')
with open(tmp_file_path, 'r') as f:
Expand All @@ -666,6 +672,9 @@ def import_excel_csv_add_table_by_dtable_server(username, dtable_uuid, dtable_na


def append_parsed_file_by_dtable_server(username, dtable_uuid, file_name, table_name):
if not is_plain_file_name(file_name):
raise ValueError('file_name invalid.')

# get json file
tmp_file_path = os.path.join(EXCEL_IMPORT_DIR, dtable_uuid, file_name + '.json')
with open(tmp_file_path, 'r') as f:
Expand Down Expand Up @@ -763,6 +772,9 @@ def get_dtable_row_data(dtable_rows, key_columns, excel_col_name_to_type, excel_


def update_parsed_file_by_dtable_server(username, dtable_uuid, file_name, table_name, selected_columns, can_add_row, can_update_row):
if not is_plain_file_name(file_name):
raise ValueError('file_name invalid.')

if not can_add_row and not can_update_row:
return

Expand Down
5 changes: 5 additions & 0 deletions dtable_events/dtable_io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,11 @@ def clear_tmp_dir(tmp_dir_path):
shutil.rmtree(tmp_dir_path)


# Require a single filename to prevent directory traversal.
def is_plain_file_name(name):
return (isinstance(name, str) and bool(name) and os.path.basename(name) == name)


def clear_tmp_file(tmp_file_path):
if os.path.exists(tmp_file_path):
os.remove(tmp_file_path)
Expand Down
Loading