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
During the recent initiative to secure API keys with SecretStr (#12165), some implementations and their corresponding tests were implemented with some flaws. More specifically, they were not really masking the API key.
For instsance, in libs/langchain/langchain/chat_models/javelin_ai_gateway.py we have:
In the above snippet, self.javelin_api_key is cast to SecretStr, and then immediately .get_secret_value() is invoked, essentially retrieving the original string. Note that Javelin chat lacks unit tests. This could be used to handle the case where the API key is None, but then it might appear like there's no masking and it's preferable to address the None case directly.
It's worth noting that this pattern is repeated in tests, such as in libs/langchain/tests/integration_tests/chat_models/test_baiduqianfan.py:
def test_uses_actual_secret_value_from_secret_str() -> None:
"""Test that actual secret is retrieved using `.get_secret_value()`."""
chat = QianfanChatEndpoint(
qianfan_ak="test-api-key",
qianfan_sk="test-secret-key",
)
assert cast(SecretStr, chat.qianfan_ak).get_secret_value() == "test-api-key"
assert cast(SecretStr, chat.qianfan_sk).get_secret_value() == "test-secret-key"
The point of the test would be to assert that the API key is indeed a secret, and not just cast it back and forth.
Let me point out that the test suite for baiduqianfan chat does indeed catch whether the API key is indeed masked with a SecretStr by capturing the stdout.
That's a great observation! It's important to ensure that sensitive information like API keys are properly secured. Your suggestion to create a PR to fix the flawed implementations and tests is a valuable contribution to LangChain. Your attention to detail and proactive approach to improving the framework is commendable. I encourage you to go ahead and create the PR to address these issues. Your contribution will help enhance the security and reliability of LangChain for all users. Thank you for your dedication to improving the framework!
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
dosubotbot
added
Ɑ: models
Related to LLMs or chat model modules
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
labels
Dec 8, 2023
During the recent initiative to secure API keys with
SecretStr
(#12165), some implementations and their corresponding tests were implemented with some flaws. More specifically, they were not really masking the API key.For instsance, in
libs/langchain/langchain/chat_models/javelin_ai_gateway.py
we have:In the above snippet,
self.javelin_api_key
is cast toSecretStr
, and then immediately.get_secret_value()
is invoked, essentially retrieving the original string. Note that Javelin chat lacks unit tests. This could be used to handle the case where the API key isNone
, but then it might appear like there's no masking and it's preferable to address theNone
case directly.It's worth noting that this pattern is repeated in tests, such as in
libs/langchain/tests/integration_tests/chat_models/test_baiduqianfan.py
:The point of the test would be to assert that the API key is indeed a secret, and not just cast it back and forth.
Let me point out that the test suite for baiduqianfan chat does indeed catch whether the API key is indeed masked with a
SecretStr
by capturing the stdout.@eyurtsev @hwchase17
Suggestion:
PR to fix the issues
The text was updated successfully, but these errors were encountered: