• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IJHack / QtPass / 46170777129

28 Nov 2026 05:29PM UTC coverage: 94.493% (+0.02%) from 94.471%
46170777129

push

github

web-flow
Folders keep their name in the tree; an edit that adds readers asks (#2382)

With signed recipient lists, someone on the store's top list who can
push to a shared store could delete a sub-folder's signed list and
rename the folder (to `admins.gpg`, say). The tree stripped `.gpg` from
every name, so it still read `admins`; the refusal to fall back to a
parent's list looks a removed list up by its path, so it did not apply;
and the next edit of an entry there was encrypted to the top list, the
attacker included, without a word.

- StoreModel drops `.gpg` from entry names only; a folder is shown and
  found by its real name.
- Pass::readersAnEditWouldAdd() names who the folder's list would add
  as readers of an existing entry (the probe from #2375 against the
  entry's recipients, each name with its key ID); PasswordDialog asks
  before saving over an entry when anyone would, and asks again if the
  list changed while the question was open.
- Because a pusher can also write an entry's recipient IDs, EntryRecord
  keeps, outside the store, the entry paths this device saved (hashed),
  seeded once when the store is opened with a signing key (trust on
  first use, tried once per run) and extended as inserts,
  re-encryptions, moves and copies land. With signed lists, an edit of
  an entry at a path never saved here, whose folder takes a parent's
  list, is asked about whatever its IDs say. Dot folders, links and
  junctions are left out of the walk; a linked store root is followed.

Lost convenience: saving over an entry whose readers the list would
widen asks once, and the first edit of an entry a teammate created in
an inheriting folder of a signed store asks once. Not covered (CHANGELOG
and SECURITY.md): a new entry, bytes swapped in under a path this
device saved, edits when the list cannot be read, and the pass backend.

Tests: the tree and the search keep a folder's `.gpg` name; the dialog
asks, cancels, re-asks on a changed list and saves; with real... (continued)

148 of 158 new or added lines in 6 files covered. (93.67%)

10913 of 11549 relevant lines covered (94.49%)

24195.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.79
/src/entryrecord.cpp
1
// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
/**
4
 * @file
5
 * @brief Implements EntryRecord: a JSON file of hashed entry paths, written
6
 *        under a lock file as the generation record is.
7
 */
8
#include "entryrecord.h"
9
#include "gpgidgeneration.h"
10
#include "qtpasslogging.h"
11

12
#include <QDir>
13
#include <QFileInfo>
14
#include <QJsonDocument>
15
#include <QJsonObject>
16
#include <QLockFile>
17
#include <QMutex>
18
#include <QSaveFile>
19
#include <QSet>
20

21
#include <optional>
22

23
namespace {
24

25
constexpr int kRecordFormat = 1;
26
/// More entries than any store holds: past it a seed stops rather than
27
/// fill the record with a runaway tree.
28
constexpr int kMaxSeeded = 200000;
29
constexpr int kLockTimeoutMs = 2000;
30

31
/**
32
 * @brief The record: hashed entry paths and hashed store roots seeded.
33
 */
34
struct Record {
466 ✔
35
  QJsonObject entries; ///< Path hash to 1.
36
  QJsonObject stores;  ///< Store root hash to 1.
37
};
38

39
/**
40
 * @brief Read the record.
41
 * @return It, empty when there is none yet; nothing when it cannot be read.
42
 */
43
auto load() -> std::optional<Record> {
234 ✔
44
  const QString path = EntryRecord::recordFile();
234 ✔
45
  if (!QFileInfo::exists(path)) {
234 ✔
46
    return Record{};
16 ✔
47
  }
48
  QFile file(path);
226 ✔
49
  if (!file.open(QIODevice::ReadOnly)) {
226 ✔
NEW
50
    return std::nullopt;
×
51
  }
52
  QJsonParseError parse{};
226 ✔
53
  const QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &parse);
226 ✔
54
  if (parse.error != QJsonParseError::NoError || !doc.isObject() ||
451 ✔
55
      doc.object().value(QLatin1String("format")).toInt() != kRecordFormat) {
451 ✔
56
    return std::nullopt;
1 ✔
57
  }
58
  return Record{doc.object().value(QLatin1String("entries")).toObject(),
675 ✔
59
                doc.object().value(QLatin1String("stores")).toObject()};
450 ✔
60
}
226 ✔
61

62
/**
63
 * @brief Write the record, owner-only, replacing it whole.
64
 * @param record What to write.
65
 * @return Whether it was written.
66
 */
67
auto save(const Record &record) -> bool {
221 ✔
68
  QJsonObject root;
221 ✔
69
  root.insert(QLatin1String("format"), kRecordFormat);
221 ✔
70
  root.insert(QLatin1String("entries"), record.entries);
221 ✔
71
  root.insert(QLatin1String("stores"), record.stores);
221 ✔
72
  QSaveFile file(EntryRecord::recordFile());
221 ✔
73
  if (!file.open(QIODevice::WriteOnly)) {
221 ✔
74
    return false;
75
  }
76
  file.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
221 ✔
77
  const QByteArray bytes = QJsonDocument(root).toJson(QJsonDocument::Compact);
221 ✔
78
  return file.write(bytes) == bytes.size() && file.commit();
221 ✔
79
}
221 ✔
80

81
/**
82
 * @brief Add the `*.gpg` entries in @p dir and its folders to @p found, up
83
 *        to @p limit. A name starting with "." is left out before the walk
84
 *        goes into it (.git, say, which QDir does not count as hidden on
85
 *        Windows), and so are links and junctions, as the tree shows them.
86
 * @param dir A folder.
87
 * @param limit At most this many entries in all.
88
 * @param found Receives the entries' absolute paths.
89
 */
90
void collectEntries(const QString &dir, int limit, QStringList &found) {
61 ✔
91
  const QFileInfoList children = QDir(dir).entryInfoList(
122 ✔
92
      QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot);
61 ✔
93
  for (const QFileInfo &child : children) {
211 ✔
94
    if (found.size() >= limit) {
150 ✔
95
      return;
96
    }
97
    // A junction is no link to Qt on Windows, so it is named here too.
98
    if (child.fileName().startsWith(QLatin1Char('.')) || child.isSymLink() ||
300 ✔
99
        child.isJunction()) {
103 ✔
100
      continue;
47 ✔
101
    }
102
    if (child.isDir()) {
103 ✔
103
      collectEntries(child.absoluteFilePath(), limit, found);
32 ✔
104
    } else if (child.fileName().endsWith(QLatin1String(".gpg"),
87 ✔
105
                                         Qt::CaseInsensitive)) {
106
      found << child.absoluteFilePath();
134 ✔
107
    }
108
  }
109
}
110

111
/**
112
 * @brief The entries @p path stands for: itself, or every `*.gpg` below it
113
 *        when it is a folder (collectEntries()).
114
 * @param path An entry or a folder.
115
 * @param limit At most this many.
116
 * @return Their absolute paths.
117
 */
118
auto entriesOf(const QString &path, int limit) -> QStringList {
236 ✔
119
  const QFileInfo info(path);
236 ✔
120
  if (info.isSymLink()) {
236 ✔
NEW
121
    return {};
×
122
  }
123
  if (!info.isDir()) {
236 ✔
124
    return {info.absoluteFilePath()};
382 ✔
125
  }
126
  QStringList found;
45 ✔
127
  collectEntries(path, limit, found);
45 ✔
128
  return found;
129
}
427 ✔
130

131
/**
132
 * @brief Run @p change on the record under its lock and save it.
133
 * @param change Edits the record; returns whether anything changed.
134
 */
135
template <typename Change> void update(Change change) {
223 ✔
136
  const QString path = EntryRecord::recordFile();
223 ✔
137
  QDir().mkpath(QFileInfo(path).absolutePath());
669 ✔
138
  QLockFile lock(path + QStringLiteral(".lock"));
446 ✔
139
  if (!lock.tryLock(kLockTimeoutMs)) {
223 ✔
140
    qCWarning(lcQtPass) << "Entry record busy, not updated:" << path;
4 ✔
141
    return;
2 ✔
142
  }
143
  std::optional<Record> record = load();
221 ✔
144
  if (!record) {
221 ✔
NEW
145
    qCWarning(lcQtPass) << "Entry record unreadable, not updated:" << path;
×
146
    return;
147
  }
148
  if (change(*record) && !save(*record)) {
221 ✔
NEW
149
    qCWarning(lcQtPass) << "Entry record not written:" << path;
×
150
  }
151
}
223 ✔
152

153
} // namespace
154

155
auto EntryRecord::recordFile() -> QString {
695 ✔
156
  return QFileInfo(GpgIdGeneration::recordFile()).absolutePath() +
2,085 ✔
157
         QStringLiteral("/QtPass-entries.json");
1,390 ✔
158
}
159

160
auto EntryRecord::known(const QString &entryFile) -> bool {
13 ✔
161
  const QString path = recordFile();
13 ✔
162
  QLockFile lock(path + QStringLiteral(".lock"));
26 ✔
163
  if (!lock.tryLock(kLockTimeoutMs)) {
13 ✔
164
    return false;
165
  }
166
  const std::optional<Record> record = load();
13 ✔
167
  return record && record->entries.contains(GpgIdGeneration::key(entryFile));
25 ✔
168
}
13 ✔
169

170
void EntryRecord::remember(const QStringList &paths) {
263 ✔
171
  QStringList entries;
263 ✔
172
  for (const QString &path : paths) {
463 ✔
173
    entries << entriesOf(path, kMaxSeeded);
400 ✔
174
  }
175
  if (entries.isEmpty()) {
263 ✔
176
    return;
177
  }
178
  update([&entries](Record &record) {
185 ✔
179
    for (const QString &entry : std::as_const(entries)) {
383 ✔
180
      record.entries.insert(GpgIdGeneration::key(entry), 1);
396 ✔
181
    }
182
    return true;
185 ✔
183
  });
184
}
185

186
void EntryRecord::seedStore(const QString &storeRoot) {
46 ✔
187
  if (storeRoot.isEmpty() || !QFileInfo(storeRoot).isDir()) {
92 ✔
188
    return;
8 ✔
189
  }
190
  const QString store = GpgIdGeneration::key(QDir::cleanPath(storeRoot));
46 ✔
191
  // One try per store and run, the first open: a seed that could not be
192
  // written (the record busy or unreadable) is not retried at a later
193
  // init(), which may come after a pull and would take what the pull
194
  // brought as saved. The store then stays unseeded, and an edit asks.
195
  {
196
    static QMutex mutex;
53 ✔
197
    static QSet<QString> tried;
53 ✔
198
    const QMutexLocker locker(&mutex);
199
    if (tried.contains(store)) {
46 ✔
200
      return;
201
    }
202
    tried.insert(store);
38 ✔
203
  }
46 ✔
204
  update([&storeRoot, &store](Record &record) {
38 ✔
205
    if (record.stores.contains(store)) {
36 ✔
206
      return false;
207
    }
208
    // A store root may itself be a link (a synced folder): walked where it
209
    // points; links below it are still left out.
210
    const QString root = QFileInfo(storeRoot).canonicalFilePath();
36 ✔
211
    for (const QString &entry : entriesOf(root, kMaxSeeded)) {
132 ✔
212
      record.entries.insert(GpgIdGeneration::key(entry), 1);
120 ✔
213
    }
214
    record.stores.insert(store, 1);
36 ✔
215
    return true;
216
  });
217
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc