summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Newson <rnewson@apache.org>2018-08-02 14:41:03 +0100
committerRobert Newson <rnewson@apache.org>2018-08-07 12:29:24 +0100
commit6d5ce6ae85373d316c3d1cf11054afbd4c7a7b5c (patch)
treebcca788cb95b129cdb3a3ae03a6a409828207e0c
parent6b5f7a75bd985b68376975f6565138c81568bc3c (diff)
downloadcouchdb-6d5ce6ae85373d316c3d1cf11054afbd4c7a7b5c.tar.gz
Enforce partition:id format in doc ids
-rw-r--r--src/couch/src/couch_doc.erl26
-rw-r--r--src/couch/test/fixtures/test.couchbin16482 -> 0 bytes
2 files changed, 22 insertions, 4 deletions
diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl
index f960ec5c2..9caa5ee8f 100644
--- a/src/couch/src/couch_doc.erl
+++ b/src/couch/src/couch_doc.erl
@@ -133,6 +133,12 @@ from_json_obj_validate(EJson) ->
from_json_obj_validate(EJson, DbName) ->
MaxSize = config:get_integer("couchdb", "max_document_size", 4294967296),
Doc = from_json_obj(EJson, DbName),
+ case is_binary(DbName) andalso mem3:is_partitioned(DbName) of
+ true ->
+ couch_doc:validate_docid(Doc#doc.id, DbName);
+ false ->
+ ok
+ end,
case couch_ejson_size:encoded_size(Doc#doc.body) =< MaxSize of
true ->
validate_attachment_sizes(Doc#doc.atts),
@@ -199,11 +205,23 @@ parse_revs(_) ->
validate_docid(DocId, DbName) ->
- case DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso
- lists:member(DocId, ?SYSTEM_DATABASES) of
- true ->
+ SystemId = DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso
+ lists:member(DocId, ?SYSTEM_DATABASES),
+ Partitioned = is_binary(DbName) andalso mem3:is_partitioned(DbName),
+ case {SystemId, Partitioned} of
+ {true, _} ->
ok;
- false ->
+ {false, true} ->
+ case binary:split(DocId, <<":">>) of
+ [<<"_design/", _/binary>> | _Rest] ->
+ validate_docid(DocId);
+ [Partition, Rest] ->
+ ok = validate_docid(Partition),
+ validate_docid(Rest);
+ _ ->
+ throw({illegal_docid, <<"doc id must be of form partition:id">>})
+ end;
+ {false, false} ->
validate_docid(DocId)
end.
diff --git a/src/couch/test/fixtures/test.couch b/src/couch/test/fixtures/test.couch
deleted file mode 100644
index 32c79af32..000000000
--- a/src/couch/test/fixtures/test.couch
+++ /dev/null
Binary files differ