Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B70B6D1B9 for ; Sun, 10 Feb 2013 12:56:50 +0000 (UTC) Received: (qmail 2793 invoked by uid 500); 10 Feb 2013 12:56:50 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 2537 invoked by uid 500); 10 Feb 2013 12:56:44 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 2474 invoked by uid 99); 10 Feb 2013 12:56:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Feb 2013 12:56:41 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bchesneau@gmail.com designates 209.85.216.181 as permitted sender) Received: from [209.85.216.181] (HELO mail-qc0-f181.google.com) (209.85.216.181) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Feb 2013 12:56:34 +0000 Received: by mail-qc0-f181.google.com with SMTP id a22so1953442qcs.12 for ; Sun, 10 Feb 2013 04:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=4eK9AXmc+pmowrRLcqCjQTVrAY1P4imOG06GMBuXNs8=; b=Ke009oHDP57F9V4/yPunMFqjLLXzrVPhRg2IEX5/Qyajj788YegBbrVFllzlskYljA 7thrX2PDzIDRLQ9eBqyR/x7Zor3ckKBB5OH+hVFTswFh4kKY8zGW8PeiP6GGLp6y6xoI MjZxQZdX7LOEGAzpxKhFLZteMIP3lWD6k/twpwRQlnxoJJc4MKaTRHBeN0o8o37ySYNR 43jl/D2JxB/kQa7tA7KbyxdAHgonDFEEg7uiu+ZTzI1tfQGUbvfF5dKuPz8ZvCmI/o7K 7q7tit4m/W3W5ZlowlMl6Kf2G/YPEmrcgiV27FLFmimXyhxzgtpw1C4AimHhu44EBzyk lRZw== MIME-Version: 1.0 X-Received: by 10.224.201.201 with SMTP id fb9mr4421990qab.54.1360500973775; Sun, 10 Feb 2013 04:56:13 -0800 (PST) Received: by 10.49.64.232 with HTTP; Sun, 10 Feb 2013 04:56:13 -0800 (PST) In-Reply-To: <20130210105354.73D3A3C245@tyr.zones.apache.org> References: <20130210105354.73D3A3C245@tyr.zones.apache.org> Date: Sun, 10 Feb 2013 13:56:13 +0100 Message-ID: Subject: Re: git commit: Only allow strings in user doc "roles" array From: Benoit Chesneau To: "dev@couchdb.apache.org" Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org sounds good for me On Sun, Feb 10, 2013 at 11:53 AM, wrote: > Updated Branches: > refs/heads/1675-fix-roles-validation [created] 5f507095a > > > Only allow strings in user doc "roles" array > > We validate that _security documents only contain strings but we have > not done the same for the roles field in user docs. This is a breaking > change as users may have been inserting other things (notably, > objects) in this field. > > COUCHDB-1675 > > > Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo > Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/5f507095 > Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/5f507095 > Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/5f507095 > > Branch: refs/heads/1675-fix-roles-validation > Commit: 5f507095a0c7996391f6ca37a30fd0c4829b5e45 > Parents: 3b103eb > Author: Robert Newson > Authored: Sun Feb 10 10:52:24 2013 +0000 > Committer: Robert Newson > Committed: Sun Feb 10 10:52:24 2013 +0000 > > ---------------------------------------------------------------------- > share/www/script/test/users_db.js | 10 ++++++++++ > src/couchdb/couch_js_functions.hrl | 6 ++++++ > 2 files changed, 16 insertions(+), 0 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/couchdb/blob/5f507095/share/www/script/test/users_db.js > ---------------------------------------------------------------------- > diff --git a/share/www/script/test/users_db.js b/share/www/script/test/users_db.js > index 44e6c88..4d6e4de 100644 > --- a/share/www/script/test/users_db.js > +++ b/share/www/script/test/users_db.js > @@ -112,6 +112,16 @@ couchTests.users_db = function(debug) { > } > jchrisUserDoc.roles = []; > > + // "roles" must be an array of strings > + jchrisUserDoc.roles = [12]; > + try { > + usersDb.save(jchrisUserDoc); > + T(false && "should only allow us to save doc when roles is an array of strings"); > + } catch(e) { > + TEquals(e.reason, "doc.roles can only contain strings"); > + } > + jchrisUserDoc.roles = []; > + > // "roles" must exist > delete jchrisUserDoc.roles; > try { > > http://git-wip-us.apache.org/repos/asf/couchdb/blob/5f507095/src/couchdb/couch_js_functions.hrl > ---------------------------------------------------------------------- > diff --git a/src/couchdb/couch_js_functions.hrl b/src/couchdb/couch_js_functions.hrl > index 2ecd851..774b724 100644 > --- a/src/couchdb/couch_js_functions.hrl > +++ b/src/couchdb/couch_js_functions.hrl > @@ -39,6 +39,12 @@ > throw({forbidden: 'doc.roles must be an array'}); > } > > + for (var idx = 0; idx < newDoc.roles.length; idx++) { > + if (typeof newDoc.roles[idx] !== 'string') { > + throw({forbidden: 'doc.roles can only contain strings'}); > + } > + } > + > if (newDoc._id !== ('org.couchdb.user:' + newDoc.name)) { > throw({ > forbidden: 'Doc ID must be of the form org.couchdb.user:name' >