Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1.25 KB

信息泄露.md

File metadata and controls

41 lines (32 loc) · 1.25 KB

信息泄露

运行服务器或者应用的时候,会产生一部分日志,这些日志可能会包含一些敏感信息。写代码个做调试的时候,可能会采用print或者logging来输出日志。

比如利用print或者sys.stdout.write输出某部分信息,方便查看后续调用或者查看是否符合预期等

def infor():
	infor = {'age':12, 'name':'join'}
	print(infor.get('age'))

更多的是使用logging来打印日志输出

def infor():
	logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    infor = {'age':12, 'name':'join'}
	logger.info(infor)

比如使用log来打印某个异常信息。

def INFOR(request):
    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    infor = {'age': 12, 'name': 'join'}
    try:
        open('exist', 'r')
    except (SystemExit, KeyboardInterrupt):
        raise
    except Exception as e:
        logger.error('Failed to open file', exc_info=True)
    return HttpResponse(logger.debug(infor))

修复代码

这种东西一般在线上系统是需要清除的,特别是关键处的错误异常输出。对没必要的异常显示,需要做异常处理显示或者禁止异常输出。