在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);
}
本文探讨了在使用特定安全头设置的情况下,部分IE浏览器无法正确显示通过IO方式生成的图片的问题。文中提供了详细的解决方案,包括如何根据文件扩展名设置正确的Content-Type。
1347

被折叠的 条评论
为什么被折叠?



