Skip to content

Commit fcd3a49

Browse files
authored
[3.3.1 backport] CBG-4975 update the documentation for CORS (#7854)
1 parent 998bdef commit fcd3a49

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
@@ -1664,24 +1681,10 @@ Database:
16641681
16651682
This also sets the default value of query param `request_plus` for [GET /{keyspace}/_changes](#operation/get_keyspace-_changes) or `request_plus` for [POST /{keyspace}/_changes](#operation/post_keyspace-_changes).
16661683
cors:
1667-
description: CORS configuration for this database; if present, overrides server's config.
1668-
type: object
1669-
properties:
1670-
origin:
1671-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
1672-
type: array
1673-
items:
1674-
type: string
1675-
login_origin:
1676-
description: List of allowed login origins
1677-
type: array
1678-
items:
1679-
type: string
1680-
headers:
1681-
description: List of allowed headers
1682-
type: array
1683-
items:
1684-
type: string
1684+
allOf:
1685+
- $ref: "#/CORS"
1686+
- type: object
1687+
description: CORS configuration for this database; if present, overrides server's config.
16851688
logging:
16861689
description: Per-database logging configuration.
16871690
type: object
@@ -2175,26 +2178,10 @@ Startup-config:
21752178
description: The TLS key file to use for the REST APIs
21762179
type: string
21772180
cors:
2178-
type: object
2179-
properties:
2180-
origin:
2181-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
2182-
type: array
2183-
items:
2184-
type: string
2185-
login_origin:
2186-
description: List of allowed login origins
2187-
type: array
2188-
items:
2189-
type: string
2190-
headers:
2191-
description: List of allowed headers
2192-
type: array
2193-
items:
2194-
type: string
2195-
max_age:
2196-
description: Maximum age of the CORS Options request
2197-
type: integer
2181+
allOf:
2182+
- type: object
2183+
description: CORS configuration for all databases
2184+
- $ref: "#/CORS"
21982185
readOnly: true
21992186
logging:
22002187
description: The configuration settings for modifying Sync Gateway logging.
@@ -3082,3 +3069,42 @@ IndexInitStatus:
30823069
- last_error
30833070
- index_status
30843071
title: IndexInitStatus
3072+
CORS:
3073+
type: object
3074+
properties:
3075+
headers:
3076+
description: |-
3077+
List of allowed headers. These headers will be added the `Access-Control-Allow-Headers` response to a valid CORS request.
3078+
3079+
A recommended minimum set of values should be `["Accept-Encoding", "Authorization", "Content-Type", "If-Match"]`.
3080+
type: array
3081+
items:
3082+
type: string
3083+
example:
3084+
- Accept-Encoding
3085+
- Authorization
3086+
- Content-Type
3087+
- If-Match
3088+
login_origin:
3089+
description: |-
3090+
List of allowed origins to apply to public `/{db}/_session` API.
3091+
3092+
To use cors on `/{db}/_session`, the domain must be present in both `login_origin` and `origin`.
3093+
3094+
If configured, `Authorization` must be included in headers.
3095+
type: array
3096+
items:
3097+
type: string
3098+
example: ["https://example.com"]
3099+
max_age:
3100+
description: Value for `Access-Control-Maximum-Age`. Uses 0 by default.
3101+
type: integer
3102+
default: 0
3103+
origin:
3104+
description: |-
3105+
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`.
3106+
type: array
3107+
items:
3108+
type: string
3109+
example: ["https://example.com"]
3110+
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)