Skip to content

Commit ad03014

Browse files
committed
Security: Social: Add sec_token when accepting a friend request
Fix GHSA-33gm-vrgh-m239
1 parent 0c4dae4 commit ad03014

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

main/inc/ajax/social.ajax.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,26 @@
2020
echo '';
2121
break;
2222
}
23-
$relation_type = USER_RELATION_TYPE_UNKNOWN; //Unknown contact
24-
if (isset($_GET['is_my_friend'])) {
25-
$relation_type = USER_RELATION_TYPE_FRIEND; //My friend
26-
}
27-
28-
if (isset($_GET['friend_id'])) {
29-
$my_current_friend = $_GET['friend_id'];
30-
UserManager::relate_users($current_user_id, $my_current_friend, $relation_type);
31-
UserManager::relate_users($my_current_friend, $current_user_id, $relation_type);
32-
SocialManager::invitation_accepted($my_current_friend, $current_user_id);
33-
Display::addFlash(
34-
Display::return_message(get_lang('AddedContactToList'), 'success')
35-
);
3623

37-
header('Location: '.api_get_path(WEB_CODE_PATH).'social/invitations.php');
38-
exit;
24+
if (Security::check_token('get', null, 'invitation')) {
25+
$relation_type = USER_RELATION_TYPE_UNKNOWN; //Unknown contact
26+
if (isset($_GET['is_my_friend'])) {
27+
$relation_type = USER_RELATION_TYPE_FRIEND; //My friend
28+
}
29+
30+
if (isset($_GET['friend_id'])) {
31+
$my_current_friend = $_GET['friend_id'];
32+
UserManager::relate_users($current_user_id, $my_current_friend, $relation_type);
33+
UserManager::relate_users($my_current_friend, $current_user_id, $relation_type);
34+
SocialManager::invitation_accepted($my_current_friend, $current_user_id);
35+
Display::addFlash(
36+
Display::return_message(get_lang('AddedContactToList'), 'success')
37+
);
38+
}
3939
}
40-
break;
40+
41+
header('Location: '.api_get_path(WEB_CODE_PATH).'social/invitations.php');
42+
exit;
4143
case 'deny_friend':
4244
if (api_is_anonymous()) {
4345
echo '';

main/social/invitations.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
'a' => 'add_friend',
136136
'friend_id' => $sender_user_id,
137137
'is_my_friend' => 'friend',
138+
'invitation_sec_token' => Security::get_existing_token('invitation'),
138139
]),
139140
'check',
140141
'primary',
@@ -145,7 +146,7 @@
145146
api_get_path(WEB_AJAX_PATH).'social.ajax.php?'.http_build_query([
146147
'a' => 'deny_friend',
147148
'denied_friend_id' => $sender_user_id,
148-
'invitation_sec_token' => Security::get_token('invitation'),
149+
'invitation_sec_token' => Security::get_existing_token('invitation'),
149150
]),
150151
'times',
151152
'danger',

main/social/profile.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
'a' => 'add_friend',
205205
'friend_id' => $user_invitation_id,
206206
'is_my_friend' => 'friend',
207+
'invitation_sec_token' => Security::get_token('invitation'),
207208
]),
208209
'plus',
209210
'default',

tests/behat/features/bootstrap/FeatureContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function iHaveAFriend($friendUsername, $friendId)
159159
'a' => 'add_friend',
160160
'friend_id' => $adminId,
161161
'is_my_friend' => 'friend',
162+
'invitation_sec_token' => Security::get_token('invitation'),
162163
]
163164
);
164165

0 commit comments

Comments
 (0)