Repository navigation
Description
Often in automation we need to use passwords or other values that should not be logged. To help with that, various libraries have keywords that avoid logging given values even though their keywords normally do that. For example, SeleniumLibrary has Input Password that doesn't log the password and also temporarily disables Robot's logging to avoid the password being logged by the underlying Selenium on DEBUG level. This works fine otherwise, but if tests are run with --loglevel TRACE, Robot anyway logs all argument values and the password will be visible. Browser's Fill Secret tries to avoid that problem by requiring the value to be passed using a special $var syntax so that Robot won't log the actual variable value. Unfortunately that doesn't work if the value is passed to Fill Secret via a user keyword and only that keyword uses the $var syntax like in the following example:
*** Variables ***
${PASSWORD} secret
*** Test Cases ***
Example
Keyword ${PASSWORD} # This value is logged on TRACE level
*** Keywords ***
Keyword
[Arguments] ${pwd}
Fill Secret selector $pwdTo make it easier to use values that should not be logged, I propose we add new variable syntax *{var} to create "secret variables". The syntax could be used when creating variables in the Variables section, when creating local variables based on keyword return values, and with Set Global/Suite/Test/Local Variable keywords. The syntax would be only used for creating variables, they would be used normally like ${var}:
*** Variables ***
*{PASSWORD} secret
*** Test Cases ***
Example
Keyword ${PASSWORD}
*{local} = Another keyword
Keyword ${local}
*** Keywords ***
Keyword
[Arguments] ${pwd}
Fill Secret selector ${pwd}Technically the *{var} assignment would create a custom object with this kind of implementation:
class Secret:
def __init__(self, value, name=None):
self.value = value
self.name = name
def __str__(self):
return f'<Secret {self.name}>' if self.name else '<Secret>'These objects would be used when the variable is passed from tests to user keywords and from user keywords to other user keywords. The real value would, however, be passed to library keywords so they would get values normally and wouldn't need to be changed to benefit from this new syntax.
Although this new syntax would work with existing keywords, we should make it possible for library keywords to require arguments to be "secret". That's basically what Fill Secret does but this new syntax would avoid the problem that the value can be logged on higher level. A convenient way to support this would be type hints:
from robot.api.secrets import Secret
def example(secret: Secret):
...This would work so that Robot would validate that the used value is a Secret and fail if it's not. I believe we should pass the real value, not the actual Secret object, to the underlying keyword also in this case. That can confuse type checkers but keywords can use typing.cast if that's a problem. To support normal type conversion, we should also allow parameterizing the type hint like Secret[int].
Keywords could also return secret values simply by returning Secret instances:
from robot.api.secrets import Secret
def example():
return Secret('value')UPDATE: The syntax to create secrets turned out to be quite a bit different to what was initially proposed, but the concept is still the same.
Activity
pekkaklarck commentedon Nov 16, 2022
One problem with the proposed implementation is that although Robot itself wouldn't log secret variable values, keywords could accidentally log them. We could easily special case keywords like
Log, but because other keywords could leak the value that alone probably doesn't make sense. One possibility would be making it an error to pass aSecretto a library keyword that doesn't explicitly requireSecret. An obvious problem of this approach is that secret variables wouldn't work with existing keywords. I got a feeling that it is a too big problem and we shouldn't to this. Possibly this behavior could be configurable, though, but in that case I'd add configuration only later.If we'd made using secrets more strict like this, I believe we should anyway allow users to use
${secret.value}syntax to access the actual value. This would make it possible to log the value for debug purposes. We should also allow keywords to accept also other values than secrets likearg: Secret | str.Another possible approach would be always just passing
Secretobjects to library keywords instead of upwrapping them and passing actual values. This wouldn't work with existing keywords any better than requiring keywords to declare they acceptSecretobjects, though.pekkaklarck commentedon Nov 17, 2022
One open question is what to do if a secret variable is added into a
@{list}or&{dict}in the Variables section:I believe we should add the
Secretobject, not the value, to containers in cases like this. Otherwise if these variables are logged on TRACE, the secret value is logged as part of them. If the variables are passed to keywords likeKeyword ${LIST}, I don't think it makes sense for us to go through their contents and convertSecretobjects to values like the plan is to do when only a secret value is used. These values can be deeply nested and also recursive making going through them hard. Not unwrappingSecretobjects means keywords can encounter these objects, but I expect that to be rare and accessing the actual value is anyway easy.If collections are created dynamically in tests or keywords like
they end up getting the real value, not
Secretobject, because that's what is planned to be passed toCreate List. The comment above discusses other alternatives to these plans, though.pekkaklarck commentedon Nov 17, 2022
Another questions is should we allow using secrets as parts of strings like
Hello, ${SECRET}!. I believe this should be prohibited because the wholeHello, ${SECRET}!argument may be logged using TRACE after the variable is resolved. UsingHello, ${SECRET.value}!would work, though, unless we hide the actual value somewhere (which is rather complicated with Python).pekkaklarck commentedon Nov 17, 2022
Yet another question is deciding what to do if variables are used like
*{var}:Options include:
${SECRET}. I don't like this too much. Having two alternative ways to do same thing is seldom a good idea.Secretand normal${SECRET}usage would pass theSecretobject, not the value. Or possibly*{SECRET}could mean passingSecretwhile${SECRET}would unwrap.If
*{SECRET}and${SECRET}would work differently, one referring to theSecretobject and other to the value, then we could allow using them both when creating @{list} and &{dict} in the Variables section. Possibly one of them would also work as part of a string.pekkaklarck commentedon Mar 7, 2023
Issue #4674 proposes supporting
$varsyntax as an alternative to${var}. If we do that, passing secrets to the Browser library by using the$varsyntax won't work anymore. That would increase the priority of this issue.Snooz82 commentedon Mar 7, 2023
I would propose to NOT implement
*{secret}because it is pretty implicit and only some super nerds will know that feature.i would propose to implement type converters for variables and user keyword arguments first! Then Secret creation is for free.
#3278
discussion about that:
https://robotframework.slack.com/archives/C04FPJ3R4PN/p1678217116430379?thread_ts=1678198681.294349&channel=C04FPJ3R4PN&message_ts=1678217116.430379
pekkaklarck commentedon Mar 7, 2023
Using
${pwd}:Secret(or${pwd:Secret}, depending on how #3278 is implemented) would be a good alternative to*{pwd}. One downside is that variable type conversion is harder to implement than adding*{pwd}syntax, but that feature also has lot of other usages so implementing it makes sense anyway. If we go that route, then this issue obviously is dependent on #3278.If we decide to rely on variable conversion instead of adding
*{var}syntax, we need to add a custom variable converter forSecretthat converts the value to aSecretobject as discussed above. Then we need another argument converter for libraries that only validates that the given argument is aSecret.pekkaklarck commentedon Mar 25, 2023
Here's some proto code how
Secretcould possibly look like. It supports alsoSecret[int]and converts value accordingly. If this is added to Robot, values naturally need to be converted using Robot's converters.45 remaining items
Fixes and enhancements to Secret.
Secret: Simplify error reporting
Fixes and enhancements to Secret tests (#4537)
pekkaklarck commentedon Sep 12, 2025
I tried moving the
Secretimplementation underrobot.api.types, but the cyclic import issues turned out to be too hard to fix. We've many times earlier exposed classes, functions, etc. implemented elsewhere viarobot.api, so I guess that's not a major issue in this case either. The implementation is currently inrobot.utils._secretmodule, but I don't think trying to hide it into a private module has benefits, especially because it is anyway public exposed viarobot.utils. I'll thus rename the module torobot.utils.secret. The class also needs a note that it should be imported viarobot.api.typesand that module itself needs docs too.`robot.utils._secret` -> `robot.utils.secret`
Enhance `Secret` API docs
pekkaklarck commentedon Sep 15, 2025
The new robot.api.types module now has API docs and those docs link to the
Secretclass. There were some technical challenges with that due to #5498.Enhance Secret documentation
pekkaklarck commentedon Sep 16, 2025
Above commits finalized documentation so this issues is now done! 🎉
Minor tuning for Secret docs
Minor tuning/fixes for Secret variable docs
Change `str(Secret(...))` to `<secret>`