Skip to content
Merged
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 Source/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ export class Process {
continue;
}
let processedContent: string = ReplyItem["content"];
processedContent = processedContent.replace(/xmoj-bbs\.tech/g, "xmoj-bbs.me");
processedContent = processedContent.replace(/xmoj-bbs\.(?:tech|me)/g, "xmoj-script.uk");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The unbounded, case-sensitive replacement rewrites any text containing xmoj-bbs.tech or xmoj-bbs.me, including unrelated hostnames such as xmoj-bbs.me.example.com and uppercase forms of the domain, producing incorrect or still-invalid links.

Triggers: When a reply contains a hostname that merely contains a legacy domain string or uses uppercase characters.

Suggested fix: Match the domain as a case-insensitive hostname with URL boundary checks, so only the exact legacy host and its subdomains are rewritten.

Suggested change
processedContent = processedContent.replace(/xmoj-bbs\.(?:tech|me)/g, "xmoj-script.uk");
processedContent = processedContent.replace(/(^|[^\w-])xmoj-bbs\.(?:tech|me)(?![\w.-])/gi, "$1xmoj-script.uk");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add a boundary after the legacy TLD

Because the new me alternative has no trailing domain boundary, reading a post now corrupts any content whose hostname merely starts with that text. For example, https://xmoj-bbs.media/post becomes https://xmoj-script.ukdia/post, and https://xmoj-bbs.me.evil.test/ is rewritten despite not being on the legacy domain. Restrict the match to a complete hostname suffix before replacing it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The rewrite regex /xmoj-bbs.(?:tech|me)/g has no trailing word boundary, so it matches the prefix of any token that merely begins with the legacy host text. 'xmoj-bbs.member' becomes 'xmoj-script.ukmber' and 'xmoj-bbs.meeting' becomes 'xmoj-script.uketing'. Add \b after the TLD alternation so only the full hostname is rewritten; subdomain preservation (www./assets.) is unaffected because the boundary sits after the replaced TLD.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Source/Process.ts, line 885:

<comment>The rewrite regex /xmoj-bbs\.(?:tech|me)/g has no trailing word boundary, so it matches the prefix of any token that merely begins with the legacy host text. 'xmoj-bbs.member' becomes 'xmoj-script.ukmber' and 'xmoj-bbs.meeting' becomes 'xmoj-script.uketing'. Add \b after the TLD alternation so only the full hostname is rewritten; subdomain preservation (www./assets.) is unaffected because the boundary sits after the replaced TLD.</comment>

<file context>
@@ -882,7 +882,7 @@ export class Process {
         }
         let processedContent: string = ReplyItem["content"];
-        processedContent = processedContent.replace(/xmoj-bbs\.tech/g, "xmoj-bbs.me");
+        processedContent = processedContent.replace(/xmoj-bbs\.(?:tech|me)/g, "xmoj-script.uk");
         ResponseData.Reply.push({
           ReplyID: ReplyItem["reply_id"],
</file context>
Suggested change
processedContent = processedContent.replace(/xmoj-bbs\.(?:tech|me)/g, "xmoj-script.uk");
processedContent = processedContent.replace(/xmoj-bbs\.(?:tech|me)\b/g, "xmoj-script.uk");

ResponseData.Reply.push({
ReplyID: ReplyItem["reply_id"],
UserID: ReplyItem["reply_user_id"],
Expand Down
15 changes: 12 additions & 3 deletions test/process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,15 +937,24 @@ test('GetPost reports a locked discussion', async () => {
assert.deepStrictEqual(result.Data.Lock, { Locked: true, LockPerson: 'admin', LockTime: 999 });
});

test('GetPost rewrites legacy domain in reply content', async () => {
test('GetPost rewrites all legacy domains in reply content', async () => {
const proc = createProcess();
stubGetPostQuery(proc, [
postRow({ reply_count: 1, reply_id: 1, reply_user_id: 'u1', content: 'see https://xmoj-bbs.tech/a and xmoj-bbs.tech/b', reply_time: 1001 })
postRow({
reply_count: 1,
reply_id: 1,
reply_user_id: 'u1',
content: 'see https://xmoj-bbs.tech/a, https://www.xmoj-bbs.me/b, and https://assets.xmoj-bbs.me/c',
reply_time: 1001
})
]);

const result = await proc.ProcessFunctions['GetPost']({ PostID: 1, Page: 1 });

assert.strictEqual(result.Data.Reply[0].Content, 'see https://xmoj-bbs.me/a and xmoj-bbs.me/b');
assert.strictEqual(
result.Data.Reply[0].Content,
'see https://xmoj-script.uk/a, https://www.xmoj-script.uk/b, and https://assets.xmoj-script.uk/c'
);
});

test('GetPost fails when the discussion does not exist', async () => {
Expand Down
Loading