Skip to content

Commit 832895b

Browse files
eternal-flame-ADRuruke
authored andcommitted
fix(backend): fix handling of invalid urls in user profile (misskey-dev#15635)
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
1 parent 08cc68b commit 832895b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- 自動でバックアップされるように
99

1010
### Server
11-
-
11+
- Fix: プロフィール追加情報で無効なURLに入力された場合に照会エラーを出るのを修正
1212

1313

1414
## 2025.3.1

packages/backend/src/core/activitypub/ApRendererService.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,28 @@ export class ApRendererService {
501501
this.userProfilesRepository.findOneByOrFail({ userId: user.id }),
502502
]);
503503

504+
const tryRewriteUrl = (maybeUrl: string) => {
505+
const urlSafeRegex = /^(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/;
506+
try {
507+
const match = maybeUrl.match(urlSafeRegex);
508+
if (!match) {
509+
return maybeUrl;
510+
}
511+
const urlPart = match[0];
512+
const urlPartParsed = new URL(urlPart);
513+
const restPart = maybeUrl.slice(match[0].length);
514+
515+
return `<a href="${urlPartParsed.href}" rel="me nofollow noopener" target="_blank">${urlPart}</a>${restPart}`;
516+
} catch (e) {
517+
return maybeUrl;
518+
}
519+
};
520+
504521
const attachment = profile.fields.map(field => ({
505522
type: 'PropertyValue',
506523
name: field.name,
507524
value: (field.value.startsWith('http://') || field.value.startsWith('https://'))
508-
? `<a href="${new URL(field.value).href}" rel="me nofollow noopener" target="_blank">${new URL(field.value).href}</a>`
525+
? tryRewriteUrl(field.value)
509526
: field.value,
510527
}));
511528

0 commit comments

Comments
 (0)