MCPcopy
hub / github.com/lissy93/web-check / securityTxtHandler

Function securityTxtHandler

api/security-txt.js:39–67  ·  view source on GitHub ↗
(urlParam)

Source from the content-addressed store, hash-verified

37};
38
39const securityTxtHandler = async (urlParam) => {
40 let url;
41 try {
42 url = new URL(urlParam.includes('://') ? urlParam : 'https://' + urlParam);
43 } catch (error) {
44 throw new Error('Invalid URL format');
45 }
46 url.pathname = '';
47
48 for (let path of SECURITY_TXT_PATHS) {
49 try {
50 const result = await fetchSecurityTxt(url, path);
51 if (result && result.toLowerCase().includes('<html')) continue;
52 if (result) {
53 return {
54 isPresent: true,
55 foundIn: path,
56 content: result,
57 isPgpSigned: isPgpSigned(result),
58 fields: parseResult(result),
59 };
60 }
61 } catch (error) {
62 throw new Error(error.message);
63 }
64 }
65
66 return { isPresent: false };
67};
68
69// Returns the file body when the path 200s, else null so the next path is tried
70const fetchSecurityTxt = async (baseURL, path) => {

Callers

nothing calls this directly

Calls 3

fetchSecurityTxtFunction · 0.85
isPgpSignedFunction · 0.85
parseResultFunction · 0.85

Tested by

no test coverage detected