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

Merge upstream #839

Draft
wants to merge 770 commits into
base: io
Choose a base branch
from
Draft

Merge upstream #839

wants to merge 770 commits into from

Conversation

u1-liquid
Copy link
Member

What

Why

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

KisaragiEffective and others added 30 commits October 3, 2024 17:05
* fix(backend): 連合限定先が間違って連合しない先に代入されているのを修正

* build: fix property typo
* feat: サーバー初期設定時専用の初期パスワードを設定できるように

* 無いのに入力された場合もエラーにする

* 🎨

* 🎨

* cypress-devcontainerにもpassを設定(テストが失敗するため)

* [ci skip] 🎨

* ✌️

* test: please revert this commit before merge

* Revert "test: please revert this commit before merge"

This reverts commit 66b2b48.

* Update locales/ja-JP.yml

Co-authored-by: syuilo <[email protected]>

* build assets

* Update Changelog

* fix condition

* fix condition

* add comment

* change error code

* 他のエラーコードと合わせる

* Update CHANGELOG.md

---------

Co-authored-by: syuilo <[email protected]>
* fix: 初期パスワードをコメントアウト

* 🎨

* fix indent
* wip

* Update MkSignin.vue

* Update MkSignin.vue

* wip

* Update CHANGELOG.md

* enhance(frontend): サインイン画面の改善

* Update Changelog

* 14655の変更取り込み

* spdx

* fix

* fix

* fix

* 🎨

* 🎨

* 🎨

* 🎨

* Captchaがリセットされない問題を修正

* 次の処理をsignin apiから読み取るように

* Add Comments

* fix

* fix test

* attempt to fix test

* fix test

* fix test

* fix test

* fix

* fix test

* fix: 一部のエラーがちゃんと出るように

* Update Changelog

* 🎨

* 🎨

* remove border

---------

Co-authored-by: syuilo <[email protected]>
* New translations ja-jp.yml (Chinese Traditional)

* New translations ja-jp.yml (Korean)

* New translations ja-jp.yml (Chinese Simplified)

* New translations ja-jp.yml (English)

* New translations ja-jp.yml (Chinese Traditional)

* New translations ja-jp.yml (Korean)

* New translations ja-jp.yml (Chinese Simplified)

* New translations ja-jp.yml (Chinese Simplified)
* fix(frontend): ログイン画面でキャプチャが表示されない問題を修正

* rename
* fix: signin の資格情報が足りないだけの場合はエラーにせず200を返すように

* run api extractor

* fix

* fix

* fix test

* /signin -> /signin-flow

* fix

* fix lint

* rename

* fix

* fix
…dev#14698)

* feat(backend): 通報および通報解決時に送出されるSystemWebhookにユーザ情報を含めるようにする

* テスト送信もペイロード形式を合わせる

* add spaces

* fix test
syuilo and others added 20 commits November 23, 2024 04:44
* fix(frontend): 画面サイズが変わった際にnavbarが自動で折りたたまれない問題を修正

* Update Changelog

* fix
…dev#15033)

* fix(backend): アドレス入力で直接ユーザのプロフィールページを表示した際、前提データが足りず描画に失敗する

* fix CHANGELOG.md
…sskey-dev#15044)

* fix(frontend): サーバードキュメントとMisskey関連リソースとの間にdividerが入らないことがある問題を修正

* Update Changelog
* check harder for connectibility

`allSettled` does not throw if a promise is rejected, so
`check_connect` never actually failed

* Update Changelog

---------

Co-authored-by: dakkar <[email protected]>
* Resolve frontend/backend contradiction for home visibility embeds

This now uses the same check from `packages/frontend/src/scripts/get-note-menu.ts`

* Update Changelog

---------

Co-authored-by: CenTdemeern1 <[email protected]>
misskey-dev#15101)

* fix(frontend): ノートがログインしているユーザーしか見れない場合にログインをキャンセルすると一切の処理が停止する問題を修正

* Update Changelog

---------

Co-authored-by: syuilo <[email protected]>
* チャンネル一覧の列を最大3列にした (Otaku-Social#13)

* fix

* fix

* fix

* 🎨

* fix

* 🎨

* Update Changelog

* Update Changelog

* 要らない_marginを消す

---------

Co-authored-by: tmorio <[email protected]>
* fix(frontend): 絵文字管理画面で絵文字が表示されないことがある問題を修正

* Update Changelog

* optimize
* fix(frontend): serverContextの型エラーを修正

* add comment
* enhance: 照会の失敗理由を表示するように

* Update Changelog

* fix

* fix test

* lookupErrors-> remoteLookupErrors
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
34 Security Hotspots
D Security Rating on New Code (required ≥ A)
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

name: randomString(),
on: ['abuseReport'],
url: WEBHOOK_HOST,
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will modify the randomString function to use crypto.randomBytes instead of Math.random().

  1. Import the crypto module in the utils.ts file.
  2. Modify the randomString function to use crypto.randomBytes to generate random values.
Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -8,3 +8,3 @@
 import { basename, isAbsolute } from 'node:path';
-import { randomUUID } from 'node:crypto';
+import { randomUUID, randomBytes } from 'node:crypto';
 import { inspect } from 'node:util';
@@ -122,5 +122,6 @@
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
+	const randomBytes = crypto.randomBytes(length);
 	let randomString = '';
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[randomBytes[i] % chars.length];
 	}
EOF
@@ -8,3 +8,3 @@
import { basename, isAbsolute } from 'node:path';
import { randomUUID } from 'node:crypto';
import { randomUUID, randomBytes } from 'node:crypto';
import { inspect } from 'node:util';
@@ -122,5 +122,6 @@
export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
const randomBytes = crypto.randomBytes(length);
let randomString = '';
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[randomBytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['userCreated'],
url: WEBHOOK_HOST,
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will update the randomString function to use crypto.randomBytes instead of Math.random().

  • Update the randomString function in packages/backend/test/utils.ts to use crypto.randomBytes.
  • Import the crypto module in packages/backend/test/utils.ts.
Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -121,6 +121,9 @@
 
+import { randomBytes } from 'node:crypto';
+
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
 	let randomString = '';
+	const bytes = randomBytes(length);
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[bytes[i] % chars.length];
 	}
EOF
@@ -121,6 +121,9 @@

import { randomBytes } from 'node:crypto';

export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
const bytes = randomBytes(length);
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[bytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['abuseReport'],
url: 'https://example.com',
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will modify the randomString function to use crypto.randomBytes instead of Math.random().

Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -121,6 +121,9 @@
 
+import { randomBytes } from 'crypto';
+
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
 	let randomString = '';
+	const bytes = randomBytes(length);
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[bytes[i] % chars.length];
 	}
EOF
@@ -121,6 +121,9 @@

import { randomBytes } from 'crypto';

export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
const bytes = randomBytes(length);
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[bytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
});

beforeEach(async () => {
const uid = idService.gen();

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will modify the getRandom() function in packages/backend/src/misc/id/meid.ts to use crypto.randomBytes instead of Math.random().

Suggested changeset 1
packages/backend/src/misc/id/meid.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/src/misc/id/meid.ts b/packages/backend/src/misc/id/meid.ts
--- a/packages/backend/src/misc/id/meid.ts
+++ b/packages/backend/src/misc/id/meid.ts
@@ -5,2 +5,4 @@
 
+import { randomBytes } from 'crypto';
+
 const CHARS = '0123456789abcdef';
@@ -23,5 +25,6 @@
 	let str = '';
+	const randomValues = randomBytes(12);
 
 	for (let i = 0; i < 12; i++) {
-		str += CHARS[Math.floor(Math.random() * CHARS.length)];
+		str += CHARS[randomValues[i] % CHARS.length];
 	}
EOF
@@ -5,2 +5,4 @@

import { randomBytes } from 'crypto';

const CHARS = '0123456789abcdef';
@@ -23,5 +25,6 @@
let str = '';
const randomValues = randomBytes(12);

for (let i = 0; i < 12; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
str += CHARS[randomValues[i] % CHARS.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['abuseReport'],
url: 'https://example.com',
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() in the randomString function with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will update the randomString function to use crypto.randomBytes instead of Math.random().

Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -121,6 +121,9 @@
 
+import { randomBytes } from 'crypto';
+
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
 	let randomString = '';
+	const bytes = randomBytes(length);
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[bytes[i] % chars.length];
 	}
EOF
@@ -121,6 +121,9 @@

import { randomBytes } from 'crypto';

export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
const bytes = randomBytes(length);
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[bytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['abuseReport'],
url: 'https://example.com',
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() in the randomString function with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to achieve this. This change will ensure that the generated random strings are not predictable.

  • Modify the randomString function in packages/backend/test/utils.ts to use crypto.randomBytes instead of Math.random().
  • Import the crypto module in the same file.
Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -8,3 +8,3 @@
 import { basename, isAbsolute } from 'node:path';
-import { randomUUID } from 'node:crypto';
+import { randomUUID, randomBytes } from 'node:crypto';
 import { inspect } from 'node:util';
@@ -122,5 +122,6 @@
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
+	const randomBytes = crypto.randomBytes(length);
 	let randomString = '';
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[randomBytes[i] % chars.length];
 	}
EOF
@@ -8,3 +8,3 @@
import { basename, isAbsolute } from 'node:path';
import { randomUUID } from 'node:crypto';
import { randomUUID, randomBytes } from 'node:crypto';
import { inspect } from 'node:util';
@@ -122,5 +122,6 @@
export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
const randomBytes = crypto.randomBytes(length);
let randomString = '';
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[randomBytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['abuseReport'],
url: 'https://example.com',
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() in the randomString function with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to achieve this. This change will ensure that the generated strings are not predictable and are suitable for use in security-sensitive contexts.

Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -121,6 +121,9 @@
 
+import { randomBytes } from 'node:crypto';
+
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
 	let randomString = '';
+	const bytes = randomBytes(length);
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[bytes[i] % chars.length];
 	}
EOF
@@ -121,6 +121,9 @@

import { randomBytes } from 'node:crypto';

export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
const bytes = randomBytes(length);
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[bytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
name: randomString(),
on: ['mention'],
url: 'https://example.com',
secret: randomString(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() in the randomString function with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will modify the randomString function to use crypto.randomBytes instead of Math.random().

Suggested changeset 1
packages/backend/test/utils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts
--- a/packages/backend/test/utils.ts
+++ b/packages/backend/test/utils.ts
@@ -121,6 +121,9 @@
 
+import { randomBytes } from 'crypto';
+
 export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
 	let randomString = '';
+	const bytes = randomBytes(length);
 	for (let i = 0; i < length; i++) {
-		randomString += chars[Math.floor(Math.random() * chars.length)];
+		randomString += chars[bytes[i] % chars.length];
 	}
EOF
@@ -121,6 +121,9 @@

import { randomBytes } from 'crypto';

export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', length = 16) {
let randomString = '';
const bytes = randomBytes(length);
for (let i = 0; i < length; i++) {
randomString += chars[Math.floor(Math.random() * chars.length)];
randomString += chars[bytes[i] % chars.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
const user = await usersRepository
.insert({
id: id,
username: `user_${id}`,

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure pseudo-random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. We will modify the getRandom function in packages/backend/src/misc/id/meid.ts to use crypto.randomBytes instead of Math.random(). This change will ensure that the generated IDs are not predictable and are suitable for use in security-sensitive contexts.

Suggested changeset 1
packages/backend/src/misc/id/meid.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/src/misc/id/meid.ts b/packages/backend/src/misc/id/meid.ts
--- a/packages/backend/src/misc/id/meid.ts
+++ b/packages/backend/src/misc/id/meid.ts
@@ -6,2 +6,3 @@
 const CHARS = '0123456789abcdef';
+import { randomBytes } from 'crypto';
 
@@ -22,2 +23,3 @@
 function getRandom() {
+	const bytes = randomBytes(12);
 	let str = '';
@@ -25,3 +27,3 @@
 	for (let i = 0; i < 12; i++) {
-		str += CHARS[Math.floor(Math.random() * CHARS.length)];
+		str += CHARS[bytes[i] % CHARS.length];
 	}
EOF
@@ -6,2 +6,3 @@
const CHARS = '0123456789abcdef';
import { randomBytes } from 'crypto';

@@ -22,2 +23,3 @@
function getRandom() {
const bytes = randomBytes(12);
let str = '';
@@ -25,3 +27,3 @@
for (let i = 0; i < 12; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
str += CHARS[bytes[i] % CHARS.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
.insert({
id: id,
username: `user_${id}`,
usernameLower: `user_${id}`.toLowerCase(),

Check failure

Code scanning / CodeQL

Insecure randomness High test

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
This uses a cryptographically insecure random number generated at
Math.random()
in a security context.

Copilot Autofix AI about 2 months ago

To fix the problem, we need to replace the use of Math.random() with a cryptographically secure random number generator. In Node.js, we can use the crypto module's randomBytes function to generate secure random values. This change will ensure that the generated IDs are not predictable.

  • Replace the getRandom function in packages/backend/src/misc/id/meid.ts to use crypto.randomBytes instead of Math.random().
  • Update the import statements to include the crypto module.
Suggested changeset 1
packages/backend/src/misc/id/meid.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/backend/src/misc/id/meid.ts b/packages/backend/src/misc/id/meid.ts
--- a/packages/backend/src/misc/id/meid.ts
+++ b/packages/backend/src/misc/id/meid.ts
@@ -21,7 +21,10 @@
 
+import { randomBytes } from 'crypto';
+
 function getRandom() {
 	let str = '';
+	const bytes = randomBytes(12);
 
 	for (let i = 0; i < 12; i++) {
-		str += CHARS[Math.floor(Math.random() * CHARS.length)];
+		str += CHARS[bytes[i] % CHARS.length];
 	}
EOF
@@ -21,7 +21,10 @@

import { randomBytes } from 'crypto';

function getRandom() {
let str = '';
const bytes = randomBytes(12);

for (let i = 0; i < 12; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
str += CHARS[bytes[i] % CHARS.length];
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.