Skip to content

Commit 3a771b6

Browse files
committed
Remove duplicate ColumnType assignment, add _is_sensitive_column helper
_validate_import_line_or_throw assigned `column` twice in the loop body (leftover from the redaction diff). Also had its own inline PASS-boundary check (`column.value < PASS.value`) duplicating the same boundary logic _redact_password_column derives independently via `ColumnType.PASS.value`. Factor both into one _is_sensitive_column helper so there's a single source of truth for "is this column sensitive enough to mask."
1 parent 371e4af commit 3a771b6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎tableauserverclient/models/user_item.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,16 @@ def validate_file_for_import(csv_file: io.TextIOWrapper, logger) -> tuple[int, l
550550
line = csv_file.readline()
551551
return num_valid_lines, invalid_lines
552552

553+
# Single source of truth for "is this column (or, for a malformed row that
554+
# shifted fields, anything at or after it) sensitive enough to mask before
555+
# it reaches a log handler or an exposed invalid-lines entry." Both
556+
# _redact_password_column (whole-line redaction) and
557+
# _validate_import_line_or_throw (per-column debug logging) key off this
558+
# instead of each re-deriving the PASS boundary independently.
559+
@staticmethod
560+
def _is_sensitive_column(column_index: int) -> bool:
561+
return column_index >= UserItem.CSVImport.ColumnType.PASS.value
562+
553563
# Return a copy of a raw CSV line with the password column replaced by "***".
554564
# Callers that log or expose invalid rows will not disclose the credential.
555565
# Preserves the original line ending (\r\n or \n) so log output and
@@ -601,7 +611,6 @@ def _validate_import_line_or_throw(incoming, logger) -> None:
601611
column = UserItem.CSVImport.ColumnType(i)
602612
value = line[i]
603613
valid = _valid_attributes[i]
604-
column = UserItem.CSVImport.ColumnType(i)
605614
# normalize case for fields with a restricted value set
606615
skip_validation = False
607616
if valid:
@@ -626,8 +635,8 @@ def _validate_import_line_or_throw(incoming, logger) -> None:
626635
else:
627636
value = value.lower()
628637
# A malformed row can shift password fragments into later columns;
629-
# keep every field after the username out of the logs.
630-
safe_value = value if column.value < UserItem.CSVImport.ColumnType.PASS.value else "***"
638+
# keep every field at or after PASS out of the logs.
639+
safe_value = "***" if UserItem.CSVImport._is_sensitive_column(column.value) else value
631640
logger.debug(f"column {column.name}: {safe_value}")
632641
# Never call _validate_attribute_value for PASS: its ValueError
633642
# embeds the raw value, and a future PR that adds password-format

0 commit comments

Comments
 (0)