@mintmark/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +18 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +277 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Mintmark
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @mintmark/core
|
|
2
|
+
|
|
3
|
+
The pure fingerprinting + drift-detection engine behind [Mintmark](https://mintmark.dev) - the trust layer for the MCP supply chain.
|
|
4
|
+
|
|
5
|
+
This package is dependency-light and I/O-free. It powers the `mintmark` CLI and the `@mintmark/census` crawler.
|
|
6
|
+
|
|
7
|
+
## What it provides
|
|
8
|
+
|
|
9
|
+
- **Interface fingerprinting** - canonicalize an MCP server's tool definitions and hash them stably (`computeFingerprint`, `interfaceHash`, `canonicalizeInterface`).
|
|
10
|
+
- **Drift / rug-pull detection** - diff a live interface against an approved baseline and classify changes by severity (`diffInterfaces`, `buildDriftReport`).
|
|
11
|
+
- **Artifact fingerprinting** - fingerprint a server's package identity (version, maintainers, integrity, install scripts) and diff it over time; maintainer takeover and same-version integrity changes rank `high` (`computeArtifactFingerprint`, `diffArtifacts`).
|
|
12
|
+
- **Heuristics** - prompt-injection pattern detection (`containsInjectionPattern`) and typosquat detection (`isTyposquat`, `levenshtein`).
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { computeFingerprint, buildDriftReport } from "@mintmark/core";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
type JsonSchema = Record<string, unknown>;
|
|
2
|
+
interface ToolDescriptor {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: JsonSchema;
|
|
6
|
+
}
|
|
7
|
+
interface ServerInterface {
|
|
8
|
+
tools: ToolDescriptor[];
|
|
9
|
+
}
|
|
10
|
+
interface ServerIdentity {
|
|
11
|
+
name: string;
|
|
12
|
+
source?: string;
|
|
13
|
+
version?: string;
|
|
14
|
+
}
|
|
15
|
+
interface Fingerprint {
|
|
16
|
+
identity: ServerIdentity;
|
|
17
|
+
interface: ServerInterface;
|
|
18
|
+
interfaceHash: string;
|
|
19
|
+
artifactHash: string | null;
|
|
20
|
+
capturedAt: string;
|
|
21
|
+
}
|
|
22
|
+
type DriftKind = "tool_added" | "tool_removed" | "description_changed" | "schema_widened" | "schema_changed";
|
|
23
|
+
type DriftCategory = "interface" | "artifact" | "semantic";
|
|
24
|
+
type Severity = "none" | "low" | "medium" | "high";
|
|
25
|
+
/** Total order on severities; shared by drift aggregation and CLI fail-on gating. */
|
|
26
|
+
declare const SEVERITY_RANK: Record<Severity, number>;
|
|
27
|
+
interface DriftChange {
|
|
28
|
+
kind: DriftKind;
|
|
29
|
+
tool?: string;
|
|
30
|
+
detail: string;
|
|
31
|
+
category: DriftCategory;
|
|
32
|
+
severity: Severity;
|
|
33
|
+
}
|
|
34
|
+
interface DriftReport {
|
|
35
|
+
serverName: string;
|
|
36
|
+
changes: DriftChange[];
|
|
37
|
+
maxSeverity: Severity;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare function normalizeText(s: string): string;
|
|
41
|
+
declare function sortKeysDeep(value: unknown): unknown;
|
|
42
|
+
declare function canonicalizeInterface(iface: ServerInterface): ServerInterface;
|
|
43
|
+
|
|
44
|
+
declare function interfaceHash(iface: ServerInterface): string;
|
|
45
|
+
|
|
46
|
+
interface FingerprintOptions {
|
|
47
|
+
capturedAt: string;
|
|
48
|
+
artifactHash?: string | null;
|
|
49
|
+
}
|
|
50
|
+
declare function computeFingerprint(identity: ServerIdentity, iface: ServerInterface, opts: FingerprintOptions): Fingerprint;
|
|
51
|
+
|
|
52
|
+
declare function containsInjectionPattern(text: string): boolean;
|
|
53
|
+
declare const injectionPatternCount: number;
|
|
54
|
+
|
|
55
|
+
declare function diffInterfaces(baseline: ServerInterface, current: ServerInterface): DriftChange[];
|
|
56
|
+
|
|
57
|
+
declare function maxSeverity(severities: Severity[]): Severity;
|
|
58
|
+
declare function buildDriftReport(serverName: string, baseline: Fingerprint, current: ServerInterface): DriftReport;
|
|
59
|
+
|
|
60
|
+
declare const POPULAR_SERVERS: string[];
|
|
61
|
+
declare function levenshtein(a: string, b: string): number;
|
|
62
|
+
declare function isTyposquat(name: string, popular?: string[]): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The human-facing segment of a server name. MCP registry names are reverse-DNS
|
|
65
|
+
* (e.g. "io.evil/githubb"); typosquat comparison should run on the part after the
|
|
66
|
+
* last "/" ("githubb"), not the whole namespaced string.
|
|
67
|
+
*/
|
|
68
|
+
declare function serverShortName(name: string): string;
|
|
69
|
+
|
|
70
|
+
interface PackageCoord {
|
|
71
|
+
registryType: "npm" | "pypi" | "oci";
|
|
72
|
+
identifier: string;
|
|
73
|
+
version: string;
|
|
74
|
+
}
|
|
75
|
+
interface ArtifactInput {
|
|
76
|
+
name: string;
|
|
77
|
+
version: string;
|
|
78
|
+
packages: PackageCoord[];
|
|
79
|
+
maintainers: string[];
|
|
80
|
+
integrity: string | null;
|
|
81
|
+
hasInstallScript: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface ArtifactFingerprint extends ArtifactInput {
|
|
84
|
+
artifactHash: string;
|
|
85
|
+
capturedAt: string;
|
|
86
|
+
}
|
|
87
|
+
declare function computeArtifactFingerprint(input: ArtifactInput, opts: {
|
|
88
|
+
capturedAt: string;
|
|
89
|
+
}): ArtifactFingerprint;
|
|
90
|
+
type ArtifactDriftKind = "version_changed" | "maintainer_changed" | "integrity_changed" | "install_script_added" | "package_added" | "package_removed";
|
|
91
|
+
interface ArtifactChange {
|
|
92
|
+
kind: ArtifactDriftKind;
|
|
93
|
+
detail: string;
|
|
94
|
+
severity: Severity;
|
|
95
|
+
}
|
|
96
|
+
declare function diffArtifacts(baseline: ArtifactFingerprint, current: ArtifactFingerprint): ArtifactChange[];
|
|
97
|
+
|
|
98
|
+
export { type ArtifactChange, type ArtifactDriftKind, type ArtifactFingerprint, type ArtifactInput, type DriftCategory, type DriftChange, type DriftKind, type DriftReport, type Fingerprint, type FingerprintOptions, type JsonSchema, POPULAR_SERVERS, type PackageCoord, SEVERITY_RANK, type ServerIdentity, type ServerInterface, type Severity, type ToolDescriptor, buildDriftReport, canonicalizeInterface, computeArtifactFingerprint, computeFingerprint, containsInjectionPattern, diffArtifacts, diffInterfaces, injectionPatternCount, interfaceHash, isTyposquat, levenshtein, maxSeverity, normalizeText, serverShortName, sortKeysDeep };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var SEVERITY_RANK = { none: 0, low: 1, medium: 2, high: 3 };
|
|
3
|
+
|
|
4
|
+
// src/canonical.ts
|
|
5
|
+
function normalizeText(s) {
|
|
6
|
+
return s.replace(/\s+/g, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
function sortKeysDeep(value) {
|
|
9
|
+
if (Array.isArray(value)) return value.map(sortKeysDeep);
|
|
10
|
+
if (value && typeof value === "object") {
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const key of Object.keys(value).sort()) {
|
|
13
|
+
out[key] = sortKeysDeep(value[key]);
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function canonicalizeInterface(iface) {
|
|
20
|
+
const tools = iface.tools.map((t) => ({
|
|
21
|
+
name: t.name,
|
|
22
|
+
description: normalizeText(t.description ?? ""),
|
|
23
|
+
inputSchema: sortKeysDeep(t.inputSchema ?? {})
|
|
24
|
+
})).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
25
|
+
return { tools };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/hash.ts
|
|
29
|
+
import { createHash } from "crypto";
|
|
30
|
+
function interfaceHash(iface) {
|
|
31
|
+
const canonical = canonicalizeInterface(iface);
|
|
32
|
+
return createHash("sha256").update(JSON.stringify(canonical)).digest("hex");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/fingerprint.ts
|
|
36
|
+
function computeFingerprint(identity, iface, opts) {
|
|
37
|
+
return {
|
|
38
|
+
identity,
|
|
39
|
+
interface: canonicalizeInterface(iface),
|
|
40
|
+
interfaceHash: interfaceHash(iface),
|
|
41
|
+
artifactHash: opts.artifactHash ?? null,
|
|
42
|
+
capturedAt: opts.capturedAt
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/injection.ts
|
|
47
|
+
var PATTERNS = [
|
|
48
|
+
/ignore\s+(all\s+)?(previous|prior|above)\s+instructions/i,
|
|
49
|
+
/you\s+must\s+(first|always|never)/i,
|
|
50
|
+
/<\s*important\s*>/i,
|
|
51
|
+
/do\s+not\s+(tell|inform|mention|reveal)/i,
|
|
52
|
+
/system\s+prompt/i,
|
|
53
|
+
/\bexfiltrat/i,
|
|
54
|
+
/\b(ssh|api|secret|private)[-_ ]?key\b/i,
|
|
55
|
+
/\.env\b|id_rsa|~\/\.ssh/i,
|
|
56
|
+
/disregard\s+(the\s+)?(user|system)/i
|
|
57
|
+
];
|
|
58
|
+
function containsInjectionPattern(text) {
|
|
59
|
+
return PATTERNS.some((re) => re.test(text));
|
|
60
|
+
}
|
|
61
|
+
var injectionPatternCount = PATTERNS.length;
|
|
62
|
+
|
|
63
|
+
// src/diff.ts
|
|
64
|
+
function schemaProperties(schema) {
|
|
65
|
+
const props = schema.properties;
|
|
66
|
+
return props && typeof props === "object" ? Object.keys(props) : [];
|
|
67
|
+
}
|
|
68
|
+
function placeholderChange() {
|
|
69
|
+
return { kind: "description_changed", detail: "", category: "interface", severity: "none" };
|
|
70
|
+
}
|
|
71
|
+
function diffInterfaces(baseline, current) {
|
|
72
|
+
const base = canonicalizeInterface(baseline);
|
|
73
|
+
const next = canonicalizeInterface(current);
|
|
74
|
+
const baseByName = new Map(base.tools.map((t) => [t.name, t]));
|
|
75
|
+
const nextByName = new Map(next.tools.map((t) => [t.name, t]));
|
|
76
|
+
const changes = [];
|
|
77
|
+
for (const t of next.tools) {
|
|
78
|
+
if (!baseByName.has(t.name)) {
|
|
79
|
+
changes.push({ ...placeholderChange(), kind: "tool_added", tool: t.name, detail: `tool "${t.name}" added` });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const t of base.tools) {
|
|
83
|
+
if (!nextByName.has(t.name)) {
|
|
84
|
+
changes.push({ ...placeholderChange(), kind: "tool_removed", tool: t.name, detail: `tool "${t.name}" removed` });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const t of next.tools) {
|
|
88
|
+
const prev = baseByName.get(t.name);
|
|
89
|
+
if (!prev) continue;
|
|
90
|
+
if (normalizeText(prev.description) !== normalizeText(t.description)) {
|
|
91
|
+
changes.push({
|
|
92
|
+
...placeholderChange(),
|
|
93
|
+
kind: "description_changed",
|
|
94
|
+
tool: t.name,
|
|
95
|
+
detail: `description of "${t.name}" changed`
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const prevProps = new Set(schemaProperties(prev.inputSchema));
|
|
99
|
+
const nextPropsArr = schemaProperties(t.inputSchema);
|
|
100
|
+
const nextProps = new Set(nextPropsArr);
|
|
101
|
+
const added = nextPropsArr.filter((p) => !prevProps.has(p));
|
|
102
|
+
const removed = [...prevProps].filter((p) => !nextProps.has(p));
|
|
103
|
+
if (added.length > 0) {
|
|
104
|
+
changes.push({ ...placeholderChange(), kind: "schema_widened", tool: t.name, detail: `schema of "${t.name}" gained: ${added.join(", ")}` });
|
|
105
|
+
}
|
|
106
|
+
if (removed.length > 0) {
|
|
107
|
+
changes.push({ ...placeholderChange(), kind: "schema_changed", tool: t.name, detail: `schema of "${t.name}" removed: ${removed.join(", ")}` });
|
|
108
|
+
}
|
|
109
|
+
if (added.length === 0 && removed.length === 0 && JSON.stringify(prev.inputSchema) !== JSON.stringify(t.inputSchema)) {
|
|
110
|
+
changes.push({ ...placeholderChange(), kind: "schema_changed", tool: t.name, detail: `schema of "${t.name}" changed` });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return changes;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/drift.ts
|
|
117
|
+
function maxSeverity(severities) {
|
|
118
|
+
let max = "none";
|
|
119
|
+
for (const s of severities) if (SEVERITY_RANK[s] > SEVERITY_RANK[max]) max = s;
|
|
120
|
+
return max;
|
|
121
|
+
}
|
|
122
|
+
function classify(change, current) {
|
|
123
|
+
const tool = current.tools.find((t) => t.name === change.tool);
|
|
124
|
+
switch (change.kind) {
|
|
125
|
+
case "tool_added":
|
|
126
|
+
return { ...change, category: "interface", severity: "medium" };
|
|
127
|
+
case "tool_removed":
|
|
128
|
+
return { ...change, category: "interface", severity: "low" };
|
|
129
|
+
case "description_changed": {
|
|
130
|
+
const poisoned = tool ? containsInjectionPattern(tool.description) : false;
|
|
131
|
+
return poisoned ? { ...change, category: "semantic", severity: "high", detail: `${change.detail} (injection pattern detected)` } : { ...change, category: "interface", severity: "low" };
|
|
132
|
+
}
|
|
133
|
+
case "schema_widened":
|
|
134
|
+
return { ...change, category: "interface", severity: "medium" };
|
|
135
|
+
case "schema_changed":
|
|
136
|
+
return { ...change, category: "interface", severity: "low" };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function buildDriftReport(serverName, baseline, current) {
|
|
140
|
+
const canonicalCurrent = canonicalizeInterface(current);
|
|
141
|
+
const raw = diffInterfaces(baseline.interface, canonicalCurrent);
|
|
142
|
+
const changes = raw.map((c) => classify(c, canonicalCurrent));
|
|
143
|
+
return { serverName, changes, maxSeverity: maxSeverity(changes.map((c) => c.severity)) };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/typosquat.ts
|
|
147
|
+
var POPULAR_SERVERS = [
|
|
148
|
+
"github",
|
|
149
|
+
"gitlab",
|
|
150
|
+
"slack",
|
|
151
|
+
"filesystem",
|
|
152
|
+
"postgres",
|
|
153
|
+
"sqlite",
|
|
154
|
+
"google-drive",
|
|
155
|
+
"puppeteer",
|
|
156
|
+
"playwright",
|
|
157
|
+
"brave-search",
|
|
158
|
+
"fetch",
|
|
159
|
+
"memory",
|
|
160
|
+
"sentry",
|
|
161
|
+
"notion",
|
|
162
|
+
"stripe",
|
|
163
|
+
"supabase",
|
|
164
|
+
"aws",
|
|
165
|
+
"docker"
|
|
166
|
+
];
|
|
167
|
+
function levenshtein(a, b) {
|
|
168
|
+
const m = a.length;
|
|
169
|
+
const n = b.length;
|
|
170
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
171
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
172
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
173
|
+
for (let i = 1; i <= m; i++) {
|
|
174
|
+
for (let j = 1; j <= n; j++) {
|
|
175
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
176
|
+
dp[i][j] = Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return dp[m][n];
|
|
180
|
+
}
|
|
181
|
+
var MIN_NAME_LEN = 4;
|
|
182
|
+
var MAX_NAME_LEN = 64;
|
|
183
|
+
function isTyposquat(name, popular = POPULAR_SERVERS) {
|
|
184
|
+
const n = name.toLowerCase();
|
|
185
|
+
if (n.length < MIN_NAME_LEN || n.length > MAX_NAME_LEN) return false;
|
|
186
|
+
const popularLower = popular.map((p) => p.toLowerCase());
|
|
187
|
+
if (popularLower.includes(n)) return false;
|
|
188
|
+
for (const pl of popularLower) {
|
|
189
|
+
if (Math.abs(n.length - pl.length) > 2) continue;
|
|
190
|
+
const d = levenshtein(n, pl);
|
|
191
|
+
if (d > 0 && d <= 2) return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
function serverShortName(name) {
|
|
196
|
+
const slash = name.lastIndexOf("/");
|
|
197
|
+
return slash >= 0 ? name.slice(slash + 1) : name;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/artifact.ts
|
|
201
|
+
import { createHash as createHash2 } from "crypto";
|
|
202
|
+
function canonicalArtifact(input) {
|
|
203
|
+
return {
|
|
204
|
+
name: input.name,
|
|
205
|
+
version: input.version,
|
|
206
|
+
packages: [...input.packages].sort(
|
|
207
|
+
(a, b) => `${a.registryType} ${a.identifier} ${a.version}`.localeCompare(`${b.registryType} ${b.identifier} ${b.version}`)
|
|
208
|
+
),
|
|
209
|
+
maintainers: [...input.maintainers].sort(),
|
|
210
|
+
integrity: input.integrity,
|
|
211
|
+
hasInstallScript: input.hasInstallScript
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function computeArtifactFingerprint(input, opts) {
|
|
215
|
+
const canon = canonicalArtifact(input);
|
|
216
|
+
const artifactHash = createHash2("sha256").update(JSON.stringify(canon)).digest("hex");
|
|
217
|
+
return { ...canon, artifactHash, capturedAt: opts.capturedAt };
|
|
218
|
+
}
|
|
219
|
+
function diffArtifacts(baseline, current) {
|
|
220
|
+
const changes = [];
|
|
221
|
+
const baseMaint = new Set(baseline.maintainers);
|
|
222
|
+
const curMaint = new Set(current.maintainers);
|
|
223
|
+
const added = current.maintainers.filter((m) => !baseMaint.has(m));
|
|
224
|
+
const removed = baseline.maintainers.filter((m) => !curMaint.has(m));
|
|
225
|
+
if (added.length > 0 || removed.length > 0) {
|
|
226
|
+
changes.push({
|
|
227
|
+
kind: "maintainer_changed",
|
|
228
|
+
severity: "high",
|
|
229
|
+
detail: `maintainers changed${added.length ? ` (+${added.join(", ")})` : ""}${removed.length ? ` (-${removed.join(", ")})` : ""}`
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (baseline.version === current.version && baseline.integrity !== current.integrity) {
|
|
233
|
+
changes.push({
|
|
234
|
+
kind: "integrity_changed",
|
|
235
|
+
severity: "high",
|
|
236
|
+
detail: `package content changed without a version bump (integrity ${baseline.integrity} -> ${current.integrity})`
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (!baseline.hasInstallScript && current.hasInstallScript) {
|
|
240
|
+
changes.push({ kind: "install_script_added", severity: "medium", detail: "an install/postinstall script was added" });
|
|
241
|
+
}
|
|
242
|
+
const baseIds = new Set(baseline.packages.map((p) => p.identifier));
|
|
243
|
+
const curIds = new Set(current.packages.map((p) => p.identifier));
|
|
244
|
+
for (const p of current.packages) {
|
|
245
|
+
if (!baseIds.has(p.identifier)) {
|
|
246
|
+
changes.push({ kind: "package_added", severity: "medium", detail: `package added: ${p.identifier}` });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
for (const p of baseline.packages) {
|
|
250
|
+
if (!curIds.has(p.identifier)) {
|
|
251
|
+
changes.push({ kind: "package_removed", severity: "medium", detail: `package removed: ${p.identifier}` });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (baseline.version !== current.version) {
|
|
255
|
+
changes.push({ kind: "version_changed", severity: "low", detail: `version ${baseline.version} -> ${current.version}` });
|
|
256
|
+
}
|
|
257
|
+
return changes;
|
|
258
|
+
}
|
|
259
|
+
export {
|
|
260
|
+
POPULAR_SERVERS,
|
|
261
|
+
SEVERITY_RANK,
|
|
262
|
+
buildDriftReport,
|
|
263
|
+
canonicalizeInterface,
|
|
264
|
+
computeArtifactFingerprint,
|
|
265
|
+
computeFingerprint,
|
|
266
|
+
containsInjectionPattern,
|
|
267
|
+
diffArtifacts,
|
|
268
|
+
diffInterfaces,
|
|
269
|
+
injectionPatternCount,
|
|
270
|
+
interfaceHash,
|
|
271
|
+
isTyposquat,
|
|
272
|
+
levenshtein,
|
|
273
|
+
maxSeverity,
|
|
274
|
+
normalizeText,
|
|
275
|
+
serverShortName,
|
|
276
|
+
sortKeysDeep
|
|
277
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mintmark/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fingerprinting + drift/rug-pull detection engine for the MCP supply chain (Mintmark core).",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mcp",
|
|
22
|
+
"model-context-protocol",
|
|
23
|
+
"supply-chain",
|
|
24
|
+
"security",
|
|
25
|
+
"fingerprint",
|
|
26
|
+
"rug-pull",
|
|
27
|
+
"ai-agents"
|
|
28
|
+
],
|
|
29
|
+
"homepage": "https://mintmark.dev",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/nakshatra-nahar/Mintmark.git",
|
|
33
|
+
"directory": "packages/core"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/nakshatra-nahar/Mintmark/issues"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup"
|
|
46
|
+
}
|
|
47
|
+
}
|