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: node.js の punycode モジュールが使用されている場所がある問題 #15248

Merged
merged 14 commits into from
Jan 14, 2025
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
6 changes: 2 additions & 4 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
"json5": "2.2.3",
"jsonld": "8.3.2",
"jsrsasign": "11.1.0",
"meilisearch": "0.45.0",
"juice": "11.0.0",
"meilisearch": "0.45.0",
"mfm-js": "0.24.0",
"microformats-parser": "2.0.2",
"mime-types": "2.1.35",
Expand All @@ -146,7 +146,7 @@
"nested-property": "4.0.0",
"node-fetch": "3.3.2",
"nodemailer": "6.9.16",
"nsfwjs": "2.4.2",
"nsfwjs": "4.2.0",
"oauth": "0.10.0",
"oauth2orize": "1.12.0",
"oauth2orize-pkce": "0.1.2",
Expand All @@ -158,7 +158,6 @@
"probe-image-size": "7.2.3",
"promise-limit": "2.7.0",
"pug": "3.0.3",
"punycode": "2.3.1",
"qrcode": "1.5.4",
"random-seed": "0.3.0",
"ratelimiter": "3.4.1",
Expand Down Expand Up @@ -215,7 +214,6 @@
"@types/oauth2orize-pkce": "0.1.2",
"@types/pg": "8.11.10",
"@types/pug": "2.0.10",
"@types/punycode": "2.1.4",
"@types/qrcode": "1.5.5",
"@types/random-seed": "0.3.5",
"@types/ratelimiter": "3.4.6",
Expand Down
4 changes: 3 additions & 1 deletion packages/backend/src/core/AiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Injectable } from '@nestjs/common';
import * as nsfw from 'nsfwjs';
import si from 'systeminformation';
import { Mutex } from 'async-mutex';
import fetch from 'node-fetch';
import { bindThis } from '@/decorators.js';

const _filename = fileURLToPath(import.meta.url);
Expand All @@ -28,7 +29,7 @@ export class AiService {
}

@bindThis
public async detectSensitive(path: string): Promise<nsfw.predictionType[] | null> {
public async detectSensitive(path: string): Promise<nsfw.PredictionType[] | null> {
try {
if (isSupportedCpu === undefined) {
isSupportedCpu = await this.computeIsSupportedCpu();
Expand All @@ -40,6 +41,7 @@ export class AiService {
}

const tf = await import('@tensorflow/tfjs-node');
tf.env().global.fetch = fetch;

if (this.model == null) {
await this.modelLoadMutex.runExclusive(async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/src/core/FetchInstanceMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async fetchDom(instance: MiInstance): Promise<DOMWindow['document']> {
private async fetchDom(instance: MiInstance): Promise<Document> {
this.logger.info(`Fetching HTML of ${instance.host} ...`);

const url = 'https://' + instance.host;
Expand All @@ -206,7 +206,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async fetchFaviconUrl(instance: MiInstance, doc: DOMWindow['document'] | null): Promise<string | null> {
private async fetchFaviconUrl(instance: MiInstance, doc: Document | null): Promise<string | null> {
const url = 'https://' + instance.host;

if (doc) {
Expand All @@ -232,7 +232,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async fetchIconUrl(instance: MiInstance, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
private async fetchIconUrl(instance: MiInstance, doc: Document | null, manifest: Record<string, any> | null): Promise<string | null> {
if (manifest && manifest.icons && manifest.icons.length > 0 && manifest.icons[0].src) {
const url = 'https://' + instance.host;
return (new URL(manifest.icons[0].src, url)).href;
Expand Down Expand Up @@ -261,7 +261,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async getThemeColor(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
private async getThemeColor(info: NodeInfo | null, doc: Document | null, manifest: Record<string, any> | null): Promise<string | null> {
const themeColor = info?.metadata?.themeColor ?? doc?.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? manifest?.theme_color;

if (themeColor) {
Expand All @@ -273,7 +273,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async getSiteName(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
private async getSiteName(info: NodeInfo | null, doc: Document | null, manifest: Record<string, any> | null): Promise<string | null> {
if (info && info.metadata) {
if (typeof info.metadata.nodeName === 'string') {
return info.metadata.nodeName;
Expand All @@ -298,7 +298,7 @@ export class FetchInstanceMetadataService {
}

@bindThis
private async getDescription(info: NodeInfo | null, doc: DOMWindow['document'] | null, manifest: Record<string, any> | null): Promise<string | null> {
private async getDescription(info: NodeInfo | null, doc: Document | null, manifest: Record<string, any> | null): Promise<string | null> {
if (info && info.metadata) {
if (typeof info.metadata.nodeDescription === 'string') {
return info.metadata.nodeDescription;
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/FileInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import * as fileType from 'file-type';
import FFmpeg from 'fluent-ffmpeg';
import isSvg from 'is-svg';
import probeImageSize from 'probe-image-size';
import { type predictionType } from 'nsfwjs';
import { sharpBmp } from '@misskey-dev/sharp-read-bmp';
import * as blurhash from 'blurhash';
import { createTempDir } from '@/misc/create-temp.js';
import { AiService } from '@/core/AiService.js';
import { LoggerService } from '@/core/LoggerService.js';
import type Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import type { PredictionType } from 'nsfwjs';

export type FileInfo = {
size: number;
Expand Down Expand Up @@ -170,7 +170,7 @@ export class FileInfoService {
let sensitive = false;
let porn = false;

function judgePrediction(result: readonly predictionType[]): [sensitive: boolean, porn: boolean] {
function judgePrediction(result: readonly PredictionType[]): [sensitive: boolean, porn: boolean] {
let sensitive = false;
let porn = false;

Expand Down
7 changes: 3 additions & 4 deletions packages/backend/src/core/UtilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { URL } from 'node:url';
import { toASCII } from 'punycode';
import { URL, domainToASCII } from 'node:url';
import { Inject, Injectable } from '@nestjs/common';
import RE2 from 're2';
import { DI } from '@/di-symbols.js';
Expand Down Expand Up @@ -106,13 +105,13 @@ export class UtilityService {

@bindThis
public toPuny(host: string): string {
return toASCII(host.toLowerCase());
return domainToASCII(host.toLowerCase());
}

@bindThis
public toPunyNullable(host: string | null | undefined): string | null {
if (host == null) return null;
return toASCII(host.toLowerCase());
return domainToASCII(host.toLowerCase());
}

@bindThis
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const html = await this.httpRequestService.getHtml(url);

const { window } = new JSDOM(html);
const doc = window.document;
const doc: Document = window.document;

const myLink = `${this.config.url}/@${user.username}`;

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend-embed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"mfm-js": "0.24.0",
"misskey-js": "workspace:*",
"frontend-shared": "workspace:*",
"punycode": "2.3.1",
"punycode.js": "2.3.1",
"rollup": "4.26.0",
"sass": "1.79.4",
"shiki": "1.22.2",
Expand All @@ -44,7 +44,7 @@
"@types/estree": "1.0.6",
"@types/micromatch": "4.0.9",
"@types/node": "22.9.0",
"@types/punycode": "2.1.4",
"@types/punycode.js": "npm:@types/punycode@2.1.4",
"@types/tinycolor2": "1.4.6",
"@types/uuid": "10.0.0",
"@types/ws": "8.5.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-embed/src/components/EmAcct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { toUnicode } from 'punycode/';
import { toUnicode } from 'punycode.js';
import { host as hostRaw } from '@@/js/config.js';

defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-embed/src/components/EmMention.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { toUnicode } from 'punycode';
import { toUnicode } from 'punycode.js';
import { } from 'vue';
import tinycolor from 'tinycolor2';
import { host as localHost } from '@@/js/config.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend-embed/src/components/EmUrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref } from 'vue';
import { toUnicode as decodePunycode } from 'punycode/';
import { toUnicode as decodePunycode } from 'punycode.js';
import EmA from './EmA.vue';
import { url as local } from '@@/js/config.js';

Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"misskey-js": "workspace:*",
"misskey-reversi": "workspace:*",
"photoswipe": "5.4.4",
"punycode": "2.3.1",
"punycode.js": "2.3.1",
"rollup": "4.26.0",
"sanitize-html": "2.13.1",
"sass": "1.79.3",
Expand Down Expand Up @@ -101,7 +101,7 @@
"@types/matter-js": "0.19.7",
"@types/micromatch": "4.0.9",
"@types/node": "22.9.0",
"@types/punycode": "2.1.4",
"@types/punycode.js": "npm:@types/punycode@2.1.4",
"@types/sanitize-html": "2.13.0",
"@types/seedrandom": "3.0.8",
"@types/throttle-debounce": "5.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkMention.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { toUnicode } from 'punycode';
import { toUnicode } from 'punycode.js';
import { computed } from 'vue';
import { host as localHost } from '@@/js/config.js';
import { $i } from '@/account.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkPostForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import { inject, watch, nextTick, onMounted, defineAsyncComponent, provide, shal
import * as mfm from 'mfm-js';
import * as Misskey from 'misskey-js';
import insertTextAtCursor from 'insert-text-at-cursor';
import { toASCII } from 'punycode/';
import { toASCII } from 'punycode.js';
import { host, url } from '@@/js/config.js';
import type { PostFormProps } from '@/types/post-form.js';
import MkNoteSimple from '@/components/MkNoteSimple.vue';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkSignin.input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script setup lang="ts">
import { ref } from 'vue';
import { toUnicode } from 'punycode/';
import { toUnicode } from 'punycode.js';

import { query, extractDomain } from '@@/js/url.js';
import { host as configHost } from '@@/js/config.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkSignupDialog.form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref, computed } from 'vue';
import { toUnicode } from 'punycode/';
import { toUnicode } from 'punycode.js';
import * as Misskey from 'misskey-js';
import * as config from '@@/js/config.js';
import MkButton from './MkButton.vue';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/global/MkAcct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { toUnicode } from 'punycode/';
import { toUnicode } from 'punycode.js';
import { host as hostRaw } from '@@/js/config.js';
import { defaultStore } from '@/store.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/global/MkUrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { defineAsyncComponent, ref } from 'vue';
import { toUnicode as decodePunycode } from 'punycode/';
import { toUnicode as decodePunycode } from 'punycode.js';
import { url as local } from '@@/js/config.js';
import * as os from '@/os.js';
import { useTooltip } from '@/scripts/use-tooltip.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/theme-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { watch, ref, computed } from 'vue';
import { toUnicode } from 'punycode/';
import { toUnicode } from 'punycode.js';
import tinycolor from 'tinycolor2';
import { v4 as uuid } from 'uuid';
import JSON5 from 'json5';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/scripts/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { nextTick, Ref, ref, defineAsyncComponent } from 'vue';
import getCaretCoordinates from 'textarea-caret';
import { toASCII } from 'punycode/';
import { toASCII } from 'punycode.js';
import { popup } from '@/os.js';

export type SuggestionType = 'user' | 'hashtag' | 'emoji' | 'mfmTag' | 'mfmParam';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/scripts/get-user-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { toUnicode } from 'punycode';
import { toUnicode } from 'punycode.js';
import { defineAsyncComponent, ref, watch } from 'vue';
import * as Misskey from 'misskey-js';
import { i18n } from '@/i18n.js';
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ export default [
'@typescript-eslint/no-var-requires': 'off',
},
},
{
rules: {
'no-restricted-imports': ['error', {
paths: [{ name: 'punycode' }],
}],
},
},
];
Loading
Loading