Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix security bugs #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"extra": {
"display-name": "Discord Notifications",
"soft-require": {
"phpbb/phpbb": ">=3.1.4,<3.2.0@dev"
"phpbb/phpbb": ">=3.1.4"
}
},
"require-dev": {
Expand Down
26 changes: 14 additions & 12 deletions notification_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function is_notification_forum_enabled($forum_id)
}

// Query the forum table where forum notification settings are stored
$sql = "SELECT discord_notifications_enabled FROM " . FORUMS_TABLE . " WHERE forum_id = $forum_id";
$sql = "SELECT discord_notifications_enabled FROM " . FORUMS_TABLE . " WHERE forum_id = " . (int)$forum_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$enabled = $data['discord_notifications_enabled'] == 1 ? true : false;
Expand Down Expand Up @@ -107,7 +107,7 @@ public function query_forum_name($forum_id)
return null;
}

$sql = "SELECT forum_name from " . FORUMS_TABLE . " WHERE forum_id = $forum_id";
$sql = "SELECT forum_name from " . FORUMS_TABLE . " WHERE forum_id = " . (int)$forum_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$name = $data['forum_name'];
Expand All @@ -127,7 +127,7 @@ public function query_post_subject($post_id)
return null;
}

$sql = "SELECT post_subject from " . POSTS_TABLE . " WHERE post_id = $post_id";
$sql = "SELECT post_subject from " . POSTS_TABLE . " WHERE post_id = " (int)$post_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$subject = $data['post_subject'];
Expand All @@ -147,7 +147,7 @@ public function query_topic_title($topic_id)
return null;
}

$sql = "SELECT topic_title from " . TOPICS_TABLE . " WHERE topic_id = $topic_id";
$sql = "SELECT topic_title from " . TOPICS_TABLE . " WHERE topic_id = " (int)$topic_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$title = $data['topic_title'];
Expand Down Expand Up @@ -176,7 +176,7 @@ public function query_topic_details($topic_id)
FROM
$forum_table f, $topic_table t
WHERE
t.forum_id = f.forum_id and t.topic_id = $topic_id";
t.forum_id = f.forum_id and t.topic_id = ". (int)$topic_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
Expand All @@ -196,7 +196,7 @@ public function query_user_name($user_id)
return null;
}

$sql = "SELECT username from " . USERS_TABLE . " WHERE user_id = $user_id";
$sql = "SELECT username from " . USERS_TABLE . " WHERE user_id = " . (int)$user_id;
$result = $this->db->sql_query($sql);
$data = $this->db->sql_fetchrow($result);
$name = $data['username'];
Expand Down Expand Up @@ -311,20 +311,22 @@ private function execute_discord_webhook($discord_webhook_url, $color, $message,
}

// Place the message inside the JSON structure that Discord expects to receive at the REST endpoint.
$post = '';
$json = array("embeds"=>array(
"color"=>$color,
"description"=>$message
)
);

if (isset($footer))
{
$post = sprintf('{"embeds": [{"color": "%d", "description" : "%s", "footer": {"text": "%s"}}]}', $color, $message, $footer);
}
else {
$post = sprintf('{"embeds": [{"color": "%d", "description" : "%s"}]}', $color, $message);
$json["embeds"]["footer"] = array("text"=>$footer);
}

// Use the CURL library to transmit the message via a POST operation to the webhook URL.
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $discord_webhook_url);
curl_setopt($h, CURLOPT_POST, 1);
curl_setopt($h, CURLOPT_POSTFIELDS, $post);
curl_setopt($h, CURLOPT_POSTFIELDS, json_encode($json));
$response = curl_exec($h);
curl_close($h);

Expand Down