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(backend): reject symlinks on emoji import #15535

Open
wants to merge 1 commit into
base: develop
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fix: pgroongaでの検索時にはじめのキーワードのみが検索に使用される問題を修正
(Cherry-picked from https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/886)
- Fix: メールアドレスの形式が正しくなければ以降の処理を行わないように
- Fix: カスタム絵文字パックが普通のファイルであるかどうかを確認するように

## 2025.2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { DbUserImportJobData } from '../types.js';

async function ensureRegularFile(path: string) {
if (!(await fs.promises.stat(path)).isFile()) {
throw new Error(`'${path}' is not a file`);
}
}

// TODO: 名前衝突時の動作を選べるようにする
@Injectable()
export class ImportCustomEmojisProcessorService {
Expand Down Expand Up @@ -69,7 +75,9 @@ export class ImportCustomEmojisProcessorService {
try {
this.logger.succ(`Unzipping to ${outputPath}`);
ZipReader.withDestinationPath(outputPath).viaBuffer(await fs.promises.readFile(destPath));
const metaRaw = fs.readFileSync(outputPath + '/meta.json', 'utf-8');
const metaPath = outputPath + '/meta.json';
await ensureRegularFile(metaPath);
const metaRaw = await fs.promises.readFile(metaPath, 'utf-8');
const meta = JSON.parse(metaRaw);

for (const record of meta.emojis) {
Expand All @@ -84,6 +92,7 @@ export class ImportCustomEmojisProcessorService {
continue;
}
const emojiPath = outputPath + '/' + record.fileName;
await ensureRegularFile(emojiPath);
await this.emojisRepository.delete({
name: emojiInfo.name,
});
Expand Down
Loading