Skip to content
API Documentation
BastionGuard™
SecureList Class Reference

#include <BastionGuard-secure.hpp>

Static Public Member Functions

static bool open_if_allowed (const std::string &url, int argc, char **argv)
static bool is_payment_domain (const std::string &domain)
static bool is_builtin_payment_provider (const std::string &domain)
static std::string extract_domain (const std::string &url)
static std::string clean_domain (const std::string &d)
static bool ends_with (const std::string &s, const std::string &suffix)

Static Private Member Functions

static std::string config_path_payments ()
static void open_system_browser (const std::string &url)
static const std::vector< std::string > & payments_cache_only ()

Detailed Description

Definition at line 26 of file BastionGuard-secure.hpp.

Member Function Documentation

◆ clean_domain()

std::string SecureList::clean_domain ( const std::string & d)
static

Definition at line 110 of file BastionGuard-secure.cpp.

110 {
111 std::string s = d;
112
113 // trim minimo
114 while (!s.empty() && std::isspace(static_cast<unsigned char>(s.front())))
115 s.erase(s.begin());
116 while (!s.empty() && std::isspace(static_cast<unsigned char>(s.back())))
117 s.pop_back();
118
119 s = to_lower(s);
120
121 if (!s.empty() && s[0] == '.')
122 s.erase(0, 1);
123
124 if (s.rfind("www.", 0) == 0)
125 s.erase(0, 4);
126
127 // rimuovi porta
128 auto p = s.find(':');
129 if (p != std::string::npos)
130 s.erase(p);
131
132 return s;
133}
static std::string to_lower(std::string s)

References to_lower().

Referenced by extract_domain(), is_builtin_payment_provider(), is_payment_domain(), and load_payments_list_only().

◆ config_path_payments()

std::string SecureList::config_path_payments ( )
staticprivate

Definition at line 50 of file BastionGuard-secure.cpp.

50 {
51 const auto base = Glib::get_user_config_dir();
52 return base + "/BastionGuard/payments.json";
53}

Referenced by payments_cache_only().

◆ ends_with()

bool SecureList::ends_with ( const std::string & s,
const std::string & suffix )
static

Definition at line 146 of file BastionGuard-secure.cpp.

146 {
147 if (suffix.size() > s.size()) return false;
148 return std::equal(
149 suffix.rbegin(), suffix.rend(),
150 s.rbegin(),
151 [](char a, char b) {
152 return std::tolower(static_cast<unsigned char>(a)) ==
153 std::tolower(static_cast<unsigned char>(b));
154 }
155 );
156}

Referenced by is_builtin_payment_provider(), and matches_payment_domain().

◆ extract_domain()

std::string SecureList::extract_domain ( const std::string & url)
static

Definition at line 135 of file BastionGuard-secure.cpp.

135 {
136 std::regex re(R"(^(?:[a-zA-Z][a-zA-Z0-9+\-.]*:\/\/)?(?:[^\/@]+@)?([^\/:?#]+))",
137 std::regex::icase);
138
139 std::smatch match;
140 if (std::regex_search(url, match, re) && match.size() >= 2) {
141 return clean_domain(match[1].str());
142 }
143 return "";
144}
static std::string clean_domain(const std::string &d)

References clean_domain().

Referenced by open_if_allowed().

◆ is_builtin_payment_provider()

bool SecureList::is_builtin_payment_provider ( const std::string & domain)
static

Definition at line 246 of file BastionGuard-secure.cpp.

246 {
247 // Domini "navigabili" dei principali provider di pagamento: pagine dove
248 // l'utente effettua davvero login/checkout/inserimento carta. Devono
249 // SEMPRE aprirsi nella sandbox CEF, anche se l'utente non li ha messi in
250 // payments.json.
251 //
252 // ATTENZIONE: qui NON vanno gli endpoint tecnici (js.stripe.com,
253 // api.stripe.com, hooks.*, cdn.*, api.paypal.com, ...). Quelli sono
254 // iframe/API caricati DENTRO la pagina di un merchant e restano nelle
255 // esclusioni del proxy: intercettarli romperebbe il checkout. Qui solo
256 // i domini che l'utente naviga direttamente.
257 static const std::vector<std::string> providers = {
258 "stripe.com", // checkout.stripe.com, dashboard.stripe.com, billing.stripe.com
259 "paypal.com", // www.paypal.com, checkout.paypal.com
260 "paypalobjects.com",
261 "adyen.com", // ca-live/checkout pages (NB: checkoutshopper-* resta escluso)
262 "checkout.com",
263 "klarna.com",
264 "worldpay.com",
265 "braintreegateway.com",
266 "nexi.it",
267 "nexigroup.com",
268 "sisalpay.it",
269 "satispay.com",
270 "sumup.com",
271 "square.com",
272 "squareup.com",
273 "mollie.com",
274 "gocardless.com",
275 "wise.com",
276 "revolut.com",
277 "skrill.com",
278 "neteller.com",
279 "paysafecard.com",
280 "amazonpay.com",
281 "wallet.google.com",
282 "pay.google.com",
283 };
284
285 const std::string dnorm = clean_domain(domain);
286 for (const auto& d : providers) {
287 if (dnorm == d) return true;
288 if (ends_with(dnorm, "." + d)) return true;
289 }
290 return false;
291}
static bool ends_with(const std::string &s, const std::string &suffix)

References clean_domain(), and ends_with().

Referenced by open_if_allowed().

◆ is_payment_domain()

bool SecureList::is_payment_domain ( const std::string & domain)
static

Definition at line 230 of file BastionGuard-secure.cpp.

230 {
231 // Se vuoi che sia sempre attivo a prescindere dalle impostazioni,
232 // rimuovi questo controllo.
234 return false;
235
236 const auto& list = payments_cache_only();
237 if (list.empty()) {
238 std::cerr << _("[BastionGuard-secure] ⚠ Nessun dominio presente in payments.json.\n");
239 return false;
240 }
241
242 const std::string dnorm = clean_domain(domain);
243 return matches_payment_domain(dnorm, list);
244}
#define _(s)
static bool matches_payment_domain(const std::string &host_norm, const std::vector< std::string > &list_norm)
static const std::vector< std::string > & payments_cache_only()
static bool get_secure_payments_enabled()

References _, clean_domain(), SettingsStore::get_secure_payments_enabled(), matches_payment_domain(), and payments_cache_only().

Referenced by open_if_allowed().

◆ open_if_allowed()

bool SecureList::open_if_allowed ( const std::string & url,
int argc,
char ** argv )
static

Definition at line 293 of file BastionGuard-secure.cpp.

293 {
294 if (url.empty()) {
295 std::cerr << _("[BastionGuard-secure] ⚠ URL vuoto.\n");
296 return false;
297 }
298
299 const std::string domain = extract_domain(url);
300 if (domain.empty()) {
301 std::cerr << _("[BastionGuard-secure] ❌ Impossibile estrarre dominio da: ") << url << "\n";
303 return false;
304 }
305
306 if (is_payment_domain(domain) || is_builtin_payment_provider(domain)) {
307 std::cout << _("[BastionGuard-secure] 🟢 Dominio consentito (payments.json / provider noto): ") << domain << "\n";
308 std::cout << _("[BastionGuard-secure] 🔐 Avvio SecureBrowser (CEF)...\n");
309 SecureBrowser::open(url, argc, argv);
310 return true;
311 }
312
313 std::cout << _("[BastionGuard-secure] 🔴 Dominio NON presente in payments.json: ") << domain << "\n";
314 std::cout << _("[BastionGuard-secure] → Apertura nel browser di sistema.\n");
316 return false;
317}
static bool open(const std::string &url, int argc, char **argv)
static void open_system_browser(const std::string &url)
static std::string extract_domain(const std::string &url)
static bool is_payment_domain(const std::string &domain)
static bool is_builtin_payment_provider(const std::string &domain)

References _, extract_domain(), is_builtin_payment_provider(), is_payment_domain(), SecureBrowser::open(), and open_system_browser().

Referenced by main().

◆ open_system_browser()

void SecureList::open_system_browser ( const std::string & url)
staticprivate

Definition at line 55 of file BastionGuard-secure.cpp.

55 {
56 // ANTI-LOOP CRITICO.
57 // Questo fallback apre l'URL nel browser di SISTEMA. Ma il browser di
58 // sistema è configurato per usare il proxy MITM di BastionGuard, quindi
59 // la richiesta verso un dominio bank/secure torna al proxy, che la
60 // re-intercetta e rilancia di nuovo BastionGuard-secure → che richiama
61 // open_system_browser → xdg-open → ... loop infinito = migliaia di
62 // finestre/processi.
63 //
64 // Due protezioni:
65 // 1) BG_OPENER_DEPTH: se siamo già stati invocati dalla catena opener,
66 // NON riapriamo il browser di sistema (interrompe la ricorsione).
67 // 2) no_proxy="*"/NO_PROXY="*" nell'ambiente del comando lanciato: il
68 // browser di sistema NON deve instradare QUESTA apertura attraverso
69 // il proxy di BastionGuard, così non viene re-intercettata.
70 if (std::getenv("BG_OPENER_DEPTH")) {
71 std::cerr << _("[BastionGuard-secure] ⛔ Anti-loop: apertura browser di "
72 "sistema già in corso, non rilancio (") << url << ")\n";
73 return;
74 }
75
76 const char* wayland = std::getenv("WAYLAND_DISPLAY");
77 const pid_t pid = ::fork();
78 if (pid < 0) {
79 std::cerr << _("[BastionGuard-secure] ❌ Impossibile avviare il browser di sistema.\n");
80 return;
81 }
82
83 if (pid == 0) {
84 // Neutralizza il proxy soltanto nel processo figlio e passa l'URL come
85 // singolo argv: nessuna interpretazione di metacaratteri da una shell.
86 ::setenv("BG_OPENER_DEPTH", "1", 1);
87 ::setenv("no_proxy", "*", 1);
88 ::setenv("NO_PROXY", "*", 1);
89 static const char* proxy_vars[] = {
90 "http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY", "all_proxy", "ALL_PROXY"
91 };
92 for (const char* name : proxy_vars)
93 ::unsetenv(name);
94
95 if (wayland && *wayland) {
96 const char* gio_argv[] = {"gio", "open", url.c_str(), nullptr};
97 ::execvp("gio", const_cast<char* const*>(gio_argv));
98 }
99
100 const char* xdg_argv[] = {"xdg-open", url.c_str(), nullptr};
101 ::execvp("xdg-open", const_cast<char* const*>(xdg_argv));
102 _exit(127);
103 }
104
105 int status = 0;
106 if (::waitpid(pid, &status, 0) < 0)
107 std::cerr << _("[BastionGuard-secure] ⚠️ waitpid fallita per browser di sistema.\n");
108}

References _.

Referenced by open_if_allowed().

◆ payments_cache_only()

const std::vector< std::string > & SecureList::payments_cache_only ( )
staticprivate

Definition at line 206 of file BastionGuard-secure.cpp.

206 {
207 static bool init = false;
208 static std::vector<std::string> cached;
209
210 if (!init) {
211 const std::string path_user = config_path_payments();
212 load_payments_list_only(path_user, cached);
213 init = true;
214 }
215
216 return cached;
217}
static void load_payments_list_only(const std::string &path, std::vector< std::string > &out)
static std::string config_path_payments()

References config_path_payments(), and load_payments_list_only().

Referenced by is_payment_domain().


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