You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
defcheck_nul(cls: Any, values: Dict[str, Any]) ->Dict[str, Any]:
"""to prevent hacking, do not allow the NUL character in a str (used by the root_validator)"""forvalin (valuesifisinstance(values, dict) elsevalues.model_dump()).values():
ifisinstance(val, str) and"\x00"inval:
raiseValueError()
returnvaluesclassListQuery(BaseModel):
model_config=ConfigDict(extra="forbid")
_check_nul=model_validator(mode='before')(check_nul)
Description
When the REST API got fuzzy tested by injecting random data, I found that NUL characters (\x00) ended up in the database. Is there a nice way to prevent/check NUL characters in string typed fields?
(python handles the NUL characters okish but it is troublesome for c-based clients).
The Example Code shows how I handle it for the moment. But it is easy to overlook adding this check.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
When the REST API got fuzzy tested by injecting random data, I found that NUL characters (\x00) ended up in the database. Is there a nice way to prevent/check NUL characters in string typed fields?
(python handles the NUL characters okish but it is troublesome for c-based clients).
The Example Code shows how I handle it for the moment. But it is easy to overlook adding this check.
Operating System
Linux
Operating System Details
No response
SQLModel Version
before 0.0.21
Python Version
3.11
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions