Skip to content

Commit 61181ba

Browse files
committed
Add a feature flag to optionally enable permission check in LC api
1 parent b075488 commit 61181ba

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

doc/sphinx-guides/source/installation/localcontexts.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ See https://github.com/gdcc/dataverse-external-vocab-support/blob/main/packages/
2929

3030
Lastly, if you wish the Local Contexts information to be shown in the summary section of the dataset page, as shown in the image above, you should add `LCProjectUrl` to list of custom summary fields via use of the :ref:`:CustomDatasetSummaryFields` setting.
3131

32+
Optionally, one could also set the dataverse.feature.add-local-contexts-permission-check FeatureFlag to true. This assures that only users editing datasets can use the LocalContexts search functionality.
33+
However, as this currently would also require setting the dataverse.feature.api-session-auth, the security implications of which haven't been fully explored, it is not recommended unless problematic use is seen.
34+
(When API access via OpenIdConnect is available, use of api-session-auth would not be required.)
35+

src/main/java/edu/harvard/iq/dataverse/api/LocalContexts.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import edu.harvard.iq.dataverse.api.auth.AuthRequired;
1616
import edu.harvard.iq.dataverse.authorization.Permission;
1717
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
18+
import edu.harvard.iq.dataverse.settings.FeatureFlags;
1819
import edu.harvard.iq.dataverse.settings.JvmSettings;
1920
import edu.harvard.iq.dataverse.util.json.JsonUtil;
2021
import jakarta.ejb.EJB;
@@ -50,7 +51,11 @@ public Response getDatasetLocalContexts(@Context ContainerRequestContext crc, @P
5051
DataverseRequest req = createDataverseRequest(getRequestUser(crc));
5152

5253
// Check if the user has edit dataset permission
53-
if (!permissionService.userOn(req.getUser(), dataset).has(Permission.EditDataset)) {
54+
/* Feature flag to skip permission check
55+
* If you add the api-session-auth FeatureFlag, you can verify if the user has edit permissions
56+
*
57+
*/
58+
if (FeatureFlags.ADD_LOCAL_CONTEXTS_PERMISSION_CHECK.enabled() && !permissionService.userOn(req.getUser(), dataset).has(Permission.EditDataset)) {
5459
return error(Response.Status.FORBIDDEN,
5560
"You do not have permission to query LocalContexts about this dataset.");
5661
}
@@ -100,8 +105,7 @@ public Response getDatasetLocalContexts(@Context ContainerRequestContext crc, @P
100105
@GET
101106
@Path("/datasets/{id}/{projectId}")
102107
@Produces(MediaType.APPLICATION_JSON)
103-
public Response searchLocalContexts(@Context ContainerRequestContext crc, @PathParam("id") String datasetId,
104-
@PathParam("projectId") String projectId) {
108+
public Response searchLocalContexts(@PathParam("id") String datasetId, @PathParam("projectId") String projectId) {
105109
try {
106110
Dataset dataset = findDatasetOrDie(datasetId);
107111
String localContextsUrl = JvmSettings.LOCALCONTEXTS_URL.lookupOptional().orElse(null);

src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public enum FeatureFlags {
2626

2727
/**
28-
* Enables API authentication via session cookie (JSESSIONID). Caution: Enabling this feature flag exposes the installation to CSRF risks
28+
* Enables API authentication via session cookie (JSESSIONID). Caution: Enabling this feature flag may expose the installation to CSRF risks
2929
* @apiNote Raise flag by setting "dataverse.feature.api-session-auth"
3030
* @since Dataverse 5.14
3131
*/
@@ -151,6 +151,21 @@ public enum FeatureFlags {
151151
* @since Dataverse 6.5
152152
*/
153153
VERSION_NOTE("enable-version-note"),
154+
/**
155+
* This flag adds a permission check to assure that the user calling the
156+
* /api/localcontexts/datasets/{id} can edit the dataset with that id. This is
157+
* currently the only use case - see
158+
* https://github.com/gdcc/dataverse-external-vocab-support/tree/main/packages/local_contexts.
159+
* The flag adds additional security to stop other uses, but would currently
160+
* have to be used in conjunction with the api-session-auth feature flag (the
161+
* security implications of which have not been fully investigated) to still
162+
* allow adding Local Contexts metadata to a dataset.
163+
*
164+
* @apiNote Raise flag by setting
165+
* "dataverse.feature.add-local-contexts-permission-check"
166+
* @since Dataverse 6.5
167+
*/
168+
ADD_LOCAL_CONTEXTS_PERMISSION_CHECK("add-local-contexts-permission-check"),
154169

155170
;
156171

0 commit comments

Comments
 (0)