fix(gateway): tighten SQL identifier validation to fullmatch (reject trailing newline)

This commit is contained in:
PedroHMCosme
2026-07-14 19:31:11 -03:00
parent 905da5151b
commit abff80e0d3
2 changed files with 21 additions and 2 deletions

View File

@@ -4,7 +4,9 @@ from sqlalchemy import text
import ingestor.metrics as metrics
_IDENTIFIER_RE = re.compile(r'^[A-Za-z0-9_]+$')
# fullmatch (no ^/$ anchors) so a trailing newline can't slip through — `$` would
# match before a trailing '\n', which is not what we want for a SQL identifier.
_IDENTIFIER_RE = re.compile(r'[A-Za-z0-9_]+')
class DataSink:
@@ -63,6 +65,6 @@ class DataSink:
@staticmethod
def _validate_identifier(name: str) -> str:
if not _IDENTIFIER_RE.match(name):
if not isinstance(name, str) or not _IDENTIFIER_RE.fullmatch(name):
raise ValueError(f'invalid SQL identifier: {name!r}')
return name