nginx设置安全策略后,部分图片无法显示问题

在nginx里增加

 add_header X-Content-Type-Options nosniff;
 add_header X-XSS-Protection "1; mode=block";    
 add_header X-Frame-Options "SAMEORIGIN";

 来处理安全问题时,发现网站有些图片无法在部分ie下正常访问。

通过排查发现,

有些ie对于通过io方式形成的图片,无法正常显示。原因:部分ie在解析页面上的图片时,若不指定页面的Content-Type,则不会显示。

解决方案:在图片对外输出的outputStream时,增加

if("jpg".equalsIgnoreCase(attachmentBean.getAttachextname()) || "jpeg".equalsIgnoreCase(attachmentBean.getAttachextname())){
	response.addHeader("Content-Type", MediaType.IMAGE_JPEG_VALUE);
}else if("png".equalsIgnoreCase(attachmentBean.getAttachextname())){
	response.addHeader("Content-Type", MediaType.IMAGE_PNG_VALUE);
}else if("gif".equalsIgnoreCase(attachmentBean.getAttachextname())){
	response.addHeader("Content-Type", MediaType.IMAGE_GIF_VALUE);
}

猜你喜欢

转载自pigga.iteye.com/blog/2410699