谨慎处理调试日志

细节

调试日志通常用于检测和纠正应用程序中的缺陷。这些日志可能泄漏有助于攻击者的敏感信息。

修复

开发人员应考虑到调试日志在生产环境中可能造成的风险。一般我们建议在生产中禁用调试日志。

通常用于输出调试消息的Android系统日志是存储在内存中的几千字节的循环缓冲区。在内核崩溃的情况下,也可以从文件系统恢复调试日志。在设备重新启动后,它将被清除,但此前任何具有READ_LOGS权限的Android应用程序可以访问日志。在更新的Android版本中,日志文件已被谨慎隔离,不需要请求系统级权限。

在Android中,还可以利用ProGuard或DexGuard在发行版中完全删除对Log类的方法调用,从而剥离对Log.d,Log.i,Log.v,Log.e方法的所有调用。

proguard.cfg中,添加以下代码段:

> -assumenosideeffects class android.util.Log { 
        > public static *** d(...);
        > public static *** v(...);
        > public static *** i(...);
        > public static *** e(...);
> }

在iOS上禁用NSLog语句便可删除可能被拦截的潜在敏感信息,另外一个好处是可能会稍微增加应用的性能。

禁用的一种方法是在生产中进行NSLog定义:

> #define NSLog(s,...)

This macro effectively removes all NSLog statements and replaces it with empty text at compilation time.

> NSLog(@”Breakpoint here with data %@”,data.description);

becomes effectively a no-op.

> ;

建议

results matching ""

    No results matching ""