Security updates #394

Merged
jsheunis merged 14 commits from security into main 2026-10-26 14:15:29 +00:00
Owner

To address #393

To address https://hub.psychoinformatics.de/orinoco/shacl-vue/issues/393
The package-lock version in 9673c9665e contained an
upgrade to vue-virtual-scroller to 2.0.1. This has some form of regression that
causes continuous remounting behavior of a component rendered via dynamicscroller
and dynamicscrolleritem, in our case the NodeShapeViewer. This presented itself as
a UI glitch when the 'More details' button was clicked: the expanded blank nodes
section displayed superimposed on the following list item for a moment, then the
display corrected itself. Or sometimes the section did not even remain expanded,
and instead just flashed.

This pin reverts that behaviour to how it worked, as expected, before. I have not
determined what explicit change in vue-virtual-scroller causes this issue.
This is multi-pronged:
firstly to fix multiple existing vulnerabilities in nested dependencies:
- upgraded vitepress which had vulnerable dependencies
- removed unplugin-fonts which had vulnerabilities; loading fonts directly from index file now
- removed vitepress-plugin-mermaid because incompatible with upgraded vitepress
- replaced above with vitepress-mermaid-viewer, and using dagre to solve rendering issue
- vitepress-mermaid-viewer required a peer dependency override, ideally temporary
secondly to install requirement for future security features: dompurify

after the above, no vulnerabilities detected by npm audit
This allows the specification of config options at build time via a path to
a JSON or YAML file, using the new BUILD_CONFIG env variable, e.g.:

BUILD_CONFIG='path/to/config/file.yaml' npm run build:app

This is read by Vite at build time and injected into environment variables
that are made accessible to the rest of the application in the standard
vite approach, i.e. via 'import.meta.env.MY_VARIABLE' in javascript/vue
files and '%MY_VARIABLE%' in html.

Note that values of keys in the config object are JSON stringified when
injected into the usable context, which means they will have to be parsed
again where necessary.

TBD whether a restriction should be placed on keys to start with 'VITE_'
in order for them to be injected or not. Currently that is not a restriction.
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.
jsheunis changed title from Security updates to wip: Security updates 2026-10-23 13:56:52 +00:00
As 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.
jsheunis changed title from wip: Security updates to Security updates 2026-10-26 12:49:43 +00:00
Sign in to join this conversation.
No description provided.