paper-search-cli 0.3.1 → 0.3.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.
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/dist/capabilities/body-snippet-search/handler.d.ts +9 -0
- package/dist/capabilities/body-snippet-search/handler.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/handler.js +17 -0
- package/dist/capabilities/body-snippet-search/handler.js.map +1 -0
- package/dist/capabilities/body-snippet-search/index.d.ts +7 -0
- package/dist/capabilities/body-snippet-search/index.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/index.js +6 -0
- package/dist/capabilities/body-snippet-search/index.js.map +1 -0
- package/dist/capabilities/body-snippet-search/schemas.d.ts +36 -0
- package/dist/capabilities/body-snippet-search/schemas.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/schemas.js +16 -0
- package/dist/capabilities/body-snippet-search/schemas.js.map +1 -0
- package/dist/capabilities/body-snippet-search/service.d.ts +4 -0
- package/dist/capabilities/body-snippet-search/service.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/service.js +4 -0
- package/dist/capabilities/body-snippet-search/service.js.map +1 -0
- package/dist/capabilities/body-snippet-search/tools.d.ts +187 -0
- package/dist/capabilities/body-snippet-search/tools.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/tools.js +49 -0
- package/dist/capabilities/body-snippet-search/tools.js.map +1 -0
- package/dist/capabilities/body-snippet-search/types.d.ts +14 -0
- package/dist/capabilities/body-snippet-search/types.d.ts.map +1 -0
- package/dist/capabilities/body-snippet-search/types.js +2 -0
- package/dist/capabilities/body-snippet-search/types.js.map +1 -0
- package/dist/capabilities/citation-expansion/CitationService.d.ts +47 -0
- package/dist/capabilities/citation-expansion/CitationService.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/CitationService.js +243 -0
- package/dist/capabilities/citation-expansion/CitationService.js.map +1 -0
- package/dist/capabilities/citation-expansion/handler.d.ts +36 -0
- package/dist/capabilities/citation-expansion/handler.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/handler.js +44 -0
- package/dist/capabilities/citation-expansion/handler.js.map +1 -0
- package/dist/capabilities/citation-expansion/index.d.ts +6 -0
- package/dist/capabilities/citation-expansion/index.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/index.js +5 -0
- package/dist/capabilities/citation-expansion/index.js.map +1 -0
- package/dist/capabilities/citation-expansion/schemas.d.ts +28 -0
- package/dist/capabilities/citation-expansion/schemas.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/schemas.js +13 -0
- package/dist/capabilities/citation-expansion/schemas.js.map +1 -0
- package/dist/capabilities/citation-expansion/tools.d.ts +82 -0
- package/dist/capabilities/citation-expansion/tools.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/tools.js +48 -0
- package/dist/capabilities/citation-expansion/tools.js.map +1 -0
- package/dist/capabilities/citation-expansion/types.d.ts +22 -0
- package/dist/capabilities/citation-expansion/types.d.ts.map +1 -0
- package/dist/capabilities/citation-expansion/types.js +2 -0
- package/dist/capabilities/citation-expansion/types.js.map +1 -0
- package/dist/capabilities/journal-metrics/JournalMetricsService.d.ts +3 -0
- package/dist/capabilities/journal-metrics/JournalMetricsService.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/JournalMetricsService.js +142 -0
- package/dist/capabilities/journal-metrics/JournalMetricsService.js.map +1 -0
- package/dist/capabilities/journal-metrics/handler.d.ts +12 -0
- package/dist/capabilities/journal-metrics/handler.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/handler.js +38 -0
- package/dist/capabilities/journal-metrics/handler.js.map +1 -0
- package/dist/capabilities/journal-metrics/index.d.ts +6 -0
- package/dist/capabilities/journal-metrics/index.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/index.js +5 -0
- package/dist/capabilities/journal-metrics/index.js.map +1 -0
- package/dist/capabilities/journal-metrics/schemas.d.ts +28 -0
- package/dist/capabilities/journal-metrics/schemas.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/schemas.js +13 -0
- package/dist/capabilities/journal-metrics/schemas.js.map +1 -0
- package/dist/capabilities/journal-metrics/tools.d.ts +67 -0
- package/dist/capabilities/journal-metrics/tools.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/tools.js +27 -0
- package/dist/capabilities/journal-metrics/tools.js.map +1 -0
- package/dist/capabilities/journal-metrics/types.d.ts +36 -0
- package/dist/capabilities/journal-metrics/types.d.ts.map +1 -0
- package/dist/capabilities/journal-metrics/types.js +2 -0
- package/dist/capabilities/journal-metrics/types.js.map +1 -0
- package/dist/capabilities/metadata-search/MultiSourceSearchService.d.ts +9 -0
- package/dist/capabilities/metadata-search/MultiSourceSearchService.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/MultiSourceSearchService.js +78 -0
- package/dist/capabilities/metadata-search/MultiSourceSearchService.js.map +1 -0
- package/dist/capabilities/metadata-search/handler.d.ts +23 -0
- package/dist/capabilities/metadata-search/handler.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/handler.js +163 -0
- package/dist/capabilities/metadata-search/handler.js.map +1 -0
- package/dist/capabilities/metadata-search/index.d.ts +6 -0
- package/dist/capabilities/metadata-search/index.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/index.js +5 -0
- package/dist/capabilities/metadata-search/index.js.map +1 -0
- package/dist/capabilities/metadata-search/schemas.d.ts +83 -0
- package/dist/capabilities/metadata-search/schemas.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/schemas.js +81 -0
- package/dist/capabilities/metadata-search/schemas.js.map +1 -0
- package/dist/capabilities/metadata-search/tools.d.ts +178 -0
- package/dist/capabilities/metadata-search/tools.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/tools.js +75 -0
- package/dist/capabilities/metadata-search/tools.js.map +1 -0
- package/dist/capabilities/metadata-search/types.d.ts +13 -0
- package/dist/capabilities/metadata-search/types.d.ts.map +1 -0
- package/dist/capabilities/metadata-search/types.js +2 -0
- package/dist/capabilities/metadata-search/types.js.map +1 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.d.ts +22 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.js +2 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.js.map +1 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts +10 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js +53 -0
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +1 -0
- package/dist/capabilities/pdf-discovery/handler.d.ts +19 -0
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/handler.js +56 -0
- package/dist/capabilities/pdf-discovery/handler.js.map +1 -0
- package/dist/capabilities/pdf-discovery/index.d.ts +7 -0
- package/dist/capabilities/pdf-discovery/index.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/index.js +5 -0
- package/dist/capabilities/pdf-discovery/index.js.map +1 -0
- package/dist/capabilities/pdf-discovery/schemas.d.ts +37 -0
- package/dist/capabilities/pdf-discovery/schemas.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/schemas.js +22 -0
- package/dist/capabilities/pdf-discovery/schemas.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.js +27 -0
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/primary.js +21 -0
- package/dist/capabilities/pdf-discovery/tiers/primary.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/repositories.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/tiers/repositories.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/repositories.js +35 -0
- package/dist/capabilities/pdf-discovery/tiers/repositories.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/scihub.js +21 -0
- package/dist/capabilities/pdf-discovery/tiers/scihub.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts +3 -0
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.js +29 -0
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.js.map +1 -0
- package/dist/capabilities/pdf-discovery/tools.d.ts +114 -0
- package/dist/capabilities/pdf-discovery/tools.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/tools.js +42 -0
- package/dist/capabilities/pdf-discovery/tools.js.map +1 -0
- package/dist/capabilities/pdf-discovery/types.d.ts +19 -0
- package/dist/capabilities/pdf-discovery/types.d.ts.map +1 -0
- package/dist/capabilities/pdf-discovery/types.js +2 -0
- package/dist/capabilities/pdf-discovery/types.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/cli.js.map +1 -1
- package/dist/core/capabilityProfile.d.ts +1 -17
- package/dist/core/capabilityProfile.d.ts.map +1 -1
- package/dist/core/capabilityProfile.js +1 -166
- package/dist/core/capabilityProfile.js.map +1 -1
- package/dist/core/diagnostics.d.ts +1 -42
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js +1 -585
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/handleToolCall.d.ts +1 -0
- package/dist/core/handleToolCall.d.ts.map +1 -1
- package/dist/core/handleToolCall.js +265 -509
- package/dist/core/handleToolCall.js.map +1 -1
- package/dist/core/httpPolicies.d.ts +2 -0
- package/dist/core/httpPolicies.d.ts.map +1 -0
- package/dist/core/httpPolicies.js +2 -0
- package/dist/core/httpPolicies.js.map +1 -0
- package/dist/core/liveSmoke.d.ts +1 -41
- package/dist/core/liveSmoke.d.ts.map +1 -1
- package/dist/core/liveSmoke.js +1 -225
- package/dist/core/liveSmoke.js.map +1 -1
- package/dist/core/platformFactories.d.ts +2 -0
- package/dist/core/platformFactories.d.ts.map +1 -0
- package/dist/core/platformFactories.js +2 -0
- package/dist/core/platformFactories.js.map +1 -0
- package/dist/core/platformMetadata.d.ts +1 -27
- package/dist/core/platformMetadata.d.ts.map +1 -1
- package/dist/core/platformMetadata.js +1 -257
- package/dist/core/platformMetadata.js.map +1 -1
- package/dist/core/schemas.d.ts +10 -202
- package/dist/core/schemas.d.ts.map +1 -1
- package/dist/core/schemas.js +11 -118
- package/dist/core/schemas.js.map +1 -1
- package/dist/core/searchers.d.ts +24 -24
- package/dist/core/searchers.d.ts.map +1 -1
- package/dist/core/searchers.js +14 -79
- package/dist/core/searchers.js.map +1 -1
- package/dist/core/textReports.d.ts +1 -20
- package/dist/core/textReports.d.ts.map +1 -1
- package/dist/core/textReports.js +1 -84
- package/dist/core/textReports.js.map +1 -1
- package/dist/core/tools.d.ts.map +1 -1
- package/dist/core/tools.js +15 -237
- package/dist/core/tools.js.map +1 -1
- package/dist/infrastructure/cache/RequestCache.d.ts +26 -0
- package/dist/infrastructure/cache/RequestCache.d.ts.map +1 -0
- package/dist/infrastructure/cache/RequestCache.js +66 -0
- package/dist/infrastructure/cache/RequestCache.js.map +1 -0
- package/dist/infrastructure/http/ErrorHandler.d.ts +99 -0
- package/dist/infrastructure/http/ErrorHandler.d.ts.map +1 -0
- package/dist/infrastructure/http/ErrorHandler.js +266 -0
- package/dist/infrastructure/http/ErrorHandler.js.map +1 -0
- package/dist/infrastructure/http/HttpClient.d.ts +31 -0
- package/dist/infrastructure/http/HttpClient.d.ts.map +1 -0
- package/dist/infrastructure/http/HttpClient.js +50 -0
- package/dist/infrastructure/http/HttpClient.js.map +1 -0
- package/dist/infrastructure/pdf/PDFExtractor.d.ts +34 -0
- package/dist/infrastructure/pdf/PDFExtractor.d.ts.map +1 -0
- package/dist/infrastructure/pdf/PDFExtractor.js +130 -0
- package/dist/infrastructure/pdf/PDFExtractor.js.map +1 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts +7 -0
- package/dist/infrastructure/pdf/PdfDownload.d.ts.map +1 -0
- package/dist/infrastructure/pdf/PdfDownload.js +175 -0
- package/dist/infrastructure/pdf/PdfDownload.js.map +1 -0
- package/dist/infrastructure/rate-limit/RateLimiter.d.ts +50 -0
- package/dist/infrastructure/rate-limit/RateLimiter.d.ts.map +1 -0
- package/dist/infrastructure/rate-limit/RateLimiter.js +128 -0
- package/dist/infrastructure/rate-limit/RateLimiter.js.map +1 -0
- package/dist/infrastructure/security/SecurityUtils.d.ts +80 -0
- package/dist/infrastructure/security/SecurityUtils.d.ts.map +1 -0
- package/dist/infrastructure/security/SecurityUtils.js +357 -0
- package/dist/infrastructure/security/SecurityUtils.js.map +1 -0
- package/dist/management/capability-profile/index.d.ts +18 -0
- package/dist/management/capability-profile/index.d.ts.map +1 -0
- package/dist/management/capability-profile/index.js +167 -0
- package/dist/management/capability-profile/index.js.map +1 -0
- package/dist/management/config/index.d.ts +2 -0
- package/dist/management/config/index.d.ts.map +1 -0
- package/dist/management/config/index.js +2 -0
- package/dist/management/config/index.js.map +1 -0
- package/dist/management/diagnostics/index.d.ts +43 -0
- package/dist/management/diagnostics/index.d.ts.map +1 -0
- package/dist/management/diagnostics/index.js +586 -0
- package/dist/management/diagnostics/index.js.map +1 -0
- package/dist/management/reports/index.d.ts +21 -0
- package/dist/management/reports/index.d.ts.map +1 -0
- package/dist/management/reports/index.js +85 -0
- package/dist/management/reports/index.js.map +1 -0
- package/dist/management/skills/index.d.ts +2 -0
- package/dist/management/skills/index.d.ts.map +1 -0
- package/dist/management/skills/index.js +2 -0
- package/dist/management/skills/index.js.map +1 -0
- package/dist/management/smoke/index.d.ts +42 -0
- package/dist/management/smoke/index.d.ts.map +1 -0
- package/dist/management/smoke/index.js +226 -0
- package/dist/management/smoke/index.js.map +1 -0
- package/dist/registry/aliases.d.ts +2 -0
- package/dist/registry/aliases.d.ts.map +1 -0
- package/dist/registry/aliases.js +2 -0
- package/dist/registry/aliases.js.map +1 -0
- package/dist/registry/httpPolicies.d.ts +3 -0
- package/dist/registry/httpPolicies.d.ts.map +1 -0
- package/dist/registry/httpPolicies.js +17 -0
- package/dist/registry/httpPolicies.js.map +1 -0
- package/dist/registry/platformFactories.d.ts +8 -0
- package/dist/registry/platformFactories.d.ts.map +1 -0
- package/dist/registry/platformFactories.js +55 -0
- package/dist/registry/platformFactories.js.map +1 -0
- package/dist/registry/platformMetadata.d.ts +39 -0
- package/dist/registry/platformMetadata.d.ts.map +1 -0
- package/dist/registry/platformMetadata.js +321 -0
- package/dist/registry/platformMetadata.js.map +1 -0
- package/dist/services/CitationService.d.ts +2 -65
- package/dist/services/CitationService.d.ts.map +1 -1
- package/dist/services/CitationService.js +1 -242
- package/dist/services/CitationService.js.map +1 -1
- package/dist/services/JournalMetricsService.d.ts +2 -37
- package/dist/services/JournalMetricsService.d.ts.map +1 -1
- package/dist/services/JournalMetricsService.js +1 -141
- package/dist/services/JournalMetricsService.js.map +1 -1
- package/dist/services/MultiSourceSearchService.d.ts +2 -18
- package/dist/services/MultiSourceSearchService.d.ts.map +1 -1
- package/dist/services/MultiSourceSearchService.js +1 -77
- package/dist/services/MultiSourceSearchService.js.map +1 -1
- package/dist/services/OpenAccessFallbackService.d.ts +3 -40
- package/dist/services/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/services/OpenAccessFallbackService.js +1 -146
- package/dist/services/OpenAccessFallbackService.js.map +1 -1
- package/dist/utils/ErrorHandler.d.ts +2 -98
- package/dist/utils/ErrorHandler.d.ts.map +1 -1
- package/dist/utils/ErrorHandler.js +2 -265
- package/dist/utils/ErrorHandler.js.map +1 -1
- package/dist/utils/HttpClient.d.ts +1 -5
- package/dist/utils/HttpClient.d.ts.map +1 -1
- package/dist/utils/HttpClient.js +1 -29
- package/dist/utils/HttpClient.js.map +1 -1
- package/dist/utils/PDFExtractor.d.ts +2 -33
- package/dist/utils/PDFExtractor.d.ts.map +1 -1
- package/dist/utils/PDFExtractor.js +2 -129
- package/dist/utils/PDFExtractor.js.map +1 -1
- package/dist/utils/PdfDownload.d.ts +1 -6
- package/dist/utils/PdfDownload.d.ts.map +1 -1
- package/dist/utils/PdfDownload.js +1 -141
- package/dist/utils/PdfDownload.js.map +1 -1
- package/dist/utils/RateLimiter.d.ts +1 -49
- package/dist/utils/RateLimiter.d.ts.map +1 -1
- package/dist/utils/RateLimiter.js +1 -127
- package/dist/utils/RateLimiter.js.map +1 -1
- package/dist/utils/RequestCache.d.ts +2 -25
- package/dist/utils/RequestCache.d.ts.map +1 -1
- package/dist/utils/RequestCache.js +2 -65
- package/dist/utils/RequestCache.js.map +1 -1
- package/dist/utils/SecurityUtils.d.ts +2 -79
- package/dist/utils/SecurityUtils.d.ts.map +1 -1
- package/dist/utils/SecurityUtils.js +2 -356
- package/dist/utils/SecurityUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,357 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Provides comprehensive protection against security vulnerabilities
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Comprehensive request sanitization to remove sensitive data
|
|
7
|
-
* @param config - Axios request configuration
|
|
8
|
-
* @returns Sanitized configuration copy
|
|
9
|
-
*/
|
|
10
|
-
export function sanitizeRequest(config) {
|
|
11
|
-
if (!config)
|
|
12
|
-
return config;
|
|
13
|
-
// Deep clone to avoid mutating original
|
|
14
|
-
let sanitized;
|
|
15
|
-
try {
|
|
16
|
-
sanitized = JSON.parse(JSON.stringify(config));
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
// If JSON serialization fails, return redacted version
|
|
20
|
-
return { __redacted: 'Failed to sanitize - potentially circular reference' };
|
|
21
|
-
}
|
|
22
|
-
// Sanitize headers
|
|
23
|
-
if (sanitized.headers) {
|
|
24
|
-
sanitized.headers = sanitizeHeaders(sanitized.headers);
|
|
25
|
-
}
|
|
26
|
-
// Sanitize URL parameters
|
|
27
|
-
if (sanitized.params) {
|
|
28
|
-
sanitized.params = sanitizeParams(sanitized.params);
|
|
29
|
-
}
|
|
30
|
-
// Sanitize request body
|
|
31
|
-
if (sanitized.data) {
|
|
32
|
-
sanitized.data = sanitizeBody(sanitized.data);
|
|
33
|
-
}
|
|
34
|
-
// Sanitize URL
|
|
35
|
-
if (sanitized.url) {
|
|
36
|
-
sanitized.url = sanitizeUrl(sanitized.url);
|
|
37
|
-
}
|
|
38
|
-
return sanitized;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Sanitize headers to remove sensitive information
|
|
42
|
-
*/
|
|
43
|
-
export function sanitizeHeaders(headers) {
|
|
44
|
-
if (!headers)
|
|
45
|
-
return headers;
|
|
46
|
-
const sanitized = { ...headers };
|
|
47
|
-
// Patterns for sensitive headers (case-insensitive)
|
|
48
|
-
const sensitivePatterns = [
|
|
49
|
-
/^api[-_]?key$/i,
|
|
50
|
-
/^x[-_]api[-_]key$/i,
|
|
51
|
-
/^authorization$/i,
|
|
52
|
-
/^x[-_]apikey$/i,
|
|
53
|
-
/^access[-_]token$/i,
|
|
54
|
-
/^bearer$/i,
|
|
55
|
-
/^x[-_]auth[-_]token$/i,
|
|
56
|
-
/^cookie$/i,
|
|
57
|
-
/^set[-_]cookie$/i,
|
|
58
|
-
/^x[-_]csrf[-_]token$/i,
|
|
59
|
-
/^x[-_]forwarded[-_]for$/i, // May contain IP
|
|
60
|
-
/^referer$/i, // May contain sensitive URLs
|
|
61
|
-
/^user[-_]agent$/i // May contain system info
|
|
62
|
-
];
|
|
63
|
-
Object.keys(sanitized).forEach(key => {
|
|
64
|
-
const lowerKey = key.toLowerCase();
|
|
65
|
-
// Check against patterns
|
|
66
|
-
if (sensitivePatterns.some(pattern => pattern.test(key))) {
|
|
67
|
-
sanitized[key] = '***REDACTED***';
|
|
68
|
-
}
|
|
69
|
-
// Also check values that might contain tokens
|
|
70
|
-
if (typeof sanitized[key] === 'string') {
|
|
71
|
-
if (sanitized[key].match(/^(Bearer|Basic)\s+/i) ||
|
|
72
|
-
sanitized[key].match(/^[a-zA-Z0-9_-]{20,}$/) || // Likely token
|
|
73
|
-
sanitized[key].includes('session=') ||
|
|
74
|
-
sanitized[key].includes('token=')) {
|
|
75
|
-
sanitized[key] = '***REDACTED***';
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return sanitized;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Sanitize URL parameters
|
|
83
|
-
*/
|
|
84
|
-
export function sanitizeParams(params) {
|
|
85
|
-
if (!params)
|
|
86
|
-
return params;
|
|
87
|
-
const sanitized = { ...params };
|
|
88
|
-
Object.keys(sanitized).forEach(key => {
|
|
89
|
-
const lowerKey = key.toLowerCase();
|
|
90
|
-
// Check for common sensitive parameter names
|
|
91
|
-
if (lowerKey.includes('api_key') ||
|
|
92
|
-
lowerKey.includes('apikey') ||
|
|
93
|
-
lowerKey.includes('token') ||
|
|
94
|
-
lowerKey.includes('secret') ||
|
|
95
|
-
lowerKey.includes('password') ||
|
|
96
|
-
lowerKey.includes('private') ||
|
|
97
|
-
lowerKey.includes('auth')) {
|
|
98
|
-
sanitized[key] = '***REDACTED***';
|
|
99
|
-
}
|
|
100
|
-
// Mask values that look like tokens
|
|
101
|
-
if (typeof sanitized[key] === 'string' &&
|
|
102
|
-
sanitized[key].match(/^[a-zA-Z0-9_-]{16,}$/)) {
|
|
103
|
-
sanitized[key] = sanitized[key].substring(0, 4) + '***';
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
return sanitized;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Sanitize request body
|
|
110
|
-
*/
|
|
111
|
-
export function sanitizeBody(body) {
|
|
112
|
-
if (!body)
|
|
113
|
-
return body;
|
|
114
|
-
// For objects, recursively sanitize
|
|
115
|
-
if (typeof body === 'object' && body !== null) {
|
|
116
|
-
// Handle arrays
|
|
117
|
-
if (Array.isArray(body)) {
|
|
118
|
-
return body.map(item => sanitizeBody(item));
|
|
119
|
-
}
|
|
120
|
-
// Handle objects
|
|
121
|
-
const sanitized = {};
|
|
122
|
-
for (const [key, value] of Object.entries(body)) {
|
|
123
|
-
const lowerKey = key.toLowerCase();
|
|
124
|
-
// Check for sensitive keys
|
|
125
|
-
if (lowerKey.includes('password') ||
|
|
126
|
-
lowerKey.includes('secret') ||
|
|
127
|
-
lowerKey.includes('token') ||
|
|
128
|
-
lowerKey.includes('api_key') ||
|
|
129
|
-
lowerKey.includes('private')) {
|
|
130
|
-
sanitized[key] = '***REDACTED***';
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
sanitized[key] = sanitizeBody(value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return sanitized;
|
|
137
|
-
}
|
|
138
|
-
// For strings, check if it looks like a token
|
|
139
|
-
if (typeof body === 'string') {
|
|
140
|
-
if (body.match(/^(Bearer|Basic)\s+/i)) {
|
|
141
|
-
return body.replace(/\s+\S+/, ' ***REDACTED***');
|
|
142
|
-
}
|
|
143
|
-
if (body.match(/^[a-zA-Z0-9_-]{32,}$/)) {
|
|
144
|
-
return body.substring(0, 8) + '***';
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return body;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Sanitize URL to remove sensitive query parameters
|
|
151
|
-
*/
|
|
152
|
-
export function sanitizeUrl(url) {
|
|
153
|
-
if (!url)
|
|
154
|
-
return url;
|
|
155
|
-
try {
|
|
156
|
-
const urlObj = new URL(url);
|
|
157
|
-
// Remove sensitive query parameters
|
|
158
|
-
const sensitiveParams = ['api_key', 'apikey', 'token', 'secret', 'auth'];
|
|
159
|
-
let hasSensitiveParams = false;
|
|
160
|
-
sensitiveParams.forEach(param => {
|
|
161
|
-
if (urlObj.searchParams.has(param)) {
|
|
162
|
-
urlObj.searchParams.set(param, '***REDACTED***');
|
|
163
|
-
hasSensitiveParams = true;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
// If we modified parameters, add indicator
|
|
167
|
-
if (hasSensitiveParams) {
|
|
168
|
-
return urlObj.toString() + '#sanitized';
|
|
169
|
-
}
|
|
170
|
-
return url;
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
// If URL parsing fails, mask the entire URL
|
|
174
|
-
return '***REDACTED_URL***';
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Validate and sanitize a DOI string
|
|
179
|
-
*/
|
|
180
|
-
export function sanitizeDoi(doi) {
|
|
181
|
-
if (!doi || typeof doi !== 'string') {
|
|
182
|
-
return { valid: false, sanitized: '', error: 'DOI must be a non-empty string' };
|
|
183
|
-
}
|
|
184
|
-
// Remove whitespace and common prefixes
|
|
185
|
-
let sanitized = doi.trim();
|
|
186
|
-
// Remove common DOI URL prefixes
|
|
187
|
-
const prefixes = [
|
|
188
|
-
'https://doi.org/',
|
|
189
|
-
'http://doi.org/',
|
|
190
|
-
'https://dx.doi.org/',
|
|
191
|
-
'http://dx.doi.org/',
|
|
192
|
-
'doi:',
|
|
193
|
-
'DOI:'
|
|
194
|
-
];
|
|
195
|
-
for (const prefix of prefixes) {
|
|
196
|
-
if (sanitized.toLowerCase().startsWith(prefix.toLowerCase())) {
|
|
197
|
-
sanitized = sanitized.substring(prefix.length);
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
// Basic DOI format validation
|
|
202
|
-
// DOI should start with "10." followed by digits and then any characters
|
|
203
|
-
const doiPattern = /^10\.\d{4,}(\.\d+)*\/\S+$/;
|
|
204
|
-
if (!doiPattern.test(sanitized)) {
|
|
205
|
-
return { valid: false, sanitized: '', error: 'Invalid DOI format' };
|
|
206
|
-
}
|
|
207
|
-
// Additional safety checks
|
|
208
|
-
if (sanitized.length > 256) {
|
|
209
|
-
return { valid: false, sanitized: '', error: 'DOI too long (max 256 characters)' };
|
|
210
|
-
}
|
|
211
|
-
// Check for suspicious patterns
|
|
212
|
-
if (sanitized.includes('<') || sanitized.includes('>') ||
|
|
213
|
-
sanitized.includes('"') || sanitized.includes("'")) {
|
|
214
|
-
return { valid: false, sanitized: '', error: 'DOI contains invalid characters' };
|
|
215
|
-
}
|
|
216
|
-
return { valid: true, sanitized: sanitized };
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Escape query value for different contexts
|
|
220
|
-
*/
|
|
221
|
-
export function escapeQueryValue(value, context = 'general') {
|
|
222
|
-
if (!value)
|
|
223
|
-
return '';
|
|
224
|
-
// Remove null bytes and control characters
|
|
225
|
-
let escaped = value.replace(/[\x00-\x1F\x7F]/g, '');
|
|
226
|
-
switch (context) {
|
|
227
|
-
case 'springer':
|
|
228
|
-
escaped = escaped
|
|
229
|
-
.replace(/"/g, '\\"') // Escape quotes
|
|
230
|
-
.replace(/[()]/g, '') // Remove parentheses
|
|
231
|
-
.replace(/;/g, '') // Remove semicolons
|
|
232
|
-
.replace(/\/\*/g, '') // Remove SQL comment start
|
|
233
|
-
.replace(/\*\//g, ''); // Remove SQL comment end
|
|
234
|
-
break;
|
|
235
|
-
case 'wos':
|
|
236
|
-
// For WoS, only remove quotes and parentheses if not user-provided field query
|
|
237
|
-
if (!escaped.includes('TS=') && !escaped.includes('TI=') &&
|
|
238
|
-
!escaped.includes('AU=') && !escaped.includes('SO=')) {
|
|
239
|
-
escaped = escaped
|
|
240
|
-
.replace(/"/g, '') // Remove quotes
|
|
241
|
-
.replace(/[()]/g, '') // Remove parentheses
|
|
242
|
-
.trim();
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
default:
|
|
246
|
-
escaped = escaped
|
|
247
|
-
.replace(/["<>]/g, '') // Remove quotes and angle brackets
|
|
248
|
-
.replace(/\/\/+/g, '') // Remove multiple slashes
|
|
249
|
-
.trim();
|
|
250
|
-
}
|
|
251
|
-
// Length limit to prevent DoS
|
|
252
|
-
if (escaped.length > 200) {
|
|
253
|
-
escaped = escaped.substring(0, 200);
|
|
254
|
-
}
|
|
255
|
-
return escaped.trim();
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Validate query complexity to prevent DoS
|
|
259
|
-
*/
|
|
260
|
-
export function validateQueryComplexity(query, options = {}) {
|
|
261
|
-
const maxLength = options.maxLength || 1000;
|
|
262
|
-
const maxBooleanOperators = options.maxBooleanOperators || 10;
|
|
263
|
-
if (!query)
|
|
264
|
-
return { valid: true };
|
|
265
|
-
// Check length
|
|
266
|
-
if (query.length > maxLength) {
|
|
267
|
-
return {
|
|
268
|
-
valid: false,
|
|
269
|
-
error: `Query too long (max ${maxLength} characters)`
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
// Count boolean operators
|
|
273
|
-
const booleanOperators = query.match(/\b(AND|OR|NOT)\b/gi) || [];
|
|
274
|
-
if (booleanOperators.length > maxBooleanOperators) {
|
|
275
|
-
return {
|
|
276
|
-
valid: false,
|
|
277
|
-
error: `Query too complex (max ${maxBooleanOperators} boolean operators)`
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
// Check for potential injection patterns
|
|
281
|
-
const injectionPatterns = [
|
|
282
|
-
/;\s*(drop|delete|update|insert|exec|union)/i,
|
|
283
|
-
/\/\*.*\*\//s, // SQL comments
|
|
284
|
-
/\/\/.*/, // Line comments
|
|
285
|
-
/\b(select|insert|update|delete|drop|create|alter|exec|execute|union)\b.*\b(from|where|and|or)\b/i,
|
|
286
|
-
/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/ // Control characters
|
|
287
|
-
];
|
|
288
|
-
for (const pattern of injectionPatterns) {
|
|
289
|
-
if (pattern.test(query)) {
|
|
290
|
-
return {
|
|
291
|
-
valid: false,
|
|
292
|
-
error: 'Query contains potentially dangerous patterns'
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return { valid: true };
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Create a timeout wrapper for promises
|
|
300
|
-
*/
|
|
301
|
-
export function withTimeout(promise, ms, message) {
|
|
302
|
-
let timer;
|
|
303
|
-
const timeout = new Promise((_, reject) => {
|
|
304
|
-
timer = setTimeout(() => {
|
|
305
|
-
reject(new Error(message || `Operation timed out after ${ms}ms`));
|
|
306
|
-
}, ms);
|
|
307
|
-
});
|
|
308
|
-
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Generate a correlation ID for request tracking
|
|
312
|
-
*/
|
|
313
|
-
export function generateCorrelationId() {
|
|
314
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Mask sensitive data in strings
|
|
318
|
-
*/
|
|
319
|
-
export function maskSensitiveData(str) {
|
|
320
|
-
if (!str || str.length < 8)
|
|
321
|
-
return '***';
|
|
322
|
-
const visibleChars = Math.min(4, Math.floor(str.length / 4));
|
|
323
|
-
return str.substring(0, visibleChars) +
|
|
324
|
-
'*'.repeat(str.length - visibleChars * 2) +
|
|
325
|
-
str.substring(str.length - visibleChars);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Check if a string looks like an API key or token
|
|
329
|
-
*/
|
|
330
|
-
export function looksLikeToken(str) {
|
|
331
|
-
if (!str || typeof str !== 'string')
|
|
332
|
-
return false;
|
|
333
|
-
// Common token patterns
|
|
334
|
-
const tokenPatterns = [
|
|
335
|
-
/^[a-zA-Z0-9_-]{20,}$/, // Long alphanumeric
|
|
336
|
-
/^Bearer\s+[a-zA-Z0-9_-]+$/, // Bearer token
|
|
337
|
-
/^Basic\s+[A-Za-z0-9+/=]+$/, // Basic auth
|
|
338
|
-
/^[0-9a-f]{32,}$/i, // Hex token
|
|
339
|
-
/^[A-Za-z0-9+/]{20,}={0,2}$/ // Base64-like
|
|
340
|
-
];
|
|
341
|
-
return tokenPatterns.some(pattern => pattern.test(str));
|
|
342
|
-
}
|
|
343
|
-
export default {
|
|
344
|
-
sanitizeRequest,
|
|
345
|
-
sanitizeHeaders,
|
|
346
|
-
sanitizeParams,
|
|
347
|
-
sanitizeBody,
|
|
348
|
-
sanitizeUrl,
|
|
349
|
-
sanitizeDoi,
|
|
350
|
-
escapeQueryValue,
|
|
351
|
-
validateQueryComplexity,
|
|
352
|
-
withTimeout,
|
|
353
|
-
generateCorrelationId,
|
|
354
|
-
maskSensitiveData,
|
|
355
|
-
looksLikeToken
|
|
356
|
-
};
|
|
1
|
+
export * from '../infrastructure/security/SecurityUtils.js';
|
|
2
|
+
export { default } from '../infrastructure/security/SecurityUtils.js';
|
|
357
3
|
//# sourceMappingURL=SecurityUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityUtils.js","sourceRoot":"","sources":["../../src/utils/SecurityUtils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"SecurityUtils.js","sourceRoot":"","sources":["../../src/utils/SecurityUtils.ts"],"names":[],"mappings":"AAAA,cAAc,6CAA6C,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,6CAA6C,CAAC"}
|