dongmibeng5885 2019-03-22 19:39
浏览 22

使用反射防止秘密被记录

Say we have a type to encapsulate sensitive information, which can only be accessed by calling its SecretValue method:

type Secret struct {
    secret string
}

func (s *Secret) SecretValue() string {
    return s.secret
}

We wish to prevent the sensitive info secret from leaking into logs. Specifically, we want to ensure that the string returned by SecretValue() is never later passed as an argument to any method that can write to stdout, stderr, or a file -- that is, methods like fmt.Printf, fmt.Println, fmt.Errorf, etc.

  1. Is it possible, either by static analysis of the code, or by using reflection at runtime, to enforce such a policy? If so, how, at a high-level, would this be achieved?

  2. Is it even possible to enumerate "all methods in the standard library that can possible write to stdout, stderr, or a file"? If so, how?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?