mirror of https://github.com/Icinga/icinga2.git
Clean up CORS implementation
This commit is contained in:
parent
d23c03bfa5
commit
186cad9872
|
@ -64,9 +64,13 @@ Configuration Attributes:
|
|||
cipher\_list | String | **Optional.** Cipher list that is allowed. For a list of available ciphers run `openssl ciphers`. Defaults to `ALL:!LOW:!WEAK:!MEDIUM:!EXP:!NULL`.
|
||||
tls\_protocolmin | String | **Optional.** Minimum TLS protocol version. Must be one of `TLSv1`, `TLSv1.1` or `TLSv1.2`. Defaults to `TLSv1`.
|
||||
access\_control\_allow\_origin | Array | **Optional.** Specifies an array of origin URLs that may access the API. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin)
|
||||
access\_control\_allow\_credentials | Boolean | **Optional.** Indicates whether or not the actual request can be made using credentials. Defaults to `true`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Credentials)
|
||||
access\_control\_allow\_headers | String | **Optional.** Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request. Defaults to `Authorization`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Headers)
|
||||
access\_control\_allow\_methods | String | **Optional.** Used in response to a preflight request to indicate which HTTP methods can be used when making the actual request. Defaults to `GET, POST, PUT, DELETE`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Methods)
|
||||
access\_control\_allow\_credentials | Boolean | **Deprecated.** Indicates whether or not the actual request can be made using credentials. Defaults to `true`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Credentials)
|
||||
access\_control\_allow\_headers | String | **Deprecated.** Used in response to a preflight request to indicate which HTTP headers can be used when making the actual request. Defaults to `Authorization`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Headers)
|
||||
access\_control\_allow\_methods | String | **Deprecated.** Used in response to a preflight request to indicate which HTTP methods can be used when making the actual request. Defaults to `GET, POST, PUT, DELETE`. [(MDN docs)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Methods)
|
||||
|
||||
The attributes `access_control_allow_credentials`, `access_control_allow_headers` and `access_control_allow_methods`
|
||||
are controlled by Icinga 2 and are not changeable by config any more.
|
||||
|
||||
|
||||
The ApiListener type expects its certificate files to be in the following locations:
|
||||
|
||||
|
|
|
@ -49,21 +49,10 @@ class ApiListener : ConfigObject
|
|||
|
||||
[config] String ticket_salt;
|
||||
|
||||
[config] Array::Ptr access_control_allow_origin {
|
||||
default {{{ return new Array(); }}}
|
||||
};
|
||||
[config] bool access_control_allow_credentials
|
||||
{
|
||||
default {{{ return true; }}}
|
||||
};
|
||||
[config] String access_control_allow_headers
|
||||
{
|
||||
default {{{ return "Authorization"; }}}
|
||||
};
|
||||
[config] String access_control_allow_methods
|
||||
{
|
||||
default {{{ return "GET, POST, PUT, DELETE"; }}}
|
||||
};
|
||||
[config] Array::Ptr access_control_allow_origin;
|
||||
[config, deprecated] bool access_control_allow_credentials;
|
||||
[config, deprecated] String access_control_allow_headers;
|
||||
[config, deprecated] String access_control_allow_methods;
|
||||
|
||||
|
||||
[state, no_user_modify] Timestamp log_message_timestamp;
|
||||
|
|
|
@ -227,16 +227,15 @@ bool HttpServerConnection::ManageHeaders(HttpResponse& response)
|
|||
}
|
||||
}
|
||||
|
||||
if (listener->GetAccessControlAllowCredentials())
|
||||
response.AddHeader("Access-Control-Allow-Credentials", "true");
|
||||
response.AddHeader("Access-Control-Allow-Credentials", "true");
|
||||
|
||||
String accessControlRequestMethodHeader = m_CurrentRequest.Headers->Get("access-control-request-method");
|
||||
|
||||
if (m_CurrentRequest.RequestMethod == "OPTIONS" && !accessControlRequestMethodHeader.IsEmpty()) {
|
||||
response.SetStatus(200, "OK");
|
||||
|
||||
response.AddHeader("Access-Control-Allow-Methods", listener->GetAccessControlAllowMethods());
|
||||
response.AddHeader("Access-Control-Allow-Headers", listener->GetAccessControlAllowHeaders());
|
||||
response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
|
||||
response.AddHeader("Access-Control-Allow-Headers", "Authorization, X-HTTP-Method-Override");
|
||||
|
||||
String msg = "Preflight OK";
|
||||
response.WriteBody(msg.CStr(), msg.GetLength());
|
||||
|
|
Loading…
Reference in New Issue