Security updates #394
No reviewers
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!394
Loading…
Reference in a new issue
No description provided.
Delete branch "security"
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?
To address #393
This is part of an overall security heightening effort; in this case to prevent XSS attacks via html injection into components with v-html directives. This new component uses DOMpurify to sanitize html before it is passed to v-html. The SanitizedHtmlViewer component takes an html tag as input to the 'as' prop, so that it can be declaratively used instead of any html tag, e.g. 'div', 'p', or 'span'. It also takes the unsanitized html as input. DOMpurify can be configured using app build-time configuration, and will accept an object with any standard DOMpurify options. The default is: { WHOLE_DOCUMENT: true, USE_PROFILES: { html: true, svg: true, } } The component also uses Vue's defineOptions to set inheritAttrs to false, which allows attributes set on the instantiated component to be passed through and set on the template 'component' via v-bind='. This allows html tag attributes like 'id' and 'class' to work as expected on the resulting html node. Example usage: <SanitizedHtmlViewer as='div' :html='renderedMarkdown' class='markdown-preview'/> This usage approach now replaces all previous instances of v-html usage in the app.Another security-heightening feature: content security policy. This new feature depends on the existing build configuration support. Deployment- specific CSP content can be configured via the CSP_CONTENT option, e.g.: CSP_CONTENT: connect-src: - https://hub.psychoinformatics.de/ - https://concepts.datalad.org/ This is parsed by a new addition to the vite config 'serializeCsp(csp)' which serializes input CSP directives and associated values into strings that can be included in the correct location in index.html meta tag: content='%CSP_CONTENT' Note that the 'self' specification in any directive, if provided via YAML, should be enclosed in single AND double quotes, in order to retain the required single quotes for the html tag. There is no default CSP introduced by this featue, just an empty string. This means shacl-vue's current CSP is unrestricted by default.Security updatesto wip: Security updatesAs part of a wider security-heightening process, we introduce the secureFetch method. This method in from io module replaces all app-wide usage of fetch (specifically GET), which is basically only in three scenarios: - fetching the configuration file content - fetching content specified in the configuration file - fetch turtle content from the integrated dumpthings backend secureFetch can be configured at build time, via the BUILD_CONFIG file, to control specific aspects of the fetch operation. The result of a constraint violation is that an error will be thrown, visible in the console. An example config: FETCH: MAX_BYTES: 5_000 TIMEOUT_MS: 10_000 CONTENT_TYPES: ... Here: - MAX_BYTES specifies the maximum content size that secureFetch can fetch. By default this is unspecified and unconstrained. - TIMEOUT_MS specifies the maximum time a request is allowed to take before aborting By default this is unspecified and unconstrained. - CONTENT_TYPES specifies the content types that the application is allowed to fetch The default in-app-specified content types are: { json: [ 'application/json', 'application/problem+json', ], html: [ 'text/html', ], yaml: [ 'application/yaml', 'application/x-yaml', 'text/yaml', 'text/plain', ], text: [ 'text/plain', ], rdf: [ 'application/ld+json', 'application/rdf+xml', 'text/turtle', 'application/n-triples', 'application/trig', ], svg: [ 'image/svg+xml', ], image: [ 'image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/avif', 'image/apng', 'image/bmp', ], } Build-time specification of CONTENT_TYPES (any) will override ALL in-app defaults. Note that the same keys MUST be used to re-specify existing defaults. New keys are not constrained. In addition to the above, secureFetch adds internal fetch options to constrain the operation further, thus making the request more secure: - method: 'GET' - credentials: 'omit' - method: 'cors' Options passed by the caller are preserved, although these do not take precedence over in-app-specified options. Note that there are two other indirect uses of an altered fetch in the app: via classDS.loadRDF(getURL) and shapesDS.loadRDF(getURL). loadRDF is a method defined in shacl-tulip, which in turn uses a modified fetch from '@rdfjs/fetch-lite'. These uses are not replaced with secureFetch in this commit; they would need to be addressed in shacl-tulip directly, or via an updated interface. shacl-tulip currently only constrains the expected content type to text/turtle.wip: Security updatesto Security updates