Skip to content

Commit 0245d2a

Browse files
authored
[4.0.1 backport] CBG-4978 update the documentation for CORS (#7853)
1 parent cd4437c commit 0245d2a

File tree

8 files changed

+132
-120
lines changed

8 files changed

+132
-120
lines changed

docs/api/components/responses.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Not-found:
1515
example:
1616
error: not_found
1717
reason: no such database "invalid-db"
18+
Unauthorized:
19+
description: User does not have access to resource, or resource does not exist
20+
content:
21+
application/json:
22+
schema:
23+
$ref: ./schemas.yaml#/HTTP-Error
1824
Conflict:
1925
description: Resource already exists under that name
2026
content:
@@ -33,12 +39,15 @@ Role:
3339
application/json:
3440
schema:
3541
$ref: ./schemas.yaml#/Role
36-
Invalid-CORS:
37-
description: Origin is not in the approved list of allowed origins
42+
Invalid-CORS-LoginOrigin:
43+
description: Value of `Origin` is not in the approved list of allowed origins in `LoginOrigin` of Sync Gateway bootstrap or database configuration.
3844
content:
3945
application/json:
4046
schema:
4147
$ref: ./schemas.yaml#/HTTP-Error
48+
example:
49+
error: "Bad Request"
50+
reason: "No CORS"
4251
User-session-information:
4352
description: Properties associated with a user session
4453
content:

docs/api/components/schemas.yaml

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -390,25 +390,42 @@ User-session-information:
390390
type: object
391391
properties:
392392
authentication_handlers:
393-
description: The ways authentication can be established to authenticate as the user.
393+
description: The ways authentication can be established to authenticate as a user. Used for CouchDB compatibility. Always contains "default" and "cookie".
394394
type: array
395-
items:
396-
type: string
395+
enum:
396+
- ["default", "cookie"]
397+
default: ["default", "cookie"]
397398
ok:
399+
description: Used for CouchDB compatibility. Always true.
398400
type: boolean
401+
enum:
402+
- true
399403
userCtx:
400404
type: object
401405
properties:
402406
channels:
403-
description: |
404-
A map of the channels the user has access to and the sequence number each channel was created at.
405-
406-
The key is the channel name and the value is the sequence number.
407+
description: A map of the channels in the default collection that the user is in along with the sequence number the user was granted access. This does not include inherited channels through roles.
407408
type: object
409+
additionalProperties:
410+
x-additionalPropertiesName: channelName
411+
type: number
412+
minimum: 1
413+
description: The sequence number the user was granted access.
414+
title: sequence number
415+
example:
416+
"!": 1
417+
"channelA": 2
408418
name:
409419
description: The name of the user.
410420
type: string
411-
nullable: true
421+
minLength: 1
422+
required:
423+
- channels
424+
- name
425+
required:
426+
- authentication_handlers
427+
- ok
428+
- userCtx
412429
title: User Session Information
413430
OIDC-callback:
414431
type: object
@@ -1162,24 +1179,10 @@ Database:
11621179
type: number
11631180
default: 1
11641181
cors:
1165-
description: CORS configuration for this database; if present, overrides server's config.
1166-
type: object
1167-
properties:
1168-
headers:
1169-
description: List of allowed headers
1170-
type: array
1171-
items:
1172-
type: string
1173-
login_origin:
1174-
description: List of allowed login origins
1175-
type: array
1176-
items:
1177-
type: string
1178-
origin:
1179-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
1180-
type: array
1181-
items:
1182-
type: string
1182+
allOf:
1183+
- $ref: "#/CORS"
1184+
- type: object
1185+
description: CORS configuration for this database; if present, overrides server's config.
11831186
delta_sync:
11841187
description: |-
11851188
Delta sync configuration settings.
@@ -2124,26 +2127,10 @@ Startup-config:
21242127
type: boolean
21252128
default: true
21262129
cors:
2127-
type: object
2128-
properties:
2129-
headers:
2130-
description: List of allowed headers
2131-
type: array
2132-
items:
2133-
type: string
2134-
login_origin:
2135-
description: List of allowed login origins
2136-
type: array
2137-
items:
2138-
type: string
2139-
max_age:
2140-
description: Maximum age of the CORS Options request
2141-
type: integer
2142-
origin:
2143-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
2144-
type: array
2145-
items:
2146-
type: string
2130+
allOf:
2131+
- type: object
2132+
description: CORS configuration for all databases
2133+
- $ref: "#/CORS"
21472134
enable_advanced_auth_dp:
21482135
description: |-
21492136
Whether to enable the DP permissions check feature of admin auth.
@@ -3183,3 +3170,42 @@ IndexInitStatus:
31833170
- last_error
31843171
- index_status
31853172
title: IndexInitStatus
3173+
CORS:
3174+
type: object
3175+
properties:
3176+
headers:
3177+
description: |-
3178+
List of allowed headers. These headers will be added the `Access-Control-Allow-Headers` response to a valid CORS request.
3179+
3180+
A recommended minimum set of values should be `["Accept-Encoding", "Authorization", "Content-Type", "If-Match"]`.
3181+
type: array
3182+
items:
3183+
type: string
3184+
example:
3185+
- Accept-Encoding
3186+
- Authorization
3187+
- Content-Type
3188+
- If-Match
3189+
login_origin:
3190+
description: |-
3191+
List of allowed origins to apply to public `/{db}/_session` API.
3192+
3193+
To use cors on `/{db}/_session`, the domain must be present in both `login_origin` and `origin`.
3194+
3195+
If configured, `Authorization` must be included in headers.
3196+
type: array
3197+
items:
3198+
type: string
3199+
example: ["https://example.com"]
3200+
max_age:
3201+
description: Value for `Access-Control-Maximum-Age`. Uses 0 by default.
3202+
type: integer
3203+
default: 0
3204+
origin:
3205+
description: |-
3206+
List of allowed origins for the public API. The request `Origin` header is checked against these values. If successful the `Origin` header is returned in the HTTP response header as `Access-Control-Allow-Origin`.
3207+
type: array
3208+
items:
3209+
type: string
3210+
example: ["https://example.com"]
3211+
title: Cors Configuration

docs/api/paths/admin/db-_facebook.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ post:
1212
description: |-
1313
Creates a new session based on a Facebook user. On a successful session creation, a session cookie is stored to keep the user authenticated for future API calls.
1414
15-
If CORS is enabled, the origin must match an allowed login origin otherwise an error will be returned.
15+
If `Origin` header is passed to this endpoint, the `Origin` header must match both the `cors.login_origin` and `cors.origin` configuration options.
1616
requestBody:
1717
content:
1818
application/json:
@@ -28,7 +28,7 @@ post:
2828
'200':
2929
description: Session created successfully
3030
'400':
31-
$ref: ../../components/responses.yaml#/Invalid-CORS
31+
$ref: ../../components/responses.yaml#/Invalid-CORS-LoginOrigin
3232
'401':
3333
description: Received error from Facebook verifier
3434
content:

docs/api/paths/admin/db-_google.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ post:
1212
description: |-
1313
Creates a new session based on a Google user. On a successful session creation, a session cookie is stored to keep the user authenticated for future API calls.
1414
15-
If CORS is enabled, the origin must match an allowed login origin otherwise an error will be returned.
15+
If `Origin` header is passed to this endpoint, the `Origin` header must match both the `cors.login_origin` and `cors.origin` configuration options.
1616
requestBody:
1717
content:
1818
application/json:
@@ -28,7 +28,7 @@ post:
2828
'200':
2929
description: Session created successfully
3030
'400':
31-
$ref: ../../components/responses.yaml#/Invalid-CORS
31+
$ref: ../../components/responses.yaml#/Invalid-CORS-LoginOrigin
3232
'401':
3333
description: Received error from Google token verifier or invalid application ID in the config
3434
content:

docs/api/paths/admin/db-_session.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,17 @@ post:
6565
session_id: c5af80a039db4ed9d2b6865576b6999935282689
6666
expires: '2022-01-21T15:24:44Z'
6767
cookie_name: SyncGatewaySession
68-
'400':
69-
$ref: ../../components/responses.yaml#/Invalid-CORS
68+
"401":
69+
$ref: ../../components/responses.yaml#/Unauthorized
7070
'404':
71-
$ref: ../../components/responses.yaml#/Not-found
71+
description: Return if database does not exist
72+
content:
73+
application/json:
74+
schema:
75+
$ref: ../../components/schemas.yaml#/HTTP-Error
76+
example:
77+
error: not_found
78+
reason: no such database "invalid-db"
7279
tags:
7380
- Session
7481
operationId: post_db-_session

docs/api/paths/public/db-_facebook.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ post:
1212
description: |-
1313
Creates a new session based on a Facebook user. On a successful session creation, a session cookie is stored to keep the user authenticated for future API calls.
1414
15-
If CORS is enabled, the origin must match an allowed login origin otherwise an error will be returned.
15+
If `Origin` header is passed to this endpoint, the `Origin` header must match both the `cors.login_origin` and `cors.origin` configuration options.
1616
requestBody:
1717
content:
1818
application/json:
@@ -28,7 +28,7 @@ post:
2828
'200':
2929
description: Session created successfully
3030
'400':
31-
$ref: ../../components/responses.yaml#/Invalid-CORS
31+
$ref: ../../components/responses.yaml#/Invalid-CORS-LoginOrigin
3232
'401':
3333
description: Received error from Facebook verifier
3434
content:

docs/api/paths/public/db-_google.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ post:
1212
description: |-
1313
Creates a new session based on a Google user. On a successful session creation, a session cookie is stored to keep the user authenticated for future API calls.
1414
15-
If CORS is enabled, the origin must match an allowed login origin otherwise an error will be returned.
15+
If `Origin` header is passed to this endpoint, the `Origin` header must match both the `cors.login_origin` and `cors.origin` configuration options.
1616
requestBody:
1717
content:
1818
application/json:
@@ -28,7 +28,7 @@ post:
2828
'200':
2929
description: Session created successfully
3030
'400':
31-
$ref: ../../components/responses.yaml#/Invalid-CORS
31+
$ref: ../../components/responses.yaml#/Invalid-CORS-LoginOrigin
3232
'401':
3333
description: Received error from Google token verifier or invalid application ID in the config
3434
content:

0 commit comments

Comments
 (0)