@@ -93,20 +93,29 @@ Both provide a way to transmit data between the backend of the app in the Nextcl
93
93
The following combinations of attributes might be relevant for various scenarios:
94
94
95
95
#. Plain frontend route: ``Controller `` class
96
- #. Plain Frontend with CRSF checks disabled: ``Controller `` class and ``#[NoCSRFRequired] `` attribute on the method
96
+ #. Plain frontend with CRSF checks disabled: ``Controller `` class and ``#[NoCSRFRequired] `` attribute on the method
97
+ #. REST route with CORS enabled: ``Controller `` class and ``#[CORS] `` and ``#[NoCSRFRequired] `` attributes on the route
97
98
#. OCS-based route: ``OCSController `` class
98
- #. OCS-based route with CSRF disabled : ``OCSController `` class and ``#[NoCSRFRequired ] `` attribute on the method
99
+ #. OCS-based route with CORS enabled : ``OCSController `` class and ``#[CORS ] `` attribute on the method
99
100
100
101
.. warning ::
101
102
Adding the ``#[NoCRSFRequired] `` attribute imposes a security risk.
102
103
You should not add this to your controller methods unless you understand the implications and be sure that you absolutely need the attribute.
103
104
105
+ .. warning ::
106
+ Adding the attribute ``#[CORS] `` alone is not sufficient to allow access using CORS.
107
+ The CSRF checker will typically fail, so enabling CORS enforces you to disable the CSRF checker as well.
108
+ Although the disabled CSRF checker in itself is a security issue to consider, adding CORS opens up this even more.
109
+ You should make sure, that you understand the implications completely when enabling CORS and do so only when there is a good use case.
110
+
104
111
There are different ways a clients might interact with your APIs.
105
112
These ways depend on your API configuration (what you allow) and on which route the request is finally made.
106
113
107
114
- *Access from web frontend * means the user is browses the Nextcloud web frontend with a browser.
108
115
- *Access from an external app * indicates that the user is not using the normal browser (as logged in) but directly navigates a certain URL.
109
116
This can be in a new browser tab or an external program (like an Android app or simply a curl command line).
117
+ - *Access from external website * means that the user browses some third party web site and *magically * data from your app appears.
118
+ Technically, the other website would embed/load/use images, JSON data, or other resources from a URL pointing to the Nextcloud server.
110
119
111
120
.. list-table :: Comparison of different API types
112
121
:header-rows: 1
@@ -115,24 +124,35 @@ These ways depend on your API configuration (what you allow) and on which route
115
124
* - Description
116
125
- 1 (plain)
117
126
- 2 (w/o CSRF)
127
+ - 3 (CORS)
118
128
- 4 (OCS)
119
- - 4 (OCS w/o CSRF )
129
+ - 5 (OCS+CORS )
120
130
* - URL prefix (relative to server)
131
+ - ``/apps/<appid>/ ``
121
132
- ``/apps/<appid>/ ``
122
133
- ``/apps/<appid>/ ``
123
134
- ``/ocs/v2.php/apps/<appid>/ ``
124
135
- ``/ocs/v2.php/apps/<appid>/ ``
125
136
* - Access from web frontend
126
137
- yes
127
138
- yes (CSRF risk)
128
- - yes
129
139
- yes (CSRF risk)
140
+ - yes
141
+ - yes (CSRF risk [# ]_)
130
142
* - Access from external app
131
143
- ---
132
144
- yes
145
+ - yes
133
146
- yes (with header [# ]_)
134
147
- yes
148
+ * - Access from external website
149
+ - ---
150
+ - ---
151
+ - yes
152
+ - ---
153
+ - yes
135
154
* - Encapsulated data
155
+ - no
136
156
- no
137
157
- no
138
158
- yes (JSON or XML)
@@ -149,4 +169,7 @@ As a rule of thumb one can conclude that OCS provides a good way to handle most
149
169
The only exception to this is if you want to provide an API for external usage where you have to comply with an externally defined API scheme.
150
170
Here, the encapsulation introduced in OCS and CSRF checks might be in your way.
151
171
172
+ .. [# ] Only if you have set ``#[NoCSRFRequired] ``.
173
+ OCS controllers have other CSRF checks in place that might with CORS without disabling the CSRF checks completely.
174
+ Using the ``OCS-APIREQUEST `` header is also a CSRF protection but is compatible with CORS.
152
175
.. [# ] The OCS controller needs the request header ``OCS-APIREQUEST `` to be set to ``true ``.
0 commit comments