Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions SECURITY_FIXES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Security Fixes

A security review of the Caesium Image Compressor codebase identified two high-severity vulnerabilities: an API endpoint hijacking risk that could leak bearer tokens to attacker-controlled servers, and OS command injection via `system()` calls for shutdown/sleep operations. Both have been fixed with minimal, targeted changes.

| File Path | Vulnerability Type | CWE | Severity | What Was Changed |
|---|---|---|---|---|
| `src/network/NetworkOperations.cpp` | Improper Input Validation / Credential Theft via Endpoint Hijacking | CWE-346 (Origin Validation Error) | High | Custom API endpoint is now trimmed and validated: must be a well-formed HTTPS URL. Rejects non-HTTPS or malformed URLs and falls back to the hardcoded default. Prevents a local attacker from redirecting API traffic (including auth tokens) to an arbitrary server. |
| `src/utils/PostCompressionActions.cpp` | OS Command Injection via `system()` | CWE-78 (OS Command Injection) | High | Replaced all `system()` calls with `QProcess::startDetached()` using explicit argument lists. `QProcess` does not invoke a shell, eliminating shell interpretation, PATH manipulation, and environment variable injection risks. |

Additional lower-severity findings were identified during this review and can be provided in follow-up PRs if desired.
10 changes: 9 additions & 1 deletion src/network/NetworkOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QObject>
#include <QSettings>
#include <QStandardPaths>
#include <QUrl>

NetworkOperations::NetworkOperations()
{
Expand All @@ -25,7 +26,14 @@ QString NetworkOperations::getBaseEndpoint()
{
QFile endpointFile(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/api_endpoint");
if (endpointFile.exists() && endpointFile.open(QFile::ReadOnly)) {
return endpointFile.readLine();
QString endpoint = endpointFile.readLine().trimmed();
QUrl url(endpoint);
if (!url.isValid() || url.scheme() != "https") {
qWarning() << "Custom API endpoint rejected: must be a valid HTTPS URL. Using default.";
return "https://caesium.app/api/v1";
}
qInfo() << "Using custom API endpoint:" << url.host();
return endpoint;
}
return "https://caesium.app/api/v1";
}
Expand Down
11 changes: 6 additions & 5 deletions src/utils/PostCompressionActions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "PostCompressionActions.h"
#include <QProcess>

void PostCompressionActions::runAction(PostCompressionAction action)
{
Expand Down Expand Up @@ -38,26 +39,26 @@ void PostCompressionActions::closeApplication()
void PostCompressionActions::shutdownMachine()
{
#ifdef Q_OS_WIN
system("shutdown /s");
QProcess::startDetached("shutdown", QStringList() << "/s");
#endif

#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
system("shutdown -h now");
QProcess::startDetached("shutdown", QStringList() << "-h" << "now");
#endif
}

void PostCompressionActions::putMachineToSleep()
{
#ifdef Q_OS_WIN
system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0");
QProcess::startDetached("rundll32.exe", QStringList() << "powrprof.dll,SetSuspendState" << "0,1,0");
#endif

#ifdef Q_OS_MAC
system("pmset sleepnow");
QProcess::startDetached("pmset", QStringList() << "sleepnow");
#endif

#ifdef Q_OS_LINUX
system("systemctl suspend");
QProcess::startDetached("systemctl", QStringList() << "suspend");
#endif
}

Expand Down
Loading