Skip to content

Commit 7fccd0f

Browse files
authored
Merge branch 'main' into automated/open-api
2 parents c3a8e3e + 4b58003 commit 7fccd0f

5 files changed

Lines changed: 98 additions & 33 deletions

File tree

.config/esbuild.config.mjs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,56 @@ function createNodeProtocolPlugin() {
206206
}
207207
}
208208

209+
/**
210+
* Plugin to stub heavy @socketsecurity/lib internals and third-party modules
211+
* that are unreachable or safely degradable in the SDK's runtime code paths.
212+
*
213+
* @socketsecurity/lib stubs:
214+
*
215+
* npm-pack.js (2.5MB) — arborist, cacache, pacote, make-fetch-happen,
216+
* semver. Reached via sorts→semver (dead) and cache-with-ttl→cacache
217+
* (degrades gracefully: safeGet returns undefined, in-memory memoization
218+
* still works).
219+
*
220+
* pico-pack.js (260KB) — picomatch, fast-glob, del. Reached via
221+
* fs→globs for isDirEmptySync/readDirNames, never called by SDK.
222+
*
223+
* globs.js, sorts.js — gateway modules to pico-pack and npm-pack.
224+
*
225+
* Third-party stubs:
226+
*
227+
* mime-db (212KB) — Massive MIME type database bundled via form-data →
228+
* mime-types → mime-db. The SDK only uses 'application/octet-stream'
229+
* (file uploads) and 'application/json' (API calls). Replaced with a
230+
* minimal lookup covering just those types.
231+
*/
232+
function createLibStubPlugin() {
233+
const libStubPattern =
234+
/@socketsecurity\/lib\/dist\/(globs|sorts|external\/(npm-pack|pico-pack))\.js$/
235+
236+
const mimeDbPattern = /mime-db\/db\.json$/
237+
238+
return {
239+
name: 'stub-unused-internals',
240+
setup(build) {
241+
// Stub heavy lib modules with empty exports.
242+
build.onLoad({ filter: libStubPattern }, () => ({
243+
contents: 'module.exports = {}',
244+
loader: 'js',
245+
}))
246+
// Replace 212KB mime-db with minimal lookup for types the SDK uses.
247+
build.onLoad({ filter: mimeDbPattern }, () => ({
248+
contents: `module.exports = {
249+
"application/json": { source: "iana", charset: "UTF-8", compressible: true },
250+
"application/octet-stream": { source: "iana", compressible: false },
251+
"multipart/form-data": { source: "iana" }
252+
}`,
253+
loader: 'js',
254+
}))
255+
},
256+
}
257+
}
258+
209259
// Build configuration for ESM output
210260
export const buildConfig = {
211261
entryPoints: [`${srcPath}/index.ts`, `${srcPath}/testing.ts`],
@@ -226,9 +276,11 @@ export const buildConfig = {
226276
logLevel: 'info',
227277

228278
// Use plugins for module resolution and path handling.
229-
plugins: [createNodeProtocolPlugin(), createPathShorteningPlugin()].filter(
230-
Boolean,
231-
),
279+
plugins: [
280+
createLibStubPlugin(),
281+
createNodeProtocolPlugin(),
282+
createPathShorteningPlugin(),
283+
].filter(Boolean),
232284

233285
// External dependencies.
234286
// All runtime dependencies from package.json are external (not bundled) - consumers must install them.

.git-hooks/pre-push

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,36 +118,51 @@ while read local_ref local_sha remote_ref remote_sha; do
118118
continue
119119
fi
120120

121+
# Use strings for binary files, grep directly for text files.
122+
# This correctly extracts printable strings from WASM, .lockb, etc.
123+
is_binary=false
124+
if grep -qI '' "$file" 2>/dev/null; then
125+
is_binary=false
126+
else
127+
is_binary=true
128+
fi
129+
130+
if [ "$is_binary" = true ]; then
131+
file_text=$(strings "$file" 2>/dev/null || echo "")
132+
else
133+
file_text=$(cat "$file" 2>/dev/null || echo "")
134+
fi
135+
121136
# Check for hardcoded user paths.
122-
if grep -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" 2>/dev/null | grep -q .; then
137+
if echo "$file_text" | grep -qE '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)'; then
123138
printf "${RED}✗ BLOCKED: Hardcoded personal path found in: %s${NC}\n" "$file"
124-
grep -n -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" | head -3
139+
echo "$file_text" | grep -nE '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' | head -3
125140
ERRORS=$((ERRORS + 1))
126141
fi
127142

128143
# Check for Socket API keys.
129-
if grep -E 'sktsec_[a-zA-Z0-9_-]+' "$file" 2>/dev/null | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'SOCKET_SECURITY_API_KEY=' | grep -v 'fake-token' | grep -v 'test-token' | grep -q .; then
144+
if echo "$file_text" | grep -E 'sktsec_[a-zA-Z0-9_-]+' | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'SOCKET_SECURITY_API_KEY=' | grep -v 'fake-token' | grep -v 'test-token' | grep -q .; then
130145
printf "${RED}✗ BLOCKED: Real API key detected in: %s${NC}\n" "$file"
131-
grep -n 'sktsec_' "$file" | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | head -3
146+
echo "$file_text" | grep -n 'sktsec_' | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | head -3
132147
ERRORS=$((ERRORS + 1))
133148
fi
134149

135150
# Check for AWS keys.
136-
if grep -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" 2>/dev/null | grep -q .; then
151+
if echo "$file_text" | grep -iqE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})'; then
137152
printf "${RED}✗ BLOCKED: Potential AWS credentials found in: %s${NC}\n" "$file"
138-
grep -n -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" | head -3
153+
echo "$file_text" | grep -niE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' | head -3
139154
ERRORS=$((ERRORS + 1))
140155
fi
141156

142157
# Check for GitHub tokens.
143-
if grep -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" 2>/dev/null | grep -q .; then
158+
if echo "$file_text" | grep -qE 'gh[ps]_[a-zA-Z0-9]{36}'; then
144159
printf "${RED}✗ BLOCKED: Potential GitHub token found in: %s${NC}\n" "$file"
145-
grep -n -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" | head -3
160+
echo "$file_text" | grep -nE 'gh[ps]_[a-zA-Z0-9]{36}' | head -3
146161
ERRORS=$((ERRORS + 1))
147162
fi
148163

149164
# Check for private keys.
150-
if grep -E '-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----' "$file" 2>/dev/null | grep -q .; then
165+
if echo "$file_text" | grep -qE -- '-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----'; then
151166
printf "${RED}✗ BLOCKED: Private key found in: %s${NC}\n" "$file"
152167
ERRORS=$((ERRORS + 1))
153168
fi

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Dependencies: After `package.json` edits, run `pnpm install` to update `pnpm-lock.yaml`
2222
- Backward Compatibility: 🚨 FORBIDDEN to maintain - actively remove when encountered (see canonical CLAUDE.md)
2323
- 🚨 **NEVER use `npx`, `pnpm dlx`, or `yarn dlx`** — use `pnpm exec <package>` for devDep binaries, or `pnpm run <script>` for package.json scripts. If a tool is needed, add it as a pinned devDependency first.
24+
- **minimumReleaseAge**: NEVER add packages to `minimumReleaseAgeExclude` in CI. Locally, ASK before adding — the age threshold is a security control.
2425

2526
---
2627

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@
6464
"type": "tsgo --noEmit -p .config/tsconfig.check.json",
6565
"update": "node scripts/update.mjs"
6666
},
67-
"dependencies": {
68-
"@socketsecurity/lib": "5.15.0",
69-
"form-data": "4.0.5"
70-
},
7167
"devDependencies": {
7268
"@anthropic-ai/claude-code": "2.1.92",
69+
"@socketsecurity/lib": "5.18.2",
7370
"@babel/generator": "7.28.5",
7471
"@babel/parser": "7.26.3",
7572
"@babel/traverse": "7.26.4",
@@ -87,6 +84,7 @@
8784
"ecc-agentshield": "1.4.0",
8885
"esbuild": "0.25.11",
8986
"fast-glob": "3.3.3",
87+
"form-data": "4.0.5",
9088
"husky": "9.1.7",
9189
"magic-string": "0.30.14",
9290
"nock": "14.0.10",
@@ -120,7 +118,7 @@
120118
"unrs-resolver"
121119
],
122120
"overrides": {
123-
"defu": ">=6.1.6",
121+
"defu": ">=6.1.7",
124122
"vite": "7.3.2"
125123
}
126124
}

pnpm-lock.yaml

Lines changed: 15 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)