aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-15 09:57:20 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-07-15 09:57:20 +0200
commitde853715e1454aba5e5300ffcc1d5b2bd8dc267d (patch)
treeec097e2f118a1405c676e4dc74cddec573135805
parent1b7caeb5acfe1d33a0305eaac188870698e622df (diff)
downloadgnunet-de853715e1454aba5e5300ffcc1d5b2bd8dc267d.tar.gz
gnunet-de853715e1454aba5e5300ffcc1d5b2bd8dc267d.zip
re-enable support for CORS config
-rw-r--r--src/rest/gnunet-rest-server.c51
-rw-r--r--src/rest/rest.conf1
2 files changed, 42 insertions, 10 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 26ac3feab..6b89d19fe 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -125,6 +125,11 @@ static struct GNUNET_CONTAINER_MultiHashMap *plugin_map;
125static int echo_origin; 125static int echo_origin;
126 126
127/** 127/**
128 * Allowed Origins (CORS)
129 */
130static char *allow_origins;
131
132/**
128 * Allowed Headers (CORS) 133 * Allowed Headers (CORS)
129 */ 134 */
130static char *allow_headers; 135static char *allow_headers;
@@ -439,17 +444,17 @@ create_response (void *cls,
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Queueing response from plugin with MHD\n"); 445 "Queueing response from plugin with MHD\n");
441 //Handle Preflights for extensions 446 //Handle Preflights for extensions
442 if (GNUNET_YES == echo_origin) 447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking origin\n");
448 GNUNET_CRYPTO_hash ("origin", strlen ("origin"), &key);
449 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle
450 ->header_param_map,
451 &key);
452 if (NULL != origin)
443 { 453 {
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking origin\n"); 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin: %s\n", origin);
445 GNUNET_CRYPTO_hash ("origin", strlen ("origin"), &key); 455 //Only echo for browser plugins
446 origin = GNUNET_CONTAINER_multihashmap_get (con_handle->data_handle 456 if (GNUNET_YES == echo_origin)
447 ->header_param_map,
448 &key);
449 if (NULL != origin)
450 { 457 {
451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Origin: %s\n", origin);
452 //Only echo for browser plugins
453 if ((0 == strncmp ("moz-extension://", 458 if ((0 == strncmp ("moz-extension://",
454 origin, 459 origin,
455 strlen ("moz-extension://"))) || 460 strlen ("moz-extension://"))) ||
@@ -462,6 +467,23 @@ create_response (void *cls,
462 origin); 467 origin);
463 } 468 }
464 } 469 }
470 if (NULL != allow_origins)
471 {
472 char *tmp = GNUNET_strdup (allow_origins);
473 char *allow_origin = strtok (tmp, ",");
474 while (NULL != allow_origin)
475 {
476 if (0 == strncmp (allow_origin, origin, strlen (allow_origin)))
477 {
478 MHD_add_response_header (con_handle->response,
479 MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
480 allow_origin);
481 break;
482 }
483 allow_origin = strtok (NULL, ",");
484 }
485 GNUNET_free (tmp);
486 }
465 } 487 }
466 if (NULL != allow_credentials) 488 if (NULL != allow_credentials)
467 { 489 {
@@ -878,6 +900,15 @@ run (void *cls,
878 GNUNET_CONFIGURATION_get_value_yesno (cfg, 900 GNUNET_CONFIGURATION_get_value_yesno (cfg,
879 "rest", 901 "rest",
880 "REST_ECHO_ORIGIN_WEBEXT"); 902 "REST_ECHO_ORIGIN_WEBEXT");
903 allow_origins = NULL;
904 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
905 "rest",
906 "REST_ALLOW_ORIGIN",
907 &allow_origins))
908 {
909 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
910 "No CORS Access-Control-Allow-Origin header will be sent...\n");
911 }
881 if (GNUNET_OK != 912 if (GNUNET_OK !=
882 GNUNET_CONFIGURATION_get_value_string (cfg, 913 GNUNET_CONFIGURATION_get_value_string (cfg,
883 "rest", 914 "rest",
@@ -886,7 +917,7 @@ run (void *cls,
886 { 917 {
887 //No origin specified 918 //No origin specified
888 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 919 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
889 "No CORS Access-Control-Allow-Origin Header will be sent...\n"); 920 "No CORS Credential Header will be sent...\n");
890 } 921 }
891 922
892 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 923 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
diff --git a/src/rest/rest.conf b/src/rest/rest.conf
index 08f4d2bc3..2b690b5b3 100644
--- a/src/rest/rest.conf
+++ b/src/rest/rest.conf
@@ -7,4 +7,5 @@ BIND_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_WEBEXT=YES 9REST_ECHO_ORIGIN_WEBEXT=YES
10REST_ALLOW_ORIGIN=http://localhost:4200
10REST_ALLOW_CREDENTIALS=true 11REST_ALLOW_CREDENTIALS=true