filetype-real-mime
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "filetype-real-mime" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-82d2d64190b3ea5326faf8be50edd320a2323d78967945b3b5f41b357d0df711. Verify the upstream source and version against https://skillhub.cn/skills/user_f1b049da/gir20261037 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Use the file-type library to identify a file's real MIME type from its header (magic bytes) to catch attachments with disguised extensions. Suitable for scenarios that require determining true file types and performing MIME checks before upload.
Introduction source: third_party · user_f1b049da · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: filetype-real-mime
slug: gir20261037
displayName: 文件真实类型
version: 1.0.0
summary: 按文件头识别真实 MIME,防伪扩展名附件,本地不请求后端。
license: MIT
description: 用 file-type 按文件头(magic bytes)识别真实 MIME,拦截伪扩展名附件。当用户需要文件真实类型、file-type、防伪造扩展名、上传前 MIME 校验时使用。文件真实类型(file-type)
灵感:能力工具箱 file-type(pkg: file-type)。
上传附件前在浏览器读文件头,识别真实 MIME/扩展名,避免「.jpg 实为可执行或异型包」仅靠后缀通过。
何时使用
- CRM / 网盘附件上传前校验
- 只允许图片、PDF、Office 等白名单
- 怀疑伪扩展名、双后缀欺骗
硬约束
- 依赖
file-type(浏览器用其支持的 Blob/Buffer API,如fileTypeFromBlob;版本以项目可安装的为准并写明)。 - 以文件头为准,不要只信
file.name/file.type。 - 识别失败(无签名文本等)单独分支:可拒绝或标「未知类型」,策略写死在封装里。
- 白名单示例:
image/jpegimage/pngimage/webpapplication/pdf;业务可扩展。 - 只读文件前若干 KB 即可;不把整文件上传到第三方鉴权服务(本 Skill 本地完成)。
- 不替代服务端再校验;前端拦截是第一层。
推荐实现要点
import { fileTypeFromBlob } from 'file-type'
const ALLOW = new Set([
'image/jpeg',
'image/png',
'image/webp',
'image/gif',
'application/pdf',
])
export async function inspectRealType(file: Blob & { name?: string }) {
const detected = await fileTypeFromBlob(file)
const extFromName = (file.name || '').split('.').pop()?.toLowerCase() || ''
if (!detected) {
return {
ok: false as const,
reason: '无法从文件头识别类型(可能是纯文本或未知格式)',
extFromName,
}
}
const allowed = ALLOW.has(detected.mime)
const extMismatch =
!!extFromName &&
extFromName !== detected.ext &&
!(extFromName === 'jpg' && detected.ext === 'jpg')
return {
ok: allowed && !extMismatch,
mime: detected.mime,
ext: detected.ext,
extFromName,
extMismatch,
reason: !allowed
? `类型 ${detected.mime} 不在允许列表`
: extMismatch
? `扩展名 .${extFromName} 与真实 .${detected.ext} 不一致`
: 'ok',
}
}
若当前
file-type大版本仅 ESM / API 名不同,Agent 应查该版本文档改导入,保持「文件头 + 白名单」语义不变。
Agent 步骤
- 安装兼容的
file-type,封装inspectRealType。 - 挂到
<input type="file">/ 拖拽上传:不通过则 toast 中文原因并清空选择。 - 自测:真实 PNG 改后缀为
.pdf应extMismatch;正常 JPEG 通过。
附加
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Areas to improve
-
缺少完整端到端示例 Reported severity: Minor
文档提供了核心实现代码片段,但缺少完整的端到端使用示例
Recommendation: 建议补充一个完整的前端页面示例,展示如何集成到文件上传流程中
Highlights
- 解决文件上传安全校验的实际痛点
- 适用于CRM/网盘等常见业务场景
- 提供白名单机制防止恶意文件上传
Areas to improve
-
触发词覆盖不全 Reported severity: Minor
description中缺少'文件类型检测'、'MIME校验'等常见触发词
Recommendation: 建议在description中补充更多用户可能使用的搜索关键词
Highlights
- 触发词覆盖合理,包含主要使用场景
- 边界清晰,不会与其他文件处理Skill混淆
Areas to improve
-
文档结构可优化 Reported severity: Minor
硬约束和推荐实现要点可以合并为更清晰的结构
Recommendation: 建议将硬约束和推荐实现要点合并为'实现要求'章节,结构更清晰
Highlights
- Phase/步骤清晰,有明确的Agent执行步骤
- 包含出口条件和自测方案
- frontmatter完整,单文件长度适中
Areas to improve
-
缺少不可逆操作确认机制 Reported severity: Minor
文档未说明在拒绝文件时是否需要用户确认
Recommendation: 建议在实现要点中补充用户交互确认机制,避免误操作
Highlights
- 工具来源明确(file-type库)
- 参数使用正确,覆盖主要异常情况
- 本地处理不依赖第三方服务,可靠性高
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.