Your worst case scenario is not as bad as you think.
You are already parsing the RSS feed, so you already have the URLs of the images. Say you have an image URL, for example http://otherdomain.com/someimage.jpg . You rewrite this URL as https://mydomain.com/imageserver?url=http://otherdomain.com/someimage.jpg&hash=abcdeafad . Thus, the browser always makes a request via https, so you get rid of problems.
The next part is to create a proxy page or servlet that does the following:
- Read url parameter from query string and check hash
- Download the image from the server and the proxy server back to the browser
- If necessary, cache the image on disk
This solution has some advantages. You do not need to upload an image while creating html. You do not need to save images locally. In addition, you are stateless; The url contains all the information needed to serve the image.
Finally, the hash parameter is for security; You want your servlet to serve images for the URLs you created. So, having created the url, calculate md5(image_url + secret_key) and add it as a hash parameter. Before submitting a request, recalculate the hash and compare it with what was sent to you. Since secret_key is known only to you, no one can create valid URLs.
If you are developing in Java, Servlet is just a few lines of code. You should be able to port the code below to any other internal technology.
protected void proxyResponse (String targetURL, HttpServletRequest request, HttpServletResponse response) throws IOException { GetMethod get = new GetMethod(targetURL); get.setFollowRedirects(true); Enumeration headers = request.getHeaderNames(); while(headers!=null && headers.hasMoreElements()) { String headerName = (String)headers.nextElement(); String headerValue = request.getHeader(headerName); if(headerValue != null) { get.addRequestHeader(headerName, headerValue); } } m_httpClient.executeMethod(get); response.setStatus(get.getStatusCode()); Header responseHeaders[] = get.getResponseHeaders(); for(int i=0; i<responseHeaders.length; i++) { String headerName = responseHeaders[i].getName(); String headerValue = responseHeaders[i].getValue(); if(headerValue != null) { response.addHeader(headerName, headerValue); } } InputStream in = get.getResponseBodyAsStream(); OutputStream out = response.getOutputStream(); if (in !=null) { IOUtils.copy(in, out); } }
Sripathi Krishnan Jun 15 2018-10-15T00: 00Z
source share