Bug 39569 - Validation of ETag by HttpHeaders.Add is too strict
Summary: Validation of ETag by HttpHeaders.Add is too strict
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-03-13 12:44 UTC by mdriley
Modified: 2016-03-14 11:39 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description mdriley 2016-03-13 12:44:36 UTC
Mono rejects ETag values that include escaped quotes (\"). These values are allowed by the RFC.

RFC2616 defines ETag as:
  ETag = "ETag" ":" entity-tag
where
  entity-tag = [ weak ] opaque-tag
  weak       = "W/"
  opaque-tag = quoted-string
and
  quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
  qdtext         = <any TEXT except <">>
  quoted-pair    = "\" CHAR

That means that something like
  ETag: "\"123\""
is valid.

---

This program works fine on Microsoft .NET 4.6.2. On Mono 4.2.1, the call to Add() throws FormatException.

// mcs test1.cs /reference:System.Net.Http
using System;
using System.Net.Http;

class Test1 {
  public static void Main(string[] args) {
    var m = new HttpResponseMessage();

    string v2 = "\"\\\"123\\\"\"";
    Console.WriteLine("ETag: {0}", v2);
    m.Headers.Add("ETag", v2);  // This throws on Mono.
  }
}

output:
Unhandled Exception:
System.FormatException: One of the identified items was in an invalid format.
  at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) <0x3bf0880 + 0x000c7> in <filename unknown>:0
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, IEnumerable`1 values) <0x3bf0468 + 0x0004b> in <filename unknown>:0
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.String value) <0x3bf0400 + 0x00053> in <filename unknown>:0
  at Test1.Main (System.String[] args) <0x3bb0f70 + 0x0006f> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: One of the identified items was in an invalid format.
  at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) <0x3bf0880 + 0x000c7> in <filename unknown>:0
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, IEnumerable`1 values) <0x3bf0468 + 0x0004b> in <filename unknown>:0
  at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.String value) <0x3bf0400 + 0x00053> in <filename unknown>:0
  at Test1.Main (System.String[] args) <0x3bb0f70 + 0x0006f> in <filename unknown>:0
Comment 1 Marek Safar 2016-03-14 11:39:40 UTC
Fixed in master and Mono 4.4