|
|
|
@@ -115,6 +115,9 @@ static const std::unordered_map<std::string, AuditEventCategory> audit_event_cat
|
|
|
|
|
{"subprocess.Popen", AuditEventCategory::ProcessCreate},
|
|
|
|
|
{"_winapi.CreateProcess", AuditEventCategory::ProcessCreate},
|
|
|
|
|
{"_posixsubprocess.fork_exec", AuditEventCategory::ProcessCreate},
|
|
|
|
|
|
|
|
|
|
// threading
|
|
|
|
|
{"_thread.start_new_thread", AuditEventCategory::Threading},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Returns the category event_name belongs to, or AuditEventCategory::None when it isn't audited.
|
|
|
|
@@ -735,6 +738,12 @@ std::vector<std::string> audit_targets(const std::string& event_name, AuditEvent
|
|
|
|
|
}
|
|
|
|
|
return targets;
|
|
|
|
|
}
|
|
|
|
|
case AuditEventCategory::Threading:
|
|
|
|
|
// Thread creation exposes no user-supplied target. Use a fixed sentinel so the grant
|
|
|
|
|
// persists per plugin: the permission list matches targets by exact string, and the
|
|
|
|
|
// started function's repr embeds an address that changes every run.
|
|
|
|
|
targets.emplace_back("thread");
|
|
|
|
|
return targets;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@@ -761,6 +770,7 @@ std::vector<std::string>* permission_list_for(AuditEventCategory category, Plugi
|
|
|
|
|
case AuditEventCategory::Http: return &permissions.network_http;
|
|
|
|
|
case AuditEventCategory::Socket: return &permissions.network_socket;
|
|
|
|
|
case AuditEventCategory::ProcessCreate: return &permissions.process;
|
|
|
|
|
case AuditEventCategory::Threading: return &permissions.threading;
|
|
|
|
|
default: return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -832,11 +842,74 @@ wxString audit_message(AuditEventCategory category, const wxString& plugin_name,
|
|
|
|
|
return wxString::Format(_L("Plugin \"%s\" is requesting to open a network connection to:\n%s"), plugin_name, target_list);
|
|
|
|
|
case AuditEventCategory::ProcessCreate:
|
|
|
|
|
return wxString::Format(_L("Plugin \"%s\" is requesting to run the following command(s):\n%s"), plugin_name, target_list);
|
|
|
|
|
case AuditEventCategory::Threading:
|
|
|
|
|
return wxString::Format(_L("Plugin \"%s\" is requesting permission to create a thread."), plugin_name);
|
|
|
|
|
default:
|
|
|
|
|
return wxString::Format(_L("Plugin \"%s\" is requesting permission for the Python audit event \"%s\"."), plugin_name, event_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Builds and shows the modal permission prompt. Must run on the GUI thread.
|
|
|
|
|
bool prompt_for_targets(AuditEventCategory category, const std::string& plugin_name, const std::string& event_name,
|
|
|
|
|
const std::vector<std::string>& unresolved)
|
|
|
|
|
{
|
|
|
|
|
wxString target_list;
|
|
|
|
|
for (const auto& target : unresolved)
|
|
|
|
|
target_list += wxString::FromUTF8(target.c_str()) + "\n";
|
|
|
|
|
|
|
|
|
|
wxMessageDialog dialog(nullptr,
|
|
|
|
|
audit_message(category, wxString::FromUTF8(plugin_name.c_str()),
|
|
|
|
|
wxString::FromUTF8(event_name.c_str()), target_list),
|
|
|
|
|
_L("Plugin permission request"), wxYES_NO | wxICON_WARNING);
|
|
|
|
|
return dialog.ShowModal() == wxID_YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Records a grant in the plugin's sidecar so it is not asked again. Reads the install state
|
|
|
|
|
// freshly because the async prompt outlives the caller's stack copy of it.
|
|
|
|
|
void persist_grant(const std::string& plugin_key, AuditEventCategory category, const std::vector<std::string>& targets)
|
|
|
|
|
{
|
|
|
|
|
PluginInstallState state;
|
|
|
|
|
if (!PluginManager::instance().get_install_state(plugin_key, state))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::vector<std::string>* permission_list = permission_list_for(category, state.permissions);
|
|
|
|
|
if (!permission_list)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto& target : targets)
|
|
|
|
|
persist_permission(plugin_key, state, *permission_list, target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Requests permission for an audited event, returning true when it is already granted or the user
|
|
|
|
|
// approves an inline prompt.
|
|
|
|
|
//
|
|
|
|
|
// An audited event can fire on a thread the UI thread may itself be blocked waiting on: the
|
|
|
|
|
// SlicingPipeline hook runs on the slicing worker thread (see PluginHooks.cpp), and
|
|
|
|
|
// BackgroundSlicingProcess::stop()/stop_internal() park the UI thread until that worker stops.
|
|
|
|
|
// Blocking the worker on a marshaled modal -- which is safe for the plugin-load worker that
|
|
|
|
|
// request_filesystem_read_permissions runs on -- would therefore deadlock the application (the
|
|
|
|
|
// invariant PluginHostUi.cpp documents for slicing-hook UI calls). Off the main thread the prompt
|
|
|
|
|
// is therefore posted asynchronously and the current event denied (fail closed, like an unanswered
|
|
|
|
|
// prompt); the grant is persisted once the user accepts, so a later attempt succeeds without
|
|
|
|
|
// re-prompting.
|
|
|
|
|
bool request_permission(AuditEventCategory category, const std::string& plugin_key, const std::string& plugin_name,
|
|
|
|
|
const std::string& event_name, const std::vector<std::string>& unresolved)
|
|
|
|
|
{
|
|
|
|
|
if (wxTheApp == nullptr || GUI::wxGetApp().is_closing())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (wxIsMainThread())
|
|
|
|
|
return prompt_for_targets(category, plugin_name, event_name, unresolved);
|
|
|
|
|
|
|
|
|
|
GUI::wxGetApp().CallAfter([category, plugin_key, plugin_name, event_name, unresolved]() {
|
|
|
|
|
if (wxTheApp == nullptr || GUI::wxGetApp().is_closing())
|
|
|
|
|
return;
|
|
|
|
|
if (prompt_for_targets(category, plugin_name, event_name, unresolved))
|
|
|
|
|
persist_grant(plugin_key, category, unresolved);
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int decide_audited_event(PluginAuditManager& mgr,
|
|
|
|
|
PluginInstallState& state,
|
|
|
|
|
const std::string& plugin_key,
|
|
|
|
@@ -857,15 +930,7 @@ int decide_audited_event(PluginAuditManager& mgr,
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxString target_list;
|
|
|
|
|
for (const auto& target : unresolved)
|
|
|
|
|
target_list += wxString::FromUTF8(target.c_str()) + "\n";
|
|
|
|
|
|
|
|
|
|
wxMessageDialog dialog(nullptr,
|
|
|
|
|
audit_message(category, wxString::FromUTF8(plugin_name.c_str()),
|
|
|
|
|
wxString::FromUTF8(event_name.c_str()), target_list),
|
|
|
|
|
_L("Plugin permission request"), wxYES_NO | wxICON_WARNING);
|
|
|
|
|
if (dialog.ShowModal() != wxID_YES)
|
|
|
|
|
if (!request_permission(category, plugin_key, plugin_name, event_name, unresolved))
|
|
|
|
|
return report_denied(mgr, event_name, {false, "audit permission required"});
|
|
|
|
|
|
|
|
|
|
if (permission_list)
|
|
|
|
|