Allow responses from image proxy server
This commit is contained in:
parent
5f004f5b45
commit
e657432ac1
|
@ -1,12 +1,22 @@
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "servehelper.h"
|
#include "servehelper.h"
|
||||||
|
|
||||||
|
static std::regex image_proxy_regex(
|
||||||
|
"(https?://)?" // optional scheme
|
||||||
|
"(?:.+?@)?" // optional username and pass
|
||||||
|
"([^/]+(?::\\d+)?)" // host
|
||||||
|
"(?:/.*)?$");
|
||||||
|
static inline std::string get_image_proxy_origin(const std::string& url);
|
||||||
|
|
||||||
void serve(const httplib::Request& req, httplib::Response& res, const Config& config, std::string title, Element element) {
|
void serve(const httplib::Request& req, httplib::Response& res, const Config& config, std::string title, Element element) {
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
std::string origin = get_origin(req, config);
|
std::string origin = get_origin(req, config);
|
||||||
std::string css_url = origin + "/style.css";
|
std::string css_url = origin + "/style.css";
|
||||||
res.set_header("Content-Security-Policy", "default-src 'none'; img-src 'self'; style-src "s + css_url);
|
res.set_header("Content-Security-Policy", "default-src 'none'; style-src "s + css_url
|
||||||
|
+ "; img-src " + get_image_proxy_origin(config.image_proxy_url));
|
||||||
|
|
||||||
Element html("html", {
|
Element html("html", {
|
||||||
Element("head", {
|
Element("head", {
|
||||||
|
@ -68,3 +78,12 @@ std::string get_origin(const httplib::Request& req, const Config& config) {
|
||||||
}
|
}
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline std::string get_image_proxy_origin(const std::string& url) {
|
||||||
|
std::smatch sm;
|
||||||
|
if (!std::regex_match(url, sm, image_proxy_regex)) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
return sm[1].str() + sm[2].str();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue