After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 792173 - there is no limit on header size and this can be use for a DOS
there is no limit on header size and this can be use for a DOS
Status: RESOLVED FIXED
Product: libsoup
Classification: Core
Component: Misc
unspecified
Other Linux
: Normal normal
: ---
Assigned To: libsoup-maint@gnome.bugs
libsoup-maint@gnome.bugs
Depends on:
Blocks:
 
 
Reported: 2018-01-03 16:09 UTC by Michele Dionisio
Modified: 2018-02-09 14:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to include limit (856 bytes, patch)
2018-01-03 16:09 UTC, Michele Dionisio
none Details | Review
change define name and indentation (1.06 KB, patch)
2018-01-06 11:06 UTC, Michele Dionisio
none Details | Review
patch to include limit on max header size received (1.15 KB, patch)
2018-02-07 09:57 UTC, Michele Dionisio
none Details | Review
test for max header size (1.90 KB, patch)
2018-02-07 09:58 UTC, Michele Dionisio
none Details | Review
patch and test (2.77 KB, patch)
2018-02-07 20:16 UTC, Michele Dionisio
none Details | Review
limit maximum header size (plus test) (2.76 KB, patch)
2018-02-08 11:18 UTC, Michele Dionisio
committed Details | Review

Description Michele Dionisio 2018-01-03 16:09:19 UTC
Created attachment 366248 [details] [review]
patch to include limit

there is no limit on header size and this can be use for a DOS.

I attach a patch for that
Comment 1 Claudio Saavedra 2018-01-04 08:54:53 UTC
Review of attachment 366248 [details] [review]:

This seems to be a reasonable concern. It would be good if we could also add a test case (probably to tests/header-parsing.c).

::: libsoup/soup-message-io.c
@@ +210,3 @@
 }
 
+#define LIMITHEADERSIZE (64*1024)

It should probably be HEADER_SIZE_LIMIT. Use spaces around * and drop the parentheses. Also, please define it at the beginning of the file, together with the RESPONSE_BLOCK_SIZE definition.

@@ +264,3 @@
+					     _("Header too big"));
+            return FALSE;
+        }

Please fix the indentation. I'm also not sure if this is the best place for that check and whether SOUP_STATUS_MALFORMED is the proper status. Maybe Dan can chime in here.
Comment 2 Dan Winship 2018-01-04 18:17:45 UTC
(In reply to Claudio Saavedra from comment #1)
> +#define LIMITHEADERSIZE (64*1024)
> 
> It should probably be HEADER_SIZE_LIMIT. Use spaces around * and drop the
> parentheses.

Agree about the name and spaces, but keep the parentheses to guarantee no operator precedence problems.

> Please fix the indentation. I'm also not sure if this is the best place for
> that check and whether SOUP_STATUS_MALFORMED is the proper status. Maybe Dan
> can chime in here.

SOUP_STATUS_MALFORMED is consistent with other errors (eg, header truncation just above). And the check basically has to be inside that loop where it is here.
Comment 3 Michele Dionisio 2018-01-06 11:06:59 UTC
Created attachment 366412 [details] [review]
change define name and indentation
Comment 4 Michele Dionisio 2018-01-06 11:09:26 UTC
I add a new patch with indentation fix.

I'm not able to add a test in  tests/header-parsing.c because I think my fix does not involve header parsing because I prevent to start parsing too big header before.
Comment 5 Claudio Saavedra 2018-01-08 14:52:35 UTC
You're right. Perhaps in misc-test.c? You can add a new path to the server that returns a long enough header and then check in the client that it is handled as expected.
Comment 6 Michele Dionisio 2018-02-07 09:57:58 UTC
Created attachment 367982 [details] [review]
patch to include limit on max header size received
Comment 7 Michele Dionisio 2018-02-07 09:58:33 UTC
Created attachment 367983 [details] [review]
test for max header size
Comment 8 Michele Dionisio 2018-02-07 10:00:21 UTC
Hi,

Hi add my patch rebase on master plus the test to check if the patch is working. I also test the test (that fail) if applyied alone on master.

I hope that this is ok to be merged on stable release
Comment 9 Claudio Saavedra 2018-02-07 16:46:44 UTC
Review of attachment 367983 [details] [review]:

In the future, please add the tests to the same patch that is being tested. There's no need for separate patches (it's also trivial this way to remove the test in case the patch needs to be reverted).

::: tests/misc-test.c
@@ +122,3 @@
 
+/* Host header handling: client must be able to override the default
+ * value, server must be able to recognize different Host values.

This comment seems copy-pasted from another test. Please change to reflect what this test does.

@@ +136,3 @@
+
+	msg = soup_message_new_from_uri ("GET", base_uri);
+	SoupSession *session;

Please fix the spacing.

@@ +138,3 @@
+	for (i=0; i<2048; i++) {
+		char *key = g_strdup_printf("test-long-header-key%d", i);
+	int i;

Same in these two.

@@ +141,3 @@
+		soup_message_headers_append (msg->request_headers, key, value);
+		g_free(value);
+

And here.
Comment 10 Claudio Saavedra 2018-02-07 16:47:32 UTC
Review of attachment 367982 [details] [review]:

Since there were some things to fix in the other patch, please merge both into one. This one is ready though.
Comment 11 Michele Dionisio 2018-02-07 20:16:49 UTC
Created attachment 368098 [details] [review]
patch and test
Comment 12 Michele Dionisio 2018-02-07 20:21:53 UTC
done
Comment 13 Claudio Saavedra 2018-02-08 09:26:05 UTC
Review of attachment 368098 [details] [review]:

You didn't fix the coding style.

::: tests/misc-test.c
@@ +122,3 @@
 
+/* request with too big header has to be discard: request with too big header
+ * has to be close from server side.

Requests with too big headers should be discarded with a IO error to prevent DOS attacks.

@@ +136,3 @@
+
+	msg = soup_message_new_from_uri ("GET", base_uri);
+	SoupSession *session;

This is still wrong. Leave a space around the equal and less-than signs (i = 0; i < 2040; i++).

@@ +138,3 @@
+	for (i=0; i<2048; i++) {
+		char *key = g_strdup_printf("test-long-header-key%d", i);
+	int i;

Spacing is still wrong here. Always leave a space between the function name and opening parenthesis.

@@ +141,3 @@
+		soup_message_headers_append (msg->request_headers, key, value);
+		g_free(value);
+

Spacing is still wrong here. Always leave a space between the function name and opening parenthesis.
Comment 14 Michele Dionisio 2018-02-08 11:18:45 UTC
Created attachment 368143 [details] [review]
limit maximum header size (plus test)
Comment 15 Michele Dionisio 2018-02-08 11:18:59 UTC
done
Comment 16 Claudio Saavedra 2018-02-08 12:05:27 UTC
Review of attachment 368143 [details] [review]:

Thanks, please push.
Comment 17 Claudio Saavedra 2018-02-09 13:35:48 UTC
If you don't have a git.gnome.org account please let me know and I'll push it for you.
Comment 18 Michele Dionisio 2018-02-09 13:41:04 UTC
I don't have any account on git.gnome.org, I will be happy if you can push it for me.

thanks
Comment 19 Claudio Saavedra 2018-02-09 14:45:45 UTC
Review of attachment 368143 [details] [review]:

Committed as f33de90ae.
Comment 20 Claudio Saavedra 2018-02-09 14:46:09 UTC
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.