I am learning the Pydantic module, trying to adopt its features/benefits via a toy FastAPI web backend as an example implementation.
I chose to use Pydantic's SecretStr
to "hide" passwords. I know it is not really secure, and I am also using passlib
for proper password encryption in DB storage (and using HTTPS for security in transit).
But this got me thinking: if there is no real security to SecretStr
, what is its purpose?
I don't mean for this to sound inflammatory; Pydantic does not claim that the Secret Types are secure. The only claim they provide is this:
You can use the
SecretStr
and theSecretBytes
data types for storing sensitive information that you do not want to be visible in logging or tracebacks.
But I do not understand this: how does SecretStr
help in hiding logging or tracebacks? Can't I just make sure not to log the password at all?
Can someone provide an explanation + example to help me better understand when and how it can be helpful? I am struggling to find its real purpose... and if there is no benefit, then it is better to just use an str
for the model/schema instead of SecretStr
.