iOS技术栈网络

iOS安全问题(Cach.db、Snapshot)

2020-12-16  本文已影响0人  汗青fullstack
一. AFNetworking默认使用NSURLCache用来缓存网络请求的信息保存在数据库,而在受损iOS设备上,攻击者能够提取应用程序沙盒中的所有文件。

进入/Library/Caches/"你的Bunld ID"里面Cache.db, 是缓存的数据库,
文件夹/fsCachedData, 就是缓存的文件,用于缓存

1.NSURLCache

iOS中的缓存技术使用 NSURLCache 类
缓存原理:一个NSURLRequest对应一个NSCachedURLResponse
缓存技术:把缓存的数据都保存到数据库中(Cache.db 和对应的/fsCachedData/请求记录文件)


明文存储的请求数据
2.处理方式:

在请求处理完成的时候清理下缓存

//由于安全问题,移除网络接口缓存
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
二. Snapshot 中可能含有敏感信息

iOS在7.0以后,APP进入后台后会把当前APP的Window状态记录,并对Window进行截图操作,会在APP的Sandbox的Library\Caches\Snapshots\xxxx.xxx.xxx文件夹中增加以下几个文件。这有可能会造成用户敏感数据的泄密。

1.处理方式

在APP进入后台使用启动图遮挡window,进入前台就移除遮挡view

/** 屏幕遮挡层 */
@property (nonatomic, strong) UIView *launchScreenView;

- (void)applicationDidEnterBackground:(UIApplication *)application {
    /** 隐藏window,避免快照缓存敏感数据 */
    [self setupLaunchScreenWithHidden:NO];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    /** 恢复显示window */
    [self setupLaunchScreenWithHidden:YES];
}

#pragma mark - lazy launchScreenView

- (UIView *)launchScreenView {
    if (!_launchScreenView) {
        UIView *view = [[UIView alloc] initWithFrame:self.window.frame];
        view.backgroundColor = [UIColor whiteColor];
        
        UIImageView *bgImageV = [[UIImageView alloc] initWithFrame:self.window.frame];
        bgImageV.image = [UIImage imageNamed:@"launch_bg"];
        bgImageV.contentMode = UIViewContentModeScaleAspectFill;
        [view addSubview:bgImageV];
        _launchScreenView = view;     }
    return _launchScreenView;
}

/** 隐藏/显示window,避免快照缓存敏感数据 */
- (void)setupLaunchScreenWithHidden:(BOOL) hidden {
    if (hidden) {
        [self.launchScreenView removeFromSuperview];
    } else {
        [self.window addSubview:self.launchScreenView];
    }

}

上一篇 下一篇

猜你喜欢

热点阅读