以下具体异常类型的 ToString() 方法是否会产生敏感数据?

发布于 2025-01-12 21:21:14 字数 1286 浏览 4 评论 0原文

尽管进行了详尽的搜索,但我找不到对上述问题的讨论。如果有的话请指出问题。

现在回答我的问题。我想将以下具体异常(它们不是自定义异常,即我自己没有编写它们)的 ToString() 方法的输出记录到文件中:

  • ArgumentNullException
  • System .Exception 本身
  • SecurityTokenException 和继承自 SecurityTokenException 的异常(例如, SecurityTokenExpiredException)

是否可以这样做,即,ToString() 不会返回可能首先导致异常的敏感数据?

根据 docsSystem.Exception.ToString() 返回以下输出:

ToString的默认实现获取类名 抛出当前异常、消息、调用结果 内部异常上的ToString,以及调用的结果 环境.StackTrace。如果这些成员中的任何一个为 null,则其值为 不包含在返回的字符串中。

检查Environment.Stacktrace 产生(如果我理解正确的话)以下信息:

  • StackTrace 不包含敏感数据(只有方法参数名称而不是它们的值)
  • 类的名称很好(这里没有敏感数据!)
  • InnerEception.ToString() 遵循上面 ToString() 的定义。因此,也应该没问题。

Message 属性是否上述异常中的哪些会产生敏感数据(例如,参数值、JwtSecurityToken 的内容等)?消息属性的纯粹未更改的输出是否可以保存地记录(我知道有加密,但与此无关)?

Despite searching exhaustively, I couldn´t find a discussion of the mentioned question. Please point me to the question if there´s any.

Now to my question. I´d like to log the output of the ToString() method of the following concrete exceptions (they aren´t custom exceptions, i.e., I didn´t write them myself) into a file:

  • ArgumentNullException
  • System.Exception itself
  • SecurityTokenException and exceptions that inherit from SecurityTokenException (e.g.,
    SecurityTokenExpiredException)

Is it save to do so, i.e., doesn´t ToString() return senstive data that might have caused the exception in the first place?

According to the docs, System.Exception.ToString() returns the following output:

The default implementation of ToString obtains the name of the class
that threw the current exception, the message, the result of calling
ToString on the inner exception, and the result of calling
Environment.StackTrace. If any of these members is null, its value is
not included in the returned string.

Examining the Environment.Stacktrace yields (if I understood it correctly) the following information:

  • StackTrace doesn´t contain senstive data (only method parameter names not their values)
  • Name of the class is fine (no senstive data here!)
  • InnerEception.ToString() follows the definition of ToString() above. Hence, it should be fine too.

Does the Message property of the mentioned exceptions yield senstive data (e.g., parameter values, content of JwtSecurityToken etc.)? Can the pure unchanged output of the message proeprty be logged savely (I know there´s encryption but independent of that)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文