Re-enable CSRF check supported by DPM now

This commit is contained in:
Maikel Linke
2025-08-11 15:13:35 +10:00
parent 342ef4e9eb
commit 842f4ae40e
2 changed files with 11 additions and 7 deletions

View File

@@ -23,7 +23,8 @@
scopes-uri="https://cdn.startinblox.com/owl/dfc/taxonomies/scopes.jsonld"
noRouter
auto-lang
lang="en">
lang="en"
auth-token="#{form_authenticity_token}">
</solid-permissioning>
%script{type: "module", src: "https://cdn.jsdelivr.net/npm/@startinblox/solid-data-permissioning@latest/dist/index.js"}

View File

@@ -8,12 +8,7 @@ module DfcProvider
'cqcm-dev' => "https://api.proxy-dev.cqcm.startinblox.com/profile",
}.freeze
# DANGER!
# This endpoint is open to CSRF attacks.
# This is a temporary measure until the DFC Permissions module accesses
# the API with a valid OIDC token to authenticate the user.
skip_before_action :verify_authenticity_token
prepend_before_action :move_authenticity_token
before_action :check_enterprise
def index
@@ -101,5 +96,13 @@ module DfcProvider
grantee: platform_id,
).pluck(:scope)
end
# The DFC Permission Module is sending tokens in the Authorization header.
# It assumes that it's an OIDC access token but we are passing the Rails
# CSRF token to the component to allow POST request with cookie auth.
def move_authenticity_token
token = request.delete_header('HTTP_AUTHORIZATION').to_s.split.last
request.headers['X-CSRF-Token'] = token if token
end
end
end