fix(gateway): tighten SQL identifier validation to fullmatch (reject trailing newline)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user