Security improvements #393
Labels
No labels
bug
config
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
orinoco/shacl-vue#393
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Firstly, packages and dependencies need to be upgraded to take care of existing vulnerabilities. This has mostly been done in
d31681bf1bThen, additional measures are necessary, especially in the context of a multi-tenant-based approach. The core idea here is that the administrator of a
shacl-vuedeployment and the provider of a configuration are not the same people/entities. The administrator build, deploys, and serves a singleshacl-vueinstance, and multiple tenants can use this frontend while supplying their own configuration files, and then the UI will present differently for them. It makes sense that a tenant will configure the user-facing aspects of their UI/UX, but this opens up vulnerabilities. We need to heighten security inshacl-vuein order to prevent any number of possible attacks. And any newly introduced security-specific config options should remain under the sole control of the system administrator (see also: #392)Investigating vulnerabilities
shacl-vuehas several features that allow externally provided resources to be fetched, loaded into some format, and then interpreted/displayed inside the app:front_page_content, for which the source is loaded via the content loading appproach mentioned above, is HTML that is rendered in a VueJSv-htmltag. This basically injects arbitrary HTML dynamically into a div. This arbitrary HTML can also contain or link JS scripts.class_url) and SHACL (shapes_url) and RDF (data_url; hardly ever provided in our deployments, but operational nonetheless). The turtle at these URLs are fetched and put directly into an N3 store.shacl-vuedeployment to include custom JS plugin code and custom VueJS components in the build process such that they become available to the deplopymentshacl-vueconfig options are urls for which the content isn't fetched but the url is used in e.g. anhreforsrctagThings to protect against
v-html-injected html runs scripts that have malicious intent, or if a url containing executable javascript is fetched.Mechanisms of protection
<script>) in order to prevent unwanted scripts from running, i.e. preventing client-side XSS attacks.Features to implement in
shacl-vue1. Content security policy
Useful options:
connect-srcdefault-srcThis can either be provided as an HTTP header in all responses from the server, or as
contentin themetatag (withhttp-equivattribute). The latter does not have access to all CSP features, but supports the useful ones for our use case.Example:
An important point regarding CSP specification and
shacl-vue: should such options be specified viashacl-vueconfig? Or can they even? As far as I can figure out, this won't be possible because:index.htmlwill be processed before the config file is even loaded, i.e. beforecontentattribute, which would be necessary once the possible CSP options are read from config, aren't processed by the browser. I.e. this would be ignored, as if no CSP is specified.This leaves two options:
These can of course be combined, we are not forced to decide on a single orthogonal aproach. This suggests that it would be useful to support build-time (i.e. Vite environment variable based) specification of CSP options in
shacl-vue(see issue: #392)To implement:
we can use Vite ENV variables, either set explicitly in build runtime environment or provided via an env file. e.g. in a file
env.production:and then this can be used in the Vue app:
2. Sanitization
We can use DOMPurify in a new component that will render sanitized html, via a computed ref. For example:
Here we can consider just including html (as opposed to also allowing svg and mathml). But a wide range of configuration options are available: https://github.com/cure53/DOMPurify#can-i-configure-dompurify. We should decide how we want to approach this. An option is to allow and pass through all DOMPurify config options, i.e. make it configurable via
shacl-vue. I don't think theshacl-vueconfig file is the correct home for this, because in the tenant setup that would allow individual tenants to specify how strict (or not) the sanitization should be, which would work against the reason for sanitizing in the first place. This means config during build time, i.e. the same approach as suggested above for specifying a content security policy.3. Fetch restrictions
The idea here is to allow restriction of several aspects of content being fetched by
shacl-vue. The CSP fetch directive can already control/limit (via allowlist) the origins from which content can be fetched, but does not help with restricting other apsects such as resource type and size, unintentional inclusion of credentials, redirect allowances, etc. All of this can be supported by updating thefetchcalls insideshacl-vue, perhaps creating a new centralfetchfunction that can be configured with these options. An illustrative example:All of these, again, could be configured at app startup. While
shacl-vueconfig is also possible, in the tenant approach this would work against the desired effect.What's next?
Implementation!
While working on:
I searched the app for all usage of
v-htmland saw several occurrences, e.g.:So we actually need the component to be able to deal with rendering all these base tags while sanitizing the html, and also render these tags with the intended classes etc.
A different way to approach this would be to use a Vue custom directive. So we would introduce something like a
v-html-sanitizedtag instead of using the existingv-htmltag. I need to read some more about how this would need to be built and declared and used...After reading that:
I decided against it, and rather just implemented the component. This is done in
b1e269112cNext step is CSP. An implementation is fairly straightforward: we need to load the build config (already supported), then check if any CSP options are defined, then parse these into the format that they are needed in in the
index.html.Example config:
Example format:
We can do the parsing as follows:
and then use it in
index.html:if
CSP_CONTENTis an empty string, no CSP is enforced by the browser, so the default is as expected.Basic CSP configuration support is now provided in
bb69bd46d8Now the question becomes: how should we construct allowlists for this, and which directives should we use. And should we rather approach it conservatively or liberally? E.g. if one specifies the
default-srcdirective as'self', it will say to the browser: you can only fetch resources for this page from the same domain that the site is hosted on. Then adding specific domains under more specific directives, e.g.image-srcorfont-srcwould individually and systematically open the gate for more sources. This would be the conservative route, and one would have to identify all possible trusted sources of content (fonts, images, text content, more). On the liberal side, one could exclude a directive setting to basically allow everything; and then pivot on specific directives that one might want to control (e.g.connect-srcthat controls scripts).While working a general "secure fetch" wrapper, which is intended to:
mode(basically alwayscors)redirects (we could conservatively alwayserror, but this could exclude legitimate origins)signal; do we actually want this? is it useful for security? what is a sensible timeout value?)I find myself questioning to what extent some of these features are really helpful i.t.o. improving security when looking at the complexity it introduces because of difficulty deciding on sensible values.
My feeling is that the following could be useful:
mode: 'cors'credentials: 'omit'I am not so sure about the rest...
This is what I currently have:
Searching through the code for instances of
fetch-GET, i found the following places where the wrapper would need to be used:configuration.jscomposable: fetching the config file (we know this will be in JSON or YAML format)configuration.jscomposable: fetching content at URLs provided via config file (here we are not sure what file type it is, although we could try to derive it from the extension in the URL)useData.jscomposable: fetching data fromdumpthings(here we know this will be in TTL or JSON format - the latter when paginated)useClasses.jsanduseShapes.jscomposables, we useloadRDFwhich is a method defined inshacl-tulip, which in turn uses a modifiedfetch(import fetch from '@rdfjs/fetch-lite'). Here we know that the source files would be some RDF format, we currently restrict it to'text/turtle'Added in #394