Re: [Json] Go JSON parser ignores the case of member names

Rob Sayre <sayrer@gmail.com> Wed, 09 March 2016 03:36 UTC

Return-Path: <sayrer@gmail.com>
X-Original-To: json@ietfa.amsl.com
Delivered-To: json@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 9C8EB12DDC7 for <json@ietfa.amsl.com>; Tue, 8 Mar 2016 19:36:12 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.699
X-Spam-Level:
X-Spam-Status: No, score=-2.699 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([127.0.0.1]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VkDsYzDK0khL for <json@ietfa.amsl.com>; Tue, 8 Mar 2016 19:36:11 -0800 (PST)
Received: from mail-io0-x230.google.com (mail-io0-x230.google.com [IPv6:2607:f8b0:4001:c06::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 2323912DCEB for <json@ietf.org>; Tue, 8 Mar 2016 19:36:11 -0800 (PST)
Received: by mail-io0-x230.google.com with SMTP id g203so51367106iof.2 for <json@ietf.org>; Tue, 08 Mar 2016 19:36:11 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=UM0TvgSGqvQQkjVM9i7hKDaSt3xiB2xGLvbNfhb26hE=; b=I5THfy8P7qSPjf1wruamu/6uQ4mrjkq+Z+XqPjT8hE/UE2z2Xyw1XvhOfEdM9TFBw3 0pRAvhhfJZHKlejdkCgXuvQj9BzFP3DAGRzftFdXgETFwnieHK2RYwxB9s245lSxZ+j3 KfnDxr/gq0quaZSkzKP7d/KL0f99T0Xa5j6oATWPn0s8Bw8nI+E9ND1QZxEeldsS/C2Z GOAqvpw/zUlAX0qSgcl3k6yhrdBqVa1w75u/hno7TRo3mT1m4+V4P338211fKEQQLhcJ MhSBUIr2JQB2Purshb1G+8HkppawukAHesJyyTyGlEa9Nl+0xIYj9WZRGeAfXongQ3lv 6clg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=UM0TvgSGqvQQkjVM9i7hKDaSt3xiB2xGLvbNfhb26hE=; b=Yi7wW24jw0igwzNfkvtWhyiltxaYNZKYBPF+7lDFdWm1xEn9B8jadHnz0EUO7JoXD9 CD3UKQOGHF7WUvQzTpJUgsIZ44g2GTvgucXeaD7p2rKmQkhy52O/Bg3FC2YTYBlB/9DR bPiToSgfMn7lTxC1Lj+hfZFsTLFsHON9kh60RCvYaVnatoJKpMvMFsF0wPzevIXmuw2y 3P/zVmH8QNHJ4rSsK2CTkzYF6R3x9WWm4NgzOnlqTeLSznnauyMNjJuAJLLuYa8jBMGz /9+pUfOkpdc/wIg3xOHcn51XLhtBeOQCsQm28CxzCxBsd5Oj57YQ8WLhEXXuqHGxfZ2I dg2A==
X-Gm-Message-State: AD7BkJJ/DY4SyrL1D6reNS4NqWniAp0pbYyfbNECbuevAa1uhnYD8qQjZ9lRNfUqSo8yJySMZ1E7P9xh7+sz1Q==
MIME-Version: 1.0
X-Received: by 10.107.164.170 with SMTP id d42mr24989747ioj.80.1457494570464; Tue, 08 Mar 2016 19:36:10 -0800 (PST)
Received: by 10.107.155.85 with HTTP; Tue, 8 Mar 2016 19:36:10 -0800 (PST)
In-Reply-To: <20160309012028.GQ32247@mercury.ccil.org>
References: <255B9BB34FB7D647A506DC292726F6E13BBE5873A1@WSMSG3153V.srv.dir.telstra.com> <20160309012028.GQ32247@mercury.ccil.org>
Date: Tue, 8 Mar 2016 19:36:10 -0800
Message-ID: <CAChr6SyGoRO-CgH5cPSXLLhnqkd5kJb9XpJ-evgJ1kB=mUot9A@mail.gmail.com>
From: Rob Sayre <sayrer@gmail.com>
To: John Cowan <cowan@mercury.ccil.org>
Content-Type: multipart/alternative; boundary=001a114217dc228576052d95665c
Archived-At: <http://mailarchive.ietf.org/arch/msg/json/rYKJmjPhwx4QSdglKesh-4vi5V4>
Cc: "Manger, James" <James.H.Manger@team.telstra.com>, "json@ietf.org" <json@ietf.org>
Subject: Re: [Json] Go JSON parser ignores the case of member names
X-BeenThere: json@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: "JavaScript Object Notation \(JSON\) WG mailing list" <json.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/json>, <mailto:json-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/json/>
List-Post: <mailto:json@ietf.org>
List-Help: <mailto:json-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/json>, <mailto:json-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 09 Mar 2016 03:36:12 -0000

Well, there are ways to avoid it too (see below). I see it more as an
object-mapper convenience than a JSON conformance problem. I imagine object
mapping libraries in other languages have this feature too.

- Rob

Program that prints all values from example:

package main

import (
"encoding/json"
"log"
)

func main() {
b := []byte(`{"typ":"JWS","alg":"HS256","ALG":"none"}`)
m := make(map[string]string)
err := json.Unmarshal(b, &m)
if err != nil {
log.Fatal("JSON parsing failed")
}
for k, v := range m {
println("k:", k, "v:", v)
}
}

---

k: typ v: JWS
k: alg v: HS256
k: ALG v: none





On Tue, Mar 8, 2016 at 5:20 PM, John Cowan <cowan@mercury.ccil.org> wrote:

> Manger, James scripsit:
>
> > I noticed that the default JSON parsing in the Go language
> > basically ignores the case of member names. Do JSON experts see this
> > case-insensitive parsing as a useful convenience for programmers (being
> > lenient with what you receive), or as a bad insecure design choice?
>
> I see it as Very Bad Indeed.  It violates the RFC and, as you say, causes
> a JSON text to be interpreted one way by one recipient and another way
> by another.
>
> > This looks quite diabolical for security as it is trivial to create
> > valid JSON values that will be interpreted differently by different
> > implementations. I would expect most implementations (that are expecting
> > an "alg" member) to see its "HS256" value and simply ignore the extra
> > "ALG" member.
>
> The Right Thing is to _validate your JSON_.  Make sure what you expect
> is there *before* acting on it, and if not *don't act on it*.
>
> --
> John Cowan          http://www.ccil.org/~cowan        cowan@ccil.org
> My confusion is rapidly waxing
> For XML Schema's too taxing:
> I'd use DTDs / If they had local trees --
> I think I best switch to RELAX NG.
>
> _______________________________________________
> json mailing list
> json@ietf.org
> https://www.ietf.org/mailman/listinfo/json
>