]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Remove jsonp callback, add security HTTP headers
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 12 Jan 2016 09:25:05 +0000 (10:25 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 14 Jan 2016 08:17:22 +0000 (09:17 +0100)
- Remove the jsonp callback, using simple json data instead (Fixes #3217)
We might need to add CORS if we want to be able to retrieve JSON
data from a webpage not stored on the embedded web server.
- Add several HTTP headers:
 * X-Content-Type-Options: no-sniff to prevent browsers from guessing MIME type
 * X-Frame-Options: deny to prevent clickjacking
 * X-Permitted-Cross-Domain-Policies: none to keep flash from crossing boundaries
 * X-XSS-Protection: 1; mode=block to mitigate XSS
 * Content-Security-Policy: default-src 'self'; img-src *; style-src 'self' 'unsafe-inline',
 a basic CSP policy to restrict which scripts and CSS can be loaded

pdns/dnsdist-web.cc
pdns/dnsdistdist/html/local.js

index e4c2f76cb5b5a7579699d94ab3c3ef7f16e01cb2..ea9aa1df08cd2dc355f2afab05073a292ad88435 100644 (file)
@@ -58,16 +58,14 @@ static void connectionThread(int sock, ComboAddress remote, string password)
 
     string command=req.getvars["command"];
 
-    string callback;
-
-    if(req.getvars.count("callback")) {
-      callback=req.getvars["callback"];
-      req.getvars.erase("callback");
-    }
-
     req.getvars.erase("_"); // jQuery cache buster
 
     YaHTTP::Response resp(req);
+    resp.headers["X-Content-Type-Options"] = "nosniff";
+    resp.headers["X-Frame-Options"] = "deny";
+    resp.headers["X-Permitted-Cross-Domain-Policies"] = "none";
+    resp.headers["X-XSS-Protection"] = "1; mode=block";
+    resp.headers["Content-Security-Policy"] = "default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'";
 
     if (!compareAuthorization(req, password)) {
       errlog("HTTP Request \"%s\" from %s: Web Authentication failed", req.url.path, remote.toStringWithPort());
@@ -217,10 +215,6 @@ static void connectionThread(int sock, ComboAddress remote, string password)
       resp.status=404;
     }
 
-    if(!callback.empty()) {
-      resp.body = callback + "(" + resp.body + ");";
-    }
-
     std::ostringstream ofs;
     ofs << resp;
     string done;
index 63f65477e296aead534ae8b2216300b65fea3ab9..22804d853090fc8497b81c9c8b3a90cf78268e57 100644 (file)
@@ -142,7 +142,7 @@ $(document).ready(function() {
         $.ajax({
             url: 'jsonstat?command=stats',
             type: 'GET',
-            dataType: 'jsonp',
+            jsonp: false,
             success: function(data, x, y) {
                 $("#questions").text(data["queries"]);
                 $("#acl-drops").text(data["acl-drops"]);