QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
PathValidator Class Reference

Password-store path-boundary checks. More...

#include <pathvalidator.h>

Static Public Member Functions

static auto isPathInStore (const QString &storeRoot, const QString &candidate) -> bool
 Check that a candidate path resolves inside the password store root, after following symlinks and resolving .. components.
static auto storeRelativePath (const QString &storeRoot, const QString &candidate) -> std::optional< QString >
 Where candidate lies in the store, judged as isPathInStore() judges it.
static auto isTargetSpelled (const QString &storeRoot, const QString &path) -> bool
 Whether path is spelled through the target of a store root that is itself a link, rather than from the root as configured.

Detailed Description

Password-store path-boundary checks.

Extracted from Util. Guards file/folder create, rename, and drag-drop against paths that resolve outside the configured password store.

Threat model: this catches mistakes and malformed input, such as a typed .., a pasted absolute path or a symlink that happens to point outside the store. It is not a defence against another process that can write to the store while QtPass runs: the check and the file operation that follows it are separate steps, and a symlink swapped in between them is not seen (the usual time-of-check/time-of-use gap of a path-based API). Anyone who can write to your password store can also replace its contents, so that is outside what QtPass can protect.

Definition at line 31 of file pathvalidator.h.

Member Function Documentation

◆ isPathInStore()

auto PathValidator::isPathInStore ( const QString & storeRoot,
const QString & candidate ) -> bool
static

Check that a candidate path resolves inside the password store root, after following symlinks and resolving .. components.

For candidates that already exist on disk the path is canonicalised via QFileInfo::canonicalFilePath() (which resolves symlinks). For candidates that do not yet exist (typical "create new file" flow) we walk up to the nearest existing ancestor, canonicalise that, then re-append the leaf components. This catches both user-typed .. escapes and symlinks pointing outside the store.

Parameters
storeRootPassword store root (typically QtPassSettings::getPassStore()).
candidatePath to validate. May be absolute or relative; relative paths are interpreted against the current working directory before resolution.
Returns
true if candidate resolves to a path equal to or strictly inside storeRoot; false otherwise (including when storeRoot itself does not exist).

Definition at line 13 of file pathvalidator.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTargetSpelled()

auto PathValidator::isTargetSpelled ( const QString & storeRoot,
const QString & path ) -> bool
static

Whether path is spelled through the target of a store root that is itself a link, rather than from the root as configured.

The Pass operations take the configured spelling (see the Pass class documentation); this names the one spelling that breaks that rule while still lying in the store. Nothing is resolved below the root.

Parameters
storeRootPassword store root, as configured.
pathAn absolute path; a relative one is never off-rule.
Returns
true when path lies under the root's canonical path but not under the root as configured, and the two differ.

Definition at line 69 of file pathvalidator.cpp.

Here is the caller graph for this function:

◆ storeRelativePath()

auto PathValidator::storeRelativePath ( const QString & storeRoot,
const QString & candidate ) -> std::optional< QString >
static

Where candidate lies in the store, judged as isPathInStore() judges it.

The relative path comes from the same canonical pair the check uses, so a store root reached through a link and a candidate spelled through the link's target still give team, not ../../data/pass/team.

Parameters
storeRootPassword store root.
candidatePath to place, as for isPathInStore().
Returns
The path relative to the store root, with / separators and empty for the root itself; nothing when isPathInStore() is false.

Definition at line 18 of file pathvalidator.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: