Skip to content
Open
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
2 changes: 1 addition & 1 deletion b2sdk/_internal/account_info/sqlite_account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _get_xdg_config_path(cls) -> str | None:

@classmethod
def get_user_account_info_path(cls, file_name: str | None = None, profile: str | None = None):
if profile and not B2_ACCOUNT_INFO_PROFILE_NAME_REGEXP.match(profile):
if profile and not B2_ACCOUNT_INFO_PROFILE_NAME_REGEXP.fullmatch(profile):
raise ValueError(f'Invalid profile name: {profile}')

profile_file = B2_ACCOUNT_INFO_PROFILE_FILE.format(profile=profile) if profile else None
Expand Down
1 change: 1 addition & 0 deletions changelog.d/629.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix account info profile name validation only checking the first character, which let names containing path separators or other invalid characters through to the database path.
15 changes: 15 additions & 0 deletions test/unit/account_info/test_sqlite_account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,21 @@ def test_invalid_profile_name(self):
with pytest.raises(ValueError):
SqliteAccountInfo.get_user_account_info_path(profile='&@(*$')

@pytest.mark.parametrize(
'profile',
[
'a/../../etc',
'a\\..\\..\\etc',
'a b',
'a&@(*$',
'a' * 65,
'abc\n',
],
)
def test_invalid_profile_name_with_valid_first_character(self, profile):
with pytest.raises(ValueError):
SqliteAccountInfo.get_user_account_info_path(profile=profile)

def test_profile_and_file_name_conflict(self):
with pytest.raises(ValueError):
SqliteAccountInfo.get_user_account_info_path(file_name='foo', profile='bar')
Expand Down