Skip to content

Commit 85bf70a

Browse files
authored
Merge pull request #856 from XMOJ-Script-dev/boomzero/cookieFix
修复由于 PHPSESSID 启用了 httpOnly 导致的后台不可用
2 parents 8b2bf37 + 71cb540 commit 85bf70a

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Update.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,17 @@
30583058
}
30593059
],
30603060
"Notes": "随着 CI 更新, 相信以后的 release 都会有 release notes("
3061+
},
3062+
"2.3.1": {
3063+
"UpdateDate": 1758944205783,
3064+
"Prerelease": true,
3065+
"UpdateContents": [
3066+
{
3067+
"PR": 856,
3068+
"Description": "修复由于 PHPSESSID 启用了 httpOnly 导致的后台不可用"
3069+
}
3070+
],
3071+
"Notes": "本版本修复了由于 PHPSESSID 启用了 httpOnly 导致的后台不可用"
30613072
}
30623073
}
30633074
}

XMOJ.user.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name XMOJ
3-
// @version 2.3.0
3+
// @version 2.3.1
44
// @description XMOJ增强脚本
55
// @author @XMOJ-Script-dev, @langningchen and the community
66
// @namespace https://github/langningchen
@@ -20,6 +20,7 @@
2020
// @grant unsafeWindow
2121
// @grant GM_setValue
2222
// @grant GM_getValue
23+
// @grant GM_cookie
2324
// @homepage https://www.xmoj-bbs.me/
2425
// @supportURL https://support.xmoj-bbs.me/form/8050213e-c806-4680-b414-0d1c48263677
2526
// @connect api.xmoj-bbs.tech
@@ -479,6 +480,20 @@ let RequestAPI = (Action, Data, CallBack) => {
479480
Session = Temp[i].split("=")[1];
480481
}
481482
}
483+
if (Session === "") { //The cookie is httpOnly
484+
GM.cookie.set({
485+
name: 'PHPSESSID',
486+
value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28),
487+
path: "/"
488+
})
489+
.then(() => {
490+
console.log('Reset PHPSESSID successfully.');
491+
location.reload(); //Refresh the page to auth with the new PHPSESSID
492+
})
493+
.catch((error) => {
494+
console.error(error);
495+
});
496+
}
482497
let PostData = {
483498
"Authentication": {
484499
"SessionID": Session, "Username": CurrentUsername,
@@ -1010,7 +1025,17 @@ async function main() {
10101025
});
10111026
PopupUL.children[5].addEventListener("click", () => {
10121027
clearCredential();
1013-
document.cookie = "PHPSESSID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/"; //This is how you remove a cookie?
1028+
GM.cookie.set({
1029+
name: 'PHPSESSID',
1030+
value: (Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)).substring(0, 28),
1031+
path: "/"
1032+
})
1033+
.then(() => {
1034+
console.log('Reset PHPSESSID successfully.');
1035+
})
1036+
.catch((error) => {
1037+
console.error(error);
1038+
}); //We can no longer rely of the server to set the cookie for us
10141039
location.href = "https://www.xmoj.tech/logout.php";
10151040
});
10161041
Array.from(PopupUL.children).forEach(item => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xmoj-script",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"description": "an improvement script for xmoj.tech",
55
"main": "AddonScript.js",
66
"scripts": {

0 commit comments

Comments
 (0)