aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-11 17:02:48 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-11 17:02:48 +0200
commitd773004b48c1c85c75a6298e32c09dec269d703f (patch)
tree061f527c4b95c8bd7dbcfff8127761e30615984a /src
parentda2a75db566b67e51ab1916378621ef1300ae37e (diff)
downloadgnunet-d773004b48c1c85c75a6298e32c09dec269d703f.tar.gz
gnunet-d773004b48c1c85c75a6298e32c09dec269d703f.zip
only add cors header for webext
Diffstat (limited to 'src')
-rw-r--r--src/rest/gnunet-rest-server.c32
-rw-r--r--src/rest/rest.conf2
2 files changed, 20 insertions, 14 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index c0db5430c..8154f33d8 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -438,23 +438,27 @@ create_response (void *cls,
438 { 438 {
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Queueing response from plugin with MHD\n"); 440 "Queueing response from plugin with MHD\n");
441 //Handle Preflights 441 //Handle Preflights for extensions
442 if (GNUNET_YES == echo_origin) 442 if (GNUNET_YES == echo_origin)
443 { 443 {
444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking origin\n");
445 "Echoing origin\n"); 445 GNUNET_CRYPTO_hash ("origin", strlen ("origin"), &key);
446 GNUNET_CRYPTO_hash ("origin",
447 strlen ("origin"),
448 &key);
449 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle 446 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle
450 ->header_param_map, 447 ->header_param_map,
451 &key); 448 &key);
452 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 449 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Origin: %s\n", origin);
453 "Origin: %s\n", origin); 450 //Only echo for browser plugins
454 if (NULL != origin) 451 if ((0 ==
455 MHD_add_response_header (con_handle->response, 452 strcmp ("moz-extension://", origin, strlen ("moz-extension://"))) ||
456 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN, 453 (0 == strcmp ("chrome-extension://",
457 origin); 454 origin,
455 strlen ("chrome-extension://"))))
456 {
457 if (NULL != origin)
458 MHD_add_response_header (con_handle->response,
459 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
460 origin);
461 }
458 } 462 }
459 if (NULL != allow_credentials) 463 if (NULL != allow_credentials)
460 { 464 {
@@ -868,7 +872,9 @@ run (void *cls,
868 872
869 /* Get CORS data from cfg */ 873 /* Get CORS data from cfg */
870 echo_origin = 874 echo_origin =
871 GNUNET_CONFIGURATION_get_value_yesno (cfg, "rest", "REST_ECHO_ORIGIN"); 875 GNUNET_CONFIGURATION_get_value_yesno (cfg,
876 "rest",
877 "REST_ECHO_ORIGIN_WEBEXT");
872 if (GNUNET_OK != 878 if (GNUNET_OK !=
873 GNUNET_CONFIGURATION_get_value_string (cfg, 879 GNUNET_CONFIGURATION_get_value_string (cfg,
874 "rest", 880 "rest",
diff --git a/src/rest/rest.conf b/src/rest/rest.conf
index 504f82a1b..08f4d2bc3 100644
--- a/src/rest/rest.conf
+++ b/src/rest/rest.conf
@@ -6,5 +6,5 @@ HTTP_PORT=7776
6BIND_TO=127.0.0.1 6BIND_TO=127.0.0.1
7BIND_TO6=::1 7BIND_TO6=::1
8REST_ALLOW_HEADERS=Authorization,Accept,Content-Type 8REST_ALLOW_HEADERS=Authorization,Accept,Content-Type
9REST_ECHO_ORIGIN=YES 9REST_ECHO_ORIGIN_WEBEXT=YES
10REST_ALLOW_CREDENTIALS=true 10REST_ALLOW_CREDENTIALS=true