Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update invalid url handling #1603

Merged
merged 7 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
logged in [#1508](https://github.com/greenbone/gsa/pull/1508)

### Fixed
- Fixed 404 URL handling in gsad which caused a XSS vulnerability [#1603](https://github.com/greenbone/gsa/pull/1603)
- Fixed status of Tickets for task.isInTrash() and isOrphan [#1592](https://github.com/greenbone/gsa/pull/1592)
- Fix and improve editing of roles [#1587](https://github.com/greenbone/gsa/pull/1587)
- Fix showing ScanConfig trends [#1582](https://github.com/greenbone/gsa/pull/1582) [#1554](https://github.com/greenbone/gsa/pull/1554)
Expand Down
38 changes: 7 additions & 31 deletions gsad/src/gsad_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,19 @@ handler_create_response (http_connection_t *connection, gchar *data,
/**
* @brief Create a default 404 (not found) http response
*
* @param[in] url Requested (not found) url
* @param[out] response_data Response data to return
*
* @return A http response
*/
http_response_t *
create_not_found_response (const gchar *url, cmd_response_data_t *response_data)
create_not_found_response (cmd_response_data_t *response_data)
{
http_response_t *response;
int len;

cmd_response_data_set_status_code (response_data, MHD_HTTP_NOT_FOUND);

gchar *msg = g_strdup_printf (
gchar *msg =
"<!DOCTYPE html>"
"<html>"
"<head>"
Expand All @@ -408,12 +407,10 @@ create_not_found_response (const gchar *url, cmd_response_data_t *response_data)
"<body>"
"<h1>URL not found</h1>"
"<p>"
"The requested URL %s is not available"
"The requested URL is not available"
"</p>"
"</body>"
"</html>",
url
);
"</html>";

cmd_response_data_set_content_type (response_data,
GSAD_CONTENT_TYPE_TEXT_HTML);
Expand All @@ -422,30 +419,9 @@ create_not_found_response (const gchar *url, cmd_response_data_t *response_data)

len = cmd_response_data_get_content_length (response_data);
response = MHD_create_response_from_buffer (len, msg, MHD_RESPMEM_MUST_COPY);
g_free (msg);
return response;
}

/**
* @brief Send a 404 response for a request
*
* @param[in] connection Connection handle, e.g. used to send response.
* @param[in] url Requested url.
*
* @return MHD_YES on success. MHD_NO on errors.
*/
int
handler_send_not_found (http_connection_t *connection, const gchar *url)
{
http_response_t *response;
cmd_response_data_t *response_data;

response_data = cmd_response_data_new ();

response = create_not_found_response (url, response_data);
return handler_send_response (connection, response, response_data, NULL);
}

/**
* @brief Allow for reauthentication of a user
*
Expand Down Expand Up @@ -718,7 +694,7 @@ file_content_response (http_connection_t *connection, const char *url,
if (file == NULL)
{
g_debug ("File %s failed, ", path);
return create_not_found_response (url, response_data);
return create_not_found_response (response_data);
}

/* Guess content type. */
Expand All @@ -729,14 +705,14 @@ file_content_response (http_connection_t *connection, const char *url,
/* File information could not be retrieved. */
g_critical ("%s: file <%s> can not be stat'ed.\n", __FUNCTION__, path);
fclose (file);
return create_not_found_response (url, response_data);
return create_not_found_response (response_data);
}

/* Make sure the requested path really is a file. */
if ((buf.st_mode & S_IFMT) != S_IFREG)
{
fclose (file);
return create_not_found_response (url, response_data);
return create_not_found_response (response_data);
}

response = MHD_create_response_from_callback (
Expand Down
3 changes: 0 additions & 3 deletions gsad/src/gsad_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ int
handler_send_response (http_connection_t *connection, http_response_t *response,
cmd_response_data_t *response_data, const gchar *sid);

int
handler_send_not_found (http_connection_t *connection, const gchar *url);

/**
* @brief Content types.
*/
Expand Down
17 changes: 4 additions & 13 deletions gsad/src/gsad_http_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ handle_validate (http_connection_t *connection, const char *method,
/* Prevent guest link from leading to URL redirection. */
if (url && (url[0] == '/') && (url[1] == '/'))
{
return handler_send_not_found (connection, url);
send_response (connection, BAD_REQUEST_PAGE, MHD_HTTP_BAD_REQUEST, NULL,
GSAD_CONTENT_TYPE_TEXT_HTML, NULL, 0);
return MHD_YES;
}

/* Many Glib functions require valid UTF-8. */
Expand All @@ -327,14 +329,6 @@ handle_validate (http_connection_t *connection, const char *method,
return http_handler_next (connection, method, url, con_info, handler, data);
}

int
handle_not_found (http_connection_t *connection, const char *method,
const char *url, gsad_connection_info_t *con_info,
http_handler_t *handler, void *data)
{
return handler_send_not_found (connection, url);
}

int
handle_invalid_method (http_connection_t *connection, const char *method,
const char *url, gsad_connection_info_t *con_info,
Expand Down Expand Up @@ -740,7 +734,6 @@ http_handler_t *
init_http_handlers ()
{
http_handler_t *method_router;
http_handler_t *not_found_handler;
http_handler_t *gmp_post_handler;
http_handler_t *url_handlers;

Expand All @@ -751,7 +744,6 @@ init_http_handlers ()
handlers = http_handler_new (handle_validate);

method_router = method_router_new ();
not_found_handler = http_handler_new (handle_not_found);
gmp_post_handler = http_handler_new (handle_gmp_post);

http_handler_add (handlers, method_router);
Expand Down Expand Up @@ -787,8 +779,7 @@ init_http_handlers ()
http_handler_add (url_handlers, system_report_url_handler);
http_handler_add (url_handlers, logout_url_handler);

url_handler_add_func (url_handlers, "^/.*$", handle_index);
http_handler_add (url_handlers, not_found_handler);
http_handler_add (url_handlers, http_handler_new (handle_index));

method_router_set_get_handler (method_router, url_handlers);
method_router_set_post_handler (method_router, gmp_post_handler);
Expand Down