Skip to content

Commit 67efdce

Browse files
authored
[3.2.7 backport] CBG-4976 update the documentation for CORS (#7855)
1 parent a5f3935 commit 67efdce

File tree

8 files changed

+131
-120
lines changed

8 files changed

+131
-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: 71 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
@@ -1644,24 +1661,9 @@ Database:
16441661
16451662
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).
16461663
cors:
1647-
description: CORS configuration for this database; if present, overrides server's config.
1648-
type: object
1649-
properties:
1650-
origin:
1651-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
1652-
type: array
1653-
items:
1654-
type: string
1655-
login_origin:
1656-
description: List of allowed login origins
1657-
type: array
1658-
items:
1659-
type: string
1660-
headers:
1661-
description: List of allowed headers
1662-
type: array
1663-
items:
1664-
type: string
1664+
allOf:
1665+
- $ref: "#/CORS"
1666+
- type: object
16651667
logging:
16661668
description: Per-database logging configuration.
16671669
type: object
@@ -2145,26 +2147,10 @@ Startup-config:
21452147
description: The TLS key file to use for the REST APIs
21462148
type: string
21472149
cors:
2148-
type: object
2149-
properties:
2150-
origin:
2151-
description: 'List of allowed origins, use [''*''] to allow access from everywhere'
2152-
type: array
2153-
items:
2154-
type: string
2155-
login_origin:
2156-
description: List of allowed login origins
2157-
type: array
2158-
items:
2159-
type: string
2160-
headers:
2161-
description: List of allowed headers
2162-
type: array
2163-
items:
2164-
type: string
2165-
max_age:
2166-
description: Maximum age of the CORS Options request
2167-
type: integer
2150+
allOf:
2151+
- type: object
2152+
description: CORS configuration for all databases
2153+
- $ref: "#/CORS"
21682154
readOnly: true
21692155
logging:
21702156
description: The configuration settings for modifying Sync Gateway logging.
@@ -2977,3 +2963,42 @@ DatabaseState:
29772963
Starting: The database is in the process of going online.
29782964
Stopping: The database is no longer accepting connections and is being taken offline or deleted.
29792965
Resyncing: The database is offline and performing a resync operation.
2966+
CORS:
2967+
type: object
2968+
properties:
2969+
headers:
2970+
description: |-
2971+
List of allowed headers. These headers will be added the `Access-Control-Allow-Headers` response to a valid CORS request.
2972+
2973+
A recommended minimum set of values should be `["Accept-Encoding", "Authorization", "Content-Type", "If-Match"]`.
2974+
type: array
2975+
items:
2976+
type: string
2977+
example:
2978+
- Accept-Encoding
2979+
- Authorization
2980+
- Content-Type
2981+
- If-Match
2982+
login_origin:
2983+
description: |-
2984+
List of allowed origins to apply to public `/{db}/_session` API.
2985+
2986+
To use cors on `/{db}/_session`, the domain must be present in both `login_origin` and `origin`.
2987+
2988+
If configured, `Authorization` must be included in headers.
2989+
type: array
2990+
items:
2991+
type: string
2992+
example: ["https://example.com"]
2993+
max_age:
2994+
description: Value for `Access-Control-Maximum-Age`. Uses 0 by default.
2995+
type: integer
2996+
default: 0
2997+
origin:
2998+
description: |-
2999+
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`.
3000+
type: array
3001+
items:
3002+
type: string
3003+
example: ["https://example.com"]
3004+
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)