Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

bug fixes

tilakpatel2213089266a94c
diff --git a/fincept-qt/CMakeLists.txt b/fincept-qt/CMakeLists.txt
index e3c7ceba3..24d350b90 100644
--- a/fincept-qt/CMakeLists.txt
+++ b/fincept-qt/CMakeLists.txt
@@ -3138,19 +3138,77 @@ add_custom_command(TARGET FinceptTerminal POST_BUILD
)
# Bundle yt-dlp for dashboard YouTube playback on all platforms.
-# Override path with: -DFINCEPT_YTDLP_EXE=/abs/path/to/yt-dlp[.exe]
-set(FINCEPT_YTDLP_EXE "" CACHE FILEPATH "Path to yt-dlp executable to bundle with FinceptTerminal")
-# Default OFF so builds on CI / macOS / Linux succeed without yt-dlp pre-installed.
-# Set ON only for official release builds where yt-dlp must be present.
-option(FINCEPT_REQUIRE_BUNDLED_YTDLP "Fail configure if yt-dlp is missing" OFF)
+#
+# Sourcing strategy (in priority order):
+# 1. -DFINCEPT_YTDLP_EXE=/abs/path/to/yt-dlp[.exe] — explicit override (air-gapped builds)
+# 2. Auto-download the pinned release from GitHub at configure time, verified by SHA-256.
+#
+# The download is the default so a clean checkout on any platform self-provisions
+# yt-dlp with zero machine setup. The pinned version + hashes make it reproducible
+# and tamper-evident. Bump FINCEPT_YTDLP_VERSION + the three hashes together when
+# upgrading (hashes come from the release's SHA2-256SUMS file).
+set(FINCEPT_YTDLP_EXE "" CACHE FILEPATH "Path to yt-dlp executable to bundle (overrides auto-download)")
+set(FINCEPT_YTDLP_VERSION "2026.03.17" CACHE STRING "Pinned yt-dlp release tag to download")
+option(FINCEPT_DOWNLOAD_YTDLP "Auto-download yt-dlp at configure time if no override is set" ON)
+# Default OFF so a transient network failure doesn't hard-block local dev builds.
+# Set ON for official release builds so a missing yt-dlp fails the build loudly.
+option(FINCEPT_REQUIRE_BUNDLED_YTDLP "Fail configure if yt-dlp can't be provisioned" OFF)
+
+# Per-platform release asset name + SHA-256 for the pinned version. Update all
+# three hashes whenever FINCEPT_YTDLP_VERSION changes.
+if(WIN32)
+ set(FINCEPT_YTDLP_ASSET "yt-dlp.exe")
+ set(FINCEPT_YTDLP_SHA256 "3db811b366b2da47337d2fcfdfe5bbd9a258dad3f350c54974f005df115a1545")
+elseif(APPLE)
+ set(FINCEPT_YTDLP_ASSET "yt-dlp_macos")
+ set(FINCEPT_YTDLP_SHA256 "e80c47b3ce712acee51d5e3d4eace2d181b44d38f1942c3a32e3c7ff53cd9ed5")
+else()
+ set(FINCEPT_YTDLP_ASSET "yt-dlp_linux")
+ set(FINCEPT_YTDLP_SHA256 "c2b0189f581fe4a2ddd41954f1bcb7d327db04b07ed0dea97e4f1b3e09b5dd8e")
+endif()
set(FINCEPT_YTDLP_TO_BUNDLE "")
-if(FINCEPT_YTDLP_EXE)
+if(FINCEPT_YTDLP_EXE AND EXISTS "${FINCEPT_YTDLP_EXE}")
+ # 1. Explicit override.
set(FINCEPT_YTDLP_TO_BUNDLE "${FINCEPT_YTDLP_EXE}")
-else()
- find_program(FINCEPT_YTDLP_AUTO_EXE NAMES yt-dlp yt-dlp.exe)
- if(FINCEPT_YTDLP_AUTO_EXE)
- set(FINCEPT_YTDLP_TO_BUNDLE "${FINCEPT_YTDLP_AUTO_EXE}")
+ message(STATUS "yt-dlp: using override ${FINCEPT_YTDLP_EXE}")
+elseif(FINCEPT_DOWNLOAD_YTDLP)
+ # 2. Auto-download the pinned, hash-verified release into the build tree.
+ set(FINCEPT_YTDLP_DL_DIR "${CMAKE_BINARY_DIR}/yt-dlp")
+ set(FINCEPT_YTDLP_DL_FILE "${FINCEPT_YTDLP_DL_DIR}/${FINCEPT_YTDLP_ASSET}")
+ set(FINCEPT_YTDLP_URL
+ "https://github.com/yt-dlp/yt-dlp/releases/download/${FINCEPT_YTDLP_VERSION}/${FINCEPT_YTDLP_ASSET}")
+
+ # Re-verify any existing download; a hash mismatch (partial/corrupt/tampered)
+ # forces a fresh fetch.
+ set(_ytdlp_need_download TRUE)
+ if(EXISTS "${FINCEPT_YTDLP_DL_FILE}")
+ file(SHA256 "${FINCEPT_YTDLP_DL_FILE}" _ytdlp_existing_hash)
+ if(_ytdlp_existing_hash STREQUAL "${FINCEPT_YTDLP_SHA256}")
+ set(_ytdlp_need_download FALSE)
+ endif()
+ endif()
+
+ if(_ytdlp_need_download)
+ message(STATUS "yt-dlp: downloading ${FINCEPT_YTDLP_VERSION} (${FINCEPT_YTDLP_ASSET})...")
+ file(DOWNLOAD
+ "${FINCEPT_YTDLP_URL}"
+ "${FINCEPT_YTDLP_DL_FILE}"
+ EXPECTED_HASH "SHA256=${FINCEPT_YTDLP_SHA256}"
+ SHOW_PROGRESS
+ STATUS _ytdlp_dl_status
+ TLS_VERIFY ON)
+ list(GET _ytdlp_dl_status 0 _ytdlp_dl_code)
+ if(NOT _ytdlp_dl_code EQUAL 0)
+ list(GET _ytdlp_dl_status 1 _ytdlp_dl_msg)
+ # Drop the partial file so a retry doesn't see a bad cache.
+ file(REMOVE "${FINCEPT_YTDLP_DL_FILE}")
+ message(WARNING "yt-dlp download failed (${_ytdlp_dl_msg}). Video playback will be unavailable.")
+ endif()
+ endif()
+
+ if(EXISTS "${FINCEPT_YTDLP_DL_FILE}")
+ set(FINCEPT_YTDLP_TO_BUNDLE "${FINCEPT_YTDLP_DL_FILE}")
endif()
endif()
@@ -3176,7 +3234,9 @@ if(FINCEPT_YTDLP_TO_BUNDLE AND EXISTS "${FINCEPT_YTDLP_TO_BUNDLE}")
endif()
else()
set(FINCEPT_YTDLP_MISSING_MSG
- "yt-dlp not found. Set FINCEPT_YTDLP_EXE or install yt-dlp on build machine. "
+ "yt-dlp could not be provisioned. Auto-download is "
+ "${FINCEPT_DOWNLOAD_YTDLP} for version ${FINCEPT_YTDLP_VERSION}; set "
+ "-DFINCEPT_YTDLP_EXE=/path/to/yt-dlp to supply it manually (e.g. air-gapped builds). "
"Bundling is required so end users need no setup."
)
if(FINCEPT_REQUIRE_BUNDLED_YTDLP)
diff --git a/fincept-qt/src/auth/AuthManager.cpp b/fincept-qt/src/auth/AuthManager.cpp
index 894c63904..b4743faf9 100644
--- a/fincept-qt/src/auth/AuthManager.cpp
+++ b/fincept-qt/src/auth/AuthManager.cpp
@@ -67,19 +67,31 @@ static void clear_tokens() {
// ── Session persistence (SQLite via SettingsRepository) ──────────────────────
void AuthManager::save_session() {
- QJsonDocument doc(session_.to_json());
+ // CR-08: persist ONLY non-secret session fields to the unencrypted settings
+ // table. The api_key and session_token are stored exclusively in
+ // SecureStorage (AES-256-GCM) so a stolen fincept.db can't yield credentials.
+ QJsonDocument doc(session_.to_persisted_json());
QString json = QString::fromUtf8(doc.toJson(QJsonDocument::Compact));
auto r = fincept::SettingsRepository::instance().set("fincept_session", json, "auth");
if (r.is_err()) {
LOG_ERROR("Auth", "Failed to save session: " + QString::fromStdString(r.error()));
}
- // Persist api_key to OS-native encrypted storage (DPAPI / Keychain) as the
- // durable credential. SQLite session JSON is the fallback.
+ // Secrets → OS-native encrypted storage (DPAPI / Keychain) only.
if (!session_.api_key.isEmpty()) {
auto sr = fincept::SecureStorage::instance().store("api_key", session_.api_key);
if (sr.is_err())
- LOG_WARN("Auth", "SecureStorage: failed to persist api_key — using SQLite fallback");
+ LOG_ERROR("Auth", "SecureStorage: failed to persist api_key — credential not saved");
+ } else {
+ fincept::SecureStorage::instance().remove("api_key");
+ }
+
+ if (!session_.session_token.isEmpty()) {
+ auto st = fincept::SecureStorage::instance().store("session_token", session_.session_token);
+ if (st.is_err())
+ LOG_ERROR("Auth", "SecureStorage: failed to persist session_token");
+ } else {
+ fincept::SecureStorage::instance().remove("session_token");
}
}
@@ -91,8 +103,14 @@ void AuthManager::load_session() {
session_ = SessionData::from_json(doc.object());
}
- // Try to recover api_key from SecureStorage (DPAPI / Keychain) — this is the
- // most reliable source since it survives SQLite corruption and DB migrations.
+ // CR-08 one-shot migration: existing installs have api_key + session_token
+ // written in clear inside the legacy "fincept_session" blob (and a separate
+ // plaintext "fincept_api_key" row). If the loaded session still carries
+ // secrets, move them into SecureStorage and purge the plaintext copies.
+ migrate_legacy_plaintext_credentials();
+
+ // Recover secrets from SecureStorage (DPAPI / Keychain) — the only durable,
+ // encrypted source. Survives SQLite corruption and DB migrations.
auto secure_key = fincept::SecureStorage::instance().retrieve("api_key");
if (secure_key.is_ok() && !secure_key.value().isEmpty()) {
if (session_.api_key.isEmpty() || session_.api_key != secure_key.value()) {
@@ -101,16 +119,68 @@ void AuthManager::load_session() {
}
}
+ auto secure_token = fincept::SecureStorage::instance().retrieve("session_token");
+ if (secure_token.is_ok() && !secure_token.value().isEmpty()) {
+ session_.session_token = secure_token.value();
+ }
+
// Never trust saved authenticated flag — must be re-validated
session_.authenticated = false;
}
+void AuthManager::migrate_legacy_plaintext_credentials() {
+ auto& settings = fincept::SettingsRepository::instance();
+ auto& secure = fincept::SecureStorage::instance();
+ bool migrated = false;
+
+ // 1. Secrets that came in via the legacy plaintext "fincept_session" blob.
+ if (!session_.api_key.isEmpty()) {
+ secure.store("api_key", session_.api_key);
+ migrated = true;
+ }
+ if (!session_.session_token.isEmpty()) {
+ secure.store("session_token", session_.session_token);
+ migrated = true;
+ }
+
+ // 2. The standalone plaintext "fincept_api_key" row written by older builds.
+ auto legacy_key = settings.get("fincept_api_key");
+ if (legacy_key.is_ok() && !legacy_key.value().isEmpty()) {
+ if (session_.api_key.isEmpty())
+ session_.api_key = legacy_key.value();
+ secure.store("api_key", legacy_key.value());
+ migrated = true;
+ }
+
+ if (migrated) {
+ // Rewrite fincept_session without secrets and drop the plaintext key row
+ // so the cleartext copies no longer exist on disk for this install.
+ QJsonDocument doc(session_.to_persisted_json());
+ settings.set("fincept_session",
+ QString::fromUtf8(doc.toJson(QJsonDocument::Compact)), "auth");
+ settings.remove("fincept_api_key");
+ LOG_INFO("Auth", "Migrated legacy plaintext credentials into SecureStorage and purged settings rows");
+ }
+}
+
+QString AuthManager::fincept_api_key() const {
+ // Single supported resolver. Prefer the live in-memory session; fall back to
+ // the encrypted SecureStorage copy. Never reads the legacy plaintext row.
+ if (!session_.api_key.isEmpty())
+ return session_.api_key;
+ auto secure_key = fincept::SecureStorage::instance().retrieve("api_key");
+ if (secure_key.is_ok())
+ return secure_key.value();
+ return {};
+}
+
void AuthManager::clear_session() {
session_ = SessionData{};
clear_tokens();
fincept::SettingsRepository::instance().remove("fincept_session");
fincept::SettingsRepository::instance().remove("fincept_api_key");
fincept::SecureStorage::instance().remove("api_key");
+ fincept::SecureStorage::instance().remove("session_token");
// PIN intentionally NOT cleared here. The PIN is a local-device credential,
// independent of the backend session. Wiping it on every logout means a
@@ -501,8 +571,11 @@ void AuthManager::auto_configure_fincept_llm() {
if (session_.api_key.isEmpty())
return;
- // Always store API key in settings — LlmService resolves it at runtime
- fincept::SettingsRepository::instance().set("fincept_api_key", session_.api_key, "auth");
+ // CR-08: do NOT persist the api_key in the plaintext settings table. The
+ // key already lives in the in-memory session and in SecureStorage (written
+ // by save_session). LlmService and friends resolve it via
+ // AuthManager::fincept_api_key(). Defensively purge any stale plaintext row.
+ fincept::SettingsRepository::instance().remove("fincept_api_key");
// Only create the fincept provider row if it doesn't already exist.
// This prevents overwriting the user's model/settings choice on every
diff --git a/fincept-qt/src/auth/AuthManager.h b/fincept-qt/src/auth/AuthManager.h
index 55932b3c2..2d633b119 100644
--- a/fincept-qt/src/auth/AuthManager.h
+++ b/fincept-qt/src/auth/AuthManager.h
@@ -18,6 +18,14 @@ class AuthManager : public QObject {
bool is_authenticated() const { return session_.authenticated; }
bool is_loading() const { return is_loading_; }
+ /// Resolve the Fincept api_key for LLM/service callers WITHOUT touching the
+ /// plaintext SQLite settings table. Prefers the live in-memory session;
+ /// falls back to the encrypted SecureStorage copy (which load_session also
+ /// restores into the session at startup). Returns empty if no key is known.
+ /// This is the single supported resolver — callers must NOT read the legacy
+ /// plaintext "fincept_api_key" settings row.
+ QString fincept_api_key() const;
+
// Auth flows
void login(const QString& email, const QString& password, bool force_login = false);
void signup(const QString& username, const QString& email, const QString& password, const QString& phone,
@@ -70,6 +78,9 @@ class AuthManager : public QObject {
void save_session();
void load_session();
void clear_session();
+ // One-shot: move secrets out of the legacy plaintext settings rows into
+ // SecureStorage, then purge the cleartext copies (CR-08). Idempotent.
+ void migrate_legacy_plaintext_credentials();
void validate_saved_session();
void fetch_user_profile(std::function<void()> on_done = {});
void fetch_user_subscription(std::function<void()> on_done = {});
diff --git a/fincept-qt/src/auth/AuthTypes.h b/fincept-qt/src/auth/AuthTypes.h
index c536d1818..d97060acb 100644
--- a/fincept-qt/src/auth/AuthTypes.h
+++ b/fincept-qt/src/auth/AuthTypes.h
@@ -253,6 +253,17 @@ struct SessionData {
return obj;
}
+ // Session JSON with secrets stripped — this is what may be persisted to the
+ // UNENCRYPTED settings table. The api_key and session_token live ONLY in
+ // SecureStorage (AES-256-GCM, machine-bound key). Persisting them in clear
+ // would defeat encryption-at-rest (CR-08).
+ QJsonObject to_persisted_json() const {
+ QJsonObject obj = to_json();
+ obj.remove("api_key");
+ obj.remove("session_token");
+ return obj;
+ }
+
static SessionData from_json(const QJsonObject& obj) {
SessionData s;
s.authenticated = obj["authenticated"].toBool();
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.cpp b/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.cpp
index 1cca9d442..2b99c7201 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.cpp
+++ b/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.cpp
@@ -452,7 +452,8 @@ void CryptoOrderEntry::set_buy_side(bool is_buy) {
buy_tab_->setProperty("active", is_buy);
sell_tab_->setProperty("active", !is_buy);
- submit_btn_->setText(is_buy ? tr("BUY %1").arg(current_symbol_) : tr("SELL %1").arg(current_symbol_));
+ if (!submit_busy_)
+ submit_btn_->setText(is_buy ? tr("BUY %1").arg(current_symbol_) : tr("SELL %1").arg(current_symbol_));
submit_btn_->setObjectName(is_buy ? "cryptoBuySubmit" : "cryptoSellSubmit");
repolish(buy_tab_);
@@ -508,7 +509,8 @@ void CryptoOrderEntry::set_mode(bool is_paper) {
void CryptoOrderEntry::set_symbol(const QString& symbol) {
current_symbol_ = symbol;
- submit_btn_->setText(is_buy_side_ ? tr("BUY %1").arg(symbol) : tr("SELL %1").arg(symbol));
+ if (!submit_busy_)
+ submit_btn_->setText(is_buy_side_ ? tr("BUY %1").arg(symbol) : tr("SELL %1").arg(symbol));
// Update unit suffix labels (base on qty, quote on price/stop) by looking
// up the children we tagged with the ftRoleUnit dynamic property.
@@ -525,7 +527,28 @@ void CryptoOrderEntry::set_symbol(const QString& symbol) {
update_cost_preview();
}
+void CryptoOrderEntry::set_submit_busy(bool busy) {
+ submit_busy_ = busy;
+ if (!submit_btn_)
+ return;
+ submit_btn_->setEnabled(!busy);
+ if (busy) {
+ submit_btn_->setText(tr("SENDING…"));
+ } else {
+ submit_btn_->setText(is_buy_side_ ? tr("BUY %1").arg(current_symbol_)
+ : tr("SELL %1").arg(current_symbol_));
+ }
+}
+
void CryptoOrderEntry::on_submit() {
+ // In-flight guard: a live order POST is dispatched to a worker thread and
+ // the receiver returns immediately, so without this a double-click or a
+ // held Ctrl+Enter would fire a second real exchange order. set_submit_busy
+ // disables the button, but the keyboard-shortcut / scripted path can still
+ // re-enter the slot, so gate here too.
+ if (submit_busy_)
+ return;
+
const QString side = is_buy_side_ ? "buy" : "sell";
static const char* type_map[] = {"market", "limit", "stop", "stop_limit"};
const QString order_type = type_map[active_type_];
@@ -719,8 +742,9 @@ void CryptoOrderEntry::retranslateUi() {
// Submit button + tooltip + subtitle
if (submit_btn_) {
- submit_btn_->setText(is_buy_side_ ? tr("BUY %1").arg(current_symbol_)
- : tr("SELL %1").arg(current_symbol_));
+ if (!submit_busy_)
+ submit_btn_->setText(is_buy_side_ ? tr("BUY %1").arg(current_symbol_)
+ : tr("SELL %1").arg(current_symbol_));
submit_btn_->setToolTip(tr("Submit order (⌘/Ctrl+Enter)"));
}
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.h b/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.h
index 6967ab037..20c11e146 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.h
+++ b/fincept-qt/src/screens/crypto_trading/CryptoOrderEntry.h
@@ -24,6 +24,14 @@ class CryptoOrderEntry : public QWidget {
void set_futures_mode(bool is_futures); // show/hide leverage + margin controls
bool reduce_only() const; // reduce-only flag (perp/futures only)
+ // In-flight guard for live order submission. While an order POST is in
+ // flight the submit button is disabled and relabelled "SENDING…" so a
+ // double-click / held Ctrl+Enter can't fire a second real exchange order.
+ // Re-enabling on the main thread when the async call completes restores the
+ // normal BUY/SELL label.
+ void set_submit_busy(bool busy);
+ bool submit_busy() const { return submit_busy_; }
+
signals:
void order_submitted(const QString& side, const QString& order_type, double quantity, double price,
double stop_price, double sl_price, double tp_price);
@@ -117,6 +125,7 @@ class CryptoOrderEntry : public QWidget {
bool is_paper_ = true;
bool is_buy_side_ = true;
bool is_futures_ = false;
+ bool submit_busy_ = false; // true while a live order POST is in flight
QString current_symbol_ = "BTC/USDT";
};
diff --git a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_Handlers.cpp b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_Handlers.cpp
index 0a8cffddd..98d608d2e 100644
--- a/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_Handlers.cpp
+++ b/fincept-qt/src/screens/crypto_trading/CryptoTradingScreen_Handlers.cpp
@@ -254,23 +254,43 @@ void CryptoTradingScreen::on_order_submitted(const QString& side, const QString&
}
refresh_portfolio();
} else {
+ // In-flight guard: place_exchange_order is dispatched to a worker and
+ // we return to the GUI thread immediately, so the submit button must
+ // be disabled for the lifetime of the POST — otherwise a double-click
+ // or held Ctrl+Enter fires a second real exchange order (CR-07).
+ order_entry_->set_submit_busy(true);
+
// Read the reduce-only flag on the UI thread before dispatching.
const bool reduce_only = order_entry_->reduce_only();
QPointer<CryptoTradingScreen> self = this;
- (void)QtConcurrent::run([self, side, order_type, qty, price, stop_price, sl, tp, reduce_only]() {
- if (!self)
- return;
+ QPointer<crypto::CryptoOrderEntry> oe = order_entry_;
+ (void)QtConcurrent::run([self, oe, side, order_type, qty, price, stop_price, sl, tp, reduce_only]() {
// stop_price drives Stop / Stop-Limit triggers; sl/tp attach native
// bracket legs; reduce_only is honoured on perps. The daemon maps
// these to ccxt unified params (triggerPrice / stopLoss / takeProfit).
- ExchangeService::instance().place_exchange_order(self->selected_symbol_, side, order_type, qty, price,
- stop_price, sl, tp, reduce_only);
+ // Re-enable the button on completion regardless of success/throw so
+ // the user is never stuck on a permanently disabled SENDING… button.
+ try {
+ if (self) {
+ ExchangeService::instance().place_exchange_order(self->selected_symbol_, side, order_type, qty,
+ price, stop_price, sl, tp, reduce_only);
+ }
+ } catch (const std::exception& e) {
+ LOG_ERROR(TAG, QString("Live order failed: %1").arg(e.what()));
+ } catch (...) {
+ LOG_ERROR(TAG, "Live order failed: unknown exception");
+ }
+ // order_entry_ is a child of the screen, so if self is alive the
+ // order-entry widget is too. Posting onto self is sufficient.
+ if (!self)
+ return;
QMetaObject::invokeMethod(
self,
- [self]() {
- if (!self)
- return;
- self->refresh_live_data();
+ [self, oe]() {
+ if (oe)
+ oe->set_submit_busy(false);
+ if (self)
+ self->refresh_live_data();
},
Qt::QueuedConnection);
});
diff --git a/fincept-qt/src/screens/settings/LlmConfigSection_Providers.cpp b/fincept-qt/src/screens/settings/LlmConfigSection_Providers.cpp
index de311dcc5..b2c703cad 100644
--- a/fincept-qt/src/screens/settings/LlmConfigSection_Providers.cpp
+++ b/fincept-qt/src/screens/settings/LlmConfigSection_Providers.cpp
@@ -8,6 +8,7 @@
#include "screens/settings/LlmConfigSection.h"
+#include "auth/AuthManager.h"
#include "core/logging/Logger.h"
#include "services/llm/LlmService.h"
#include "storage/repositories/LlmConfigRepository.h"
@@ -548,9 +549,9 @@ void LlmConfigSection::populate_form(const QString& provider) {
if (is_fincept) {
api_key_edit_->clear();
- auto stored = SettingsRepository::instance().get("fincept_api_key");
- if (stored.is_ok() && !stored.value().isEmpty()) {
- QString masked = stored.value().left(8) + "...";
+ const QString stored = fincept::auth::AuthManager::instance().fincept_api_key();
+ if (!stored.isEmpty()) {
+ QString masked = stored.left(8) + "...";
api_key_edit_->setPlaceholderText(tr("Linked to your Fincept account: %1").arg(masked));
} else {
api_key_edit_->setPlaceholderText(tr("Login to your Fincept account to enable"));
@@ -594,9 +595,9 @@ void LlmConfigSection::populate_form(const QString& provider) {
api_key_edit_->clear();
api_key_edit_->setEnabled(!is_fincept && !is_ollama);
if (is_fincept) {
- auto stored = SettingsRepository::instance().get("fincept_api_key");
- if (stored.is_ok() && !stored.value().isEmpty())
- api_key_edit_->setPlaceholderText(tr("Linked to your Fincept account: %1").arg(stored.value().left(8) + "..."));
+ const QString stored = fincept::auth::AuthManager::instance().fincept_api_key();
+ if (!stored.isEmpty())
+ api_key_edit_->setPlaceholderText(tr("Linked to your Fincept account: %1").arg(stored.left(8) + "..."));
else
api_key_edit_->setPlaceholderText(tr("Login to your Fincept account to enable"));
model_combo_->setVisible(false);
@@ -758,9 +759,9 @@ void LlmConfigSection::on_test_connection() {
}
if (provider == "fincept") {
- // Fincept is a managed service — verify API key exists
- auto stored = SettingsRepository::instance().get("fincept_api_key");
- if (stored.is_ok() && !stored.value().isEmpty())
+ // Fincept is a managed service — verify API key exists (session → SecureStorage)
+ const QString stored = fincept::auth::AuthManager::instance().fincept_api_key();
+ if (!stored.isEmpty())
show_status(tr("Fincept connected — API key active"), false);
else
show_status(tr("Not connected — login to your Fincept account first"), true);
diff --git a/fincept-qt/src/services/llm/LlmModelsApi.cpp b/fincept-qt/src/services/llm/LlmModelsApi.cpp
index 4363bf01d..106705357 100644
--- a/fincept-qt/src/services/llm/LlmModelsApi.cpp
+++ b/fincept-qt/src/services/llm/LlmModelsApi.cpp
@@ -2,6 +2,7 @@
#include "services/llm/LlmService.h"
+#include "auth/AuthManager.h"
#include "core/logging/Logger.h"
#include "storage/repositories/SettingsRepository.h"
@@ -86,13 +87,11 @@ QMap<QString, QString> LlmService::get_models_headers(const QString& provider, c
} else if (p == "ollama") {
// No auth.
} else if (p == "fincept") {
- // Same fallback as ensure_config.
+ // Same fallback as ensure_config — resolve via AuthManager
+ // (session → SecureStorage), never the plaintext settings row (CR-08).
QString resolved_key = api_key;
- if (resolved_key.isEmpty()) {
- auto stored = SettingsRepository::instance().get("fincept_api_key");
- if (stored.is_ok() && !stored.value().isEmpty())
- resolved_key = stored.value();
- }
+ if (resolved_key.isEmpty())
+ resolved_key = fincept::auth::AuthManager::instance().fincept_api_key();
if (!resolved_key.isEmpty())
h["X-API-Key"] = resolved_key;
} else {
diff --git a/fincept-qt/src/services/llm/LlmService.cpp b/fincept-qt/src/services/llm/LlmService.cpp
index 13b2687dc..dc3f0bf88 100644
--- a/fincept-qt/src/services/llm/LlmService.cpp
+++ b/fincept-qt/src/services/llm/LlmService.cpp
@@ -64,14 +64,11 @@ void LlmService::ensure_config() const {
// those re-resolve every call so a login that happens after first ensure_config() doesn't 401 forever.
if (config_loaded_) {
if (provider_ == "fincept") {
- const auto& sess = fincept::auth::AuthManager::instance().session();
- if (!sess.api_key.isEmpty()) {
- api_key_ = sess.api_key;
- } else {
- auto stored = SettingsRepository::instance().get("fincept_api_key");
- if (stored.is_ok() && !stored.value().isEmpty())
- api_key_ = stored.value();
- }
+ // Resolve via AuthManager (session → SecureStorage). Never the
+ // legacy plaintext settings row (CR-08).
+ const QString key = fincept::auth::AuthManager::instance().fincept_api_key();
+ if (!key.isEmpty())
+ api_key_ = key;
}
return;
}
@@ -113,16 +110,12 @@ void LlmService::ensure_config() const {
LOG_INFO(kLlmSvcTag, "No LLM provider configured — using Fincept default");
}
- // Fincept key always comes from the live AuthManager session; SettingsRepository fallback is the legacy path.
+ // Fincept key resolves via AuthManager (live session → encrypted
+ // SecureStorage). The legacy plaintext settings row is no longer read (CR-08).
if (provider_ == "fincept") {
- const auto& sess = fincept::auth::AuthManager::instance().session();
- if (!sess.api_key.isEmpty()) {
- api_key_ = sess.api_key;
- } else {
- auto stored_key = SettingsRepository::instance().get("fincept_api_key");
- if (stored_key.is_ok() && !stored_key.value().isEmpty())
- api_key_ = stored_key.value();
- }
+ const QString key = fincept::auth::AuthManager::instance().fincept_api_key();
+ if (!key.isEmpty())
+ api_key_ = key;
}
auto gs = LlmConfigRepository::instance().get_global_settings();