Skip to content

Add unit tests for security-relevant helpers and report test coverage #2102

Open

Description

@duderoot

Current Behavior

Vitest and Playwright are set up and run in CI, but the pure helpers that guard security-relevant behavior have no unit tests:

  • isUrlSaveForRedirect() in src/shared/utils.js is the open-redirect guard for the post-login redirect query parameter. Nothing checks that it keeps rejecting other origins, protocol-relative URLs, javascript:/data:/blob: URLs or paths outside the allowed roots.
  • hasPermission(), storePermissions() and getPermissions() in src/shared/permissions.js gate what the UI shows (via the v-permission directive and permissionsMixin). The e2e permission specs cover them through the UI, but nothing checks edge cases such as missing or corrupt stored permissions directly.
  • The HTML-building formatters in src/shared/common.js rely on xss-filters for escaping. Nothing checks that untrusted values stay escaped, so removing an escape call during a refactoring would go unnoticed.

There is also no coverage report, so it is not visible which parts of the code are untested.

These are what remains of #1731 after the move to Vitest and Playwright.

Proposed Behavior

  1. Unit tests (Vitest, colocated *.test.js) for:
    • isUrlSaveForRedirect(): allowed same-origin paths, including under a non-root context path, and rejection of other origins, //host, backslash and percent-encoded variants, non-http(s) schemes, disallowed paths and empty input.
    • hasPermission() / storePermissions() / getPermissions(): granted and missing permissions, and absent, corrupt or non-array stored data.
    • The HTML-building formatters in src/shared/common.js: hostile input (<script>, attribute break-outs, javascript: links) comes out escaped, while normal input renders as before.
  2. Each test group proven effective by mutation: temporarily removing the guarded check makes the tests fail.
  3. Optional, report-only coverage: @vitest/coverage-v8 and an npm run test-coverage script that writes coverage/ (text + lcov), with no enforced threshold.

No production code changes are intended. Surprising behavior found along the way would be documented in the tests and raised separately.

Checklist

Activity

  1. added
    enhancement
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions