Skip to content

Merge remote changes - #70

Merged
sakitibi merged 1 commit into
mainfrom
dev
Jun 28, 2026
Merged

Merge remote changes#70
sakitibi merged 1 commit into
mainfrom
dev

Conversation

@sakitibi

@sakitibi sakitibi commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • ファイル送信時のデータ処理を改善し、Base64 形式の内容を正しく扱えるようになりました。
    • クロスオリジン通信の許可ヘッダーを追加し、送信時の互換性を向上しました。
    • 既存の応答動作(成功・失敗・未対応)は維持されています。

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
asakura-wiki Ready Ready Preview, Comment Jun 28, 2026 2:08pm

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

ウォークスルー

FilePayloadfileContent 型を ArrayBuffer から string に変更し、POST ハンドラで受信した文字列をBase64デコードして Uint8Array を生成し Blob を作成する処理に置き換えた。CORSヘッダに Access-Control-Allow-Headers: Content-Type を追加した。

変更内容

Base64デコード対応

レイヤー / ファイル 概要
FilePayload型変更とBase64デコード処理
pages/api/unzip/filenow_up.ts
fileContent の型を ArrayBuffer から string に変更し、POSTハンドラで atob によるBase64デコード → Uint8Array 生成 → Blobapplication/octet-stream)作成の処理に置き換えた。あわせてCORSレスポンスヘッダに Access-Control-Allow-Headers: Content-Type を追加した。

推定コードレビュー工数

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive タイトルが抽象的で、Base64デコード対応などの実変更内容を示していません。 変更内容を要約する具体的なタイトルにしてください。例: "Base64 fileContent をデコードして zip 処理を修正"
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pages/api/unzip/filenow_up.ts`:
- Line 15: The CORS setup in the unzip upload API is too permissive because it
allows any origin with Content-Type access; update the header handling in the
upload proxy route so only the intended frontend Origin(s) are accepted via an
allowlist, and reject or omit CORS headers for all others. Adjust the existing
res.setHeader calls in the API handler to use a restricted origin check rather
than a wildcard, while keeping the necessary header allowance limited to the
expected client.
- Around line 20-23: In the API route handling `req.body` and `FilePayload`,
replace `Uint8Array.fromBase64` with a Node-compatible
`Buffer.from(body.fileContent, 'base64')` flow, and add a guard that returns 400
when `req.body` or `body.fileContent` is missing. Also validate the Base64 input
before decoding, since `Buffer.from` accepts invalid characters; reject
malformed payloads explicitly before creating the `Blob`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b5b04486-a2ed-4bea-a5d8-c3f99aaf86e0

📥 Commits

Reviewing files that changed from the base of the PR and between 2e5314b and c9dc009.

📒 Files selected for processing (1)
  • pages/api/unzip/filenow_up.ts

) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'POST,OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

CORS の許可範囲を限定してください。

Access-Control-Allow-Origin: *Access-Control-Allow-Headers: Content-Type の組み合わせにより、任意サイトからブラウザ経由でこのアップロードプロキシへ JSON POST できます。想定フロントエンドだけを許可する Origin allowlist にしてください。

修正例
-    res.setHeader('Access-Control-Allow-Origin', '*');
+    const allowedOrigins = new Set([
+        process.env.NEXT_PUBLIC_APP_ORIGIN,
+    ]);
+    const origin = req.headers.origin;
+    if (origin && allowedOrigins.has(origin)) {
+        res.setHeader('Access-Control-Allow-Origin', origin);
+    }
+    res.setHeader('Vary', 'Origin');
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/api/unzip/filenow_up.ts` at line 15, The CORS setup in the unzip upload
API is too permissive because it allows any origin with Content-Type access;
update the header handling in the upload proxy route so only the intended
frontend Origin(s) are accepted via an allowlist, and reject or omit CORS
headers for all others. Adjust the existing res.setHeader calls in the API
handler to use a restricted origin check rather than a wildcard, while keeping
the necessary header allowance limited to the expected client.

Comment on lines 20 to +23
const body = req.body as FilePayload;
const decodedb64 = Uint8Array.fromBase64(body.fileContent);

const csvBlob = new Blob([body.fileContent], { type: 'application/octet-stream' });
const csvBlob = new Blob([decodedb64], { type: 'application/octet-stream' });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Node/Next の宣言ランタイムと fromBase64 利用箇所を確認する
fd -i '^(package.json|\.node-version|\.nvmrc|Dockerfile|next\.config\.(js|mjs|ts)|tsconfig\.json)$' \
  --exec sh -c 'echo "--- $1"; sed -n "1,180p" "$1"' sh {}

rg -n --glob '*.ts' --glob '*.tsx' '\bUint8Array\.fromBase64\b'

Repository: sakitibi/AsakuraWiki

Length of output: 3199


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- pages/api/unzip/filenow_up.ts'
sed -n '1,220p' pages/api/unzip/filenow_up.ts

echo '--- runtime declarations / api route markers'
rg -n --glob 'pages/api/**/*.ts' --glob 'app/**/route.ts' 'runtime\s*=|export const runtime|fromBase64|Buffer\.from|atob\(|btoa\('

echo '--- node compatibility hints'
fd -i '^(package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb|README\.md|docs?)$' --exec sh -c 'echo "--- $1"; sed -n "1,120p" "$1"' sh {}

Repository: sakitibi/AsakuraWiki

Length of output: 2019


🌐 Web query:

Node.js Uint8Array.fromBase64 availability version documentation

💡 Result:

The Uint8Array.fromBase64 method is available in Node.js starting from version 25.0.0 [1][2][3]. While some earlier reports or community discussions may have incorrectly cited Node.js 22 as the introduction point for this feature, it was formally stabilized and made available beginning with Node.js 25 [1][4][2]. Because this method is implemented at the V8 engine level [1], its availability is tied to the V8 version included with the specific Node.js release [1]. Documentation for this feature can be found in the MDN Web Docs [2][3], as it is part of the standard JavaScript language specification for TypedArrays (TC39 proposal) [1][5]. In environments older than Node.js 25, attempting to call Uint8Array.fromBase64 will result in a TypeError, as the method will be undefined [4][6]. For backward compatibility in projects targeting older Node.js versions, developers commonly continue to use the established Buffer.from(string, 'base64') pattern [4][7].

Citations:


🌐 Web query:

Node.js Buffer.from base64 invalid input behavior documentation

💡 Result:

In Node.js, the Buffer.from(string, 'base64') method does not throw an error when encountering invalid Base64 input [1][2]. Instead, it follows a "forgiving" approach where it silently ignores or skips characters that are not part of the valid Base64 alphabet [1][2]. Key behaviors regarding Base64 input include: 1. Silent Handling of Invalid Characters: Any characters in the input string that do not conform to the Base64 alphabet (A-Z, a-z, 0-9, +, /) are ignored during the decoding process rather than causing the operation to fail [1][2]. 2. Whitespace Handling: The base64 encoding implementation explicitly ignores standard whitespace characters, including spaces, tabs, and new lines, contained within the encoded string [3][4]. 3. Assumed Validity: Official Node.js documentation notes that Buffer.from assumes valid input for base64, base64url, and hex encodings [5][4]. Because it does not perform strict validation, developers requiring strict adherence to protocol standards must manually validate strings (e.g., using regular expressions or third-party validation libraries) before passing them to Buffer.from [1][2]. Because of this behavior, developers cannot rely on Buffer.from to detect malformed Base64 data [2]. If input integrity is required, pre-validation is necessary [2].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
console.log('node', process.version);
console.log('Uint8Array.fromBase64 type:', typeof Uint8Array.fromBase64);

const samples = [
  'Zm9v',
  '!!!',
  'Zg==',
  'Zg=',
  'not-base64',
];

for (const s of samples) {
  try {
    const buf = Buffer.from(s, 'base64');
    console.log(JSON.stringify({ kind: 'Buffer.from', input: s, length: buf.length, hex: buf.toString('hex') }));
  } catch (e) {
    console.log(JSON.stringify({ kind: 'Buffer.from', input: s, error: e && e.name, message: e && e.message }));
  }

  try {
    if (typeof Uint8Array.fromBase64 === 'function') {
      const arr = Uint8Array.fromBase64(s);
      console.log(JSON.stringify({ kind: 'Uint8Array.fromBase64', input: s, length: arr.length, hex: Buffer.from(arr).toString('hex') }));
    } else {
      console.log(JSON.stringify({ kind: 'Uint8Array.fromBase64', input: s, unavailable: true }));
    }
  } catch (e) {
    console.log(JSON.stringify({ kind: 'Uint8Array.fromBase64', input: s, error: e && e.name, message: e && e.message }));
  }
}
JS

Repository: sakitibi/AsakuraWiki

Length of output: 867


Uint8Array.fromBase64 は使わないでください。
Node 24 では未対応で、この API ルートは実行時に失敗します。req.body の存在確認を入れたうえで Buffer.from(body.fileContent, 'base64') に置き換え、不正 Base64 は事前検証して 400 を返してください。Buffer.from は不正文字をそのまま受けるため、置き換えだけでは拒否できません。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/api/unzip/filenow_up.ts` around lines 20 - 23, In the API route
handling `req.body` and `FilePayload`, replace `Uint8Array.fromBase64` with a
Node-compatible `Buffer.from(body.fileContent, 'base64')` flow, and add a guard
that returns 400 when `req.body` or `body.fileContent` is missing. Also validate
the Base64 input before decoding, since `Buffer.from` accepts invalid
characters; reject malformed payloads explicitly before creating the `Blob`.

@sakitibi
sakitibi merged commit 1895720 into main Jun 28, 2026
3 checks passed
@sakitibi
sakitibi deleted the dev branch June 28, 2026 14:12
@coderabbitai coderabbitai Bot mentioned this pull request Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant