Sync gateway gives me error about user defined property starting with _ when no such property exists

I am getting some really weird functionality from sync gateway v1.1.0 for documents when I try to upload an image. I am trying to attach an image to a document by running a PUT request with the image as the request body payload, but it keeps giving me this error:

{
  "error": "Bad Request",
  "reason": "user defined top level properties beginning with '_' are not allowed in document body"
}

Request: http://hostname/db/documentId/profileImage

The document does not have any top level properties beginning with underscore though. I checked the raw doc in the DB and the only top level property beginning with underscore is _sync.

@alexegli

Did you run a resync because the sync function was changed after the copy process?

Could you post an example document and if possible the format of the PUT request (ideally curl) you are using to add an attachment.

The valid top level properties beginning with ‘_’ are:

_id
_rev
_deleted
_attachments
_revisions

Can you enable all log channels in SG, “log”:["*"] property in sync_gateway_config.json, reproduce the both the PUT attachment and the Forbidden error and add the logs to a gist and post a link here.

Creating named documents via the REST API is supported.

After some testing I discovered that it was the failed PUT request that was affecting my session and causing forbidden errors only for the document I tried to run the PUT request on. I’ve updated the question above to reflect this. After I clear the session completely and re-login I’m able to retrieve the documents I have access to again.
The main issue seems to be the PUT request failing, which could be related to the tool I’m using which is Postman in Google Chrome. When I run the same PUT request to attach images to other documents though it works fine, which is why I was confused about this one. I enabled all logs and re-ran the request, and this is all I see in the sync gateway log:

2015-08-31T17:23:01.177Z Attach:        Added attachment "sha1-n6OFgj3+wDuMWo4373eh1gvjgqc="
2015-08-31T17:23:01.177Z HTTP: #007:     --> 400 user defined top level properties beginning with '_' are not allowed in document body  (6.3 ms)

My request is sending in binary image data, not a document body, and content-type=image/jpeg. The document I am trying to attach an image too is this (not including the _sync metadata section):

{
    "city": "Toronto",
    "createdAt": "2015-08-28T15:50:40-0400",
    "dateOfBirth": "1990-01-01",
    "email": "0142272c-d9ef-4c80-9358-6fe61f5e9a93@test.com",
    "familyName": "User",
    "favouriteExercises": [],
    "gender": "m",
    "givenName": "0142272c-d9ef-4c80-9358-6fe61f5e9a93",
    "goal": "speed",
    "heightUnit": "cm",
    "homeGym": "",
    "isManualEntryHintDisplayed": false,
    "isManualEntryWalkthroughDisplayed": false,
    "mobileDevicesUsed": [
        "IPOD_TOUCH_8.4",
        "IPHONE_8.4.1"
    ],
    "realTimeOn": false,
    "realTimeOnBeeping": false,
    "recommendationOn": true,
    "seenWalkthrough": true,
    "skillLevel": "beginner",
    "type": "user",
    "updatedAt": "2015-08-31T11:18:03-0400",
    "userId": "<userId>",
    "weightUnit": "kg"
}

I have tried to reproduce this with the document body you posted, but I can not so far.

Could you run the following curl command against the document exhibiting the issue, it will help to isolate the tool vs SG as the issue.

You will need to replace the db/doc/revision/image details for your local environment.

curl -X PUT “http://localhost:4985/db/atttestdoc1/attach1?rev=1-c22b5c574588ca326d67fc26e67c3cb8” -H “Content-Type: image/jpeg” --data-binary @mypicture.jpg

Thanks, when I ran it directly on the server with curl it went ok. It must be an issue with Postman. For some reason it can run this attach request on a different document type, but not on the document type I was just trying with.