Skip to content

Commit

Permalink
Merge pull request #1 from Lissy93/master
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
banderson12 authored Mar 28, 2024
2 parents c4dc9ab + 728a823 commit 9b1feca
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 89 deletions.
33 changes: 13 additions & 20 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,6 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
<sub><b>Peng1can</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/alydemah">
<img src="https://avatars.githubusercontent.com/u/652035?u=ac2c04e474da37bfeafcfa25076cc1800997aedb&v=4" width="80;" alt="alydemah"/>
<br />
<sub><b>Aly Mohamed</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/bgadrian">
<img src="https://avatars.githubusercontent.com/u/830001?u=69f115baad2fcd8c14eb05bdbf5cd80f4649a95a&v=4" width="80;" alt="bgadrian"/>
Expand All @@ -1076,15 +1069,15 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
<br />
<sub><b>Eddy Lazzarin</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/AnandChowdhary">
<img src="https://avatars.githubusercontent.com/u/2841780?u=747e554b3a7f12eb20b7910e1c87d817844f714f&v=4" width="80;" alt="AnandChowdhary"/>
<br />
<sub><b>Anand Chowdhary</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/shrippen">
<img src="https://avatars.githubusercontent.com/u/2873570?v=4" width="80;" alt="shrippen"/>
Expand Down Expand Up @@ -1119,15 +1112,15 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
<br />
<sub><b>InDieTasten</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/bmcgonag">
<img src="https://avatars.githubusercontent.com/u/7346620?u=2a0f9284f3e12ac1cc15288c254d1ec68a5081e8&v=4" width="80;" alt="bmcgonag"/>
<br />
<sub><b>Brian McGonagill</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/vlad-timofeev">
<img src="https://avatars.githubusercontent.com/u/11474041?u=eee43705b54d2ec9f51fc4fcce5ad18dd17c87e4&v=4" width="80;" alt="vlad-timofeev"/>
Expand All @@ -1144,7 +1137,7 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
</td>
<td align="center">
<a href="https://github.com/mryesiller">
<img src="https://avatars.githubusercontent.com/u/24632172?v=4" width="80;" alt="mryesiller"/>
<img src="https://avatars.githubusercontent.com/u/24632172?u=0d20f2d615158f87cd60a3398d3efb026c32f291&v=4" width="80;" alt="mryesiller"/>
<br />
<sub><b>Göksel Yeşiller</b></sub>
</a>
Expand All @@ -1162,15 +1155,15 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
<br />
<sub><b>Bastii717</b></sub>
</a>
</td></tr>
<tr>
</td>
<td align="center">
<a href="https://github.com/frankdez93">
<img src="https://avatars.githubusercontent.com/u/87549420?v=4" width="80;" alt="frankdez93"/>
<br />
<sub><b>Frankdez93</b></sub>
</a>
</td>
</td></tr>
<tr>
<td align="center">
<a href="https://github.com/ratty222">
<img src="https://avatars.githubusercontent.com/u/92832598?u=137b65530cbd5f5af9c24cde51baa6cc77cc934b&v=4" width="80;" alt="ratty222"/>
Expand All @@ -1179,10 +1172,10 @@ Huge thanks to these wonderful people, who sponsor me on GitHub, their support h
</a>
</td>
<td align="center">
<a href="https://github.com/hernanpopper">
<img src="https://avatars.githubusercontent.com/u/104868017?v=4" width="80;" alt="hernanpopper"/>
<a href="https://github.com/terminaltrove">
<img src="https://avatars.githubusercontent.com/u/121595180?v=4" width="80;" alt="terminaltrove"/>
<br />
<sub><b>Hernanpopper</b></sub>
<sub><b>Terminal Trove</b></sub>
</a>
</td>
<td align="center">
Expand Down
63 changes: 54 additions & 9 deletions api/_common/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,47 @@ const normalizeUrl = (url) => {
return url.startsWith('http') ? url : `https://${url}`;
};

// If present, set a shorter timeout for API requests
const TIMEOUT = process.env.API_TIMEOUT_LIMIT ? parseInt(process.env.API_TIMEOUT_LIMIT, 10) : 60000;

// If present, set CORS allowed origins for responses
const ALLOWED_ORIGINS = process.env.API_CORS_ORIGIN || '*';

// Set the platform currently being used
let PLATFORM = 'NETLIFY';
if (process.env.PLATFORM) { PLATFORM = process.env.PLATFORM.toUpperCase(); }
else if (process.env.VERCEL) { PLATFORM = 'VERCEL'; }
else if (process.env.WC_SERVER) { PLATFORM = 'NODE'; }

// Define the headers to be returned with each response
const headers = {
'Access-Control-Allow-Origin': process.env.API_CORS_ORIGIN || '*',
'Access-Control-Allow-Origin': ALLOWED_ORIGINS,
'Access-Control-Allow-Credentials': true,
'Content-Type': 'application/json;charset=UTF-8',
};


const timeoutErrorMsg = 'You can re-trigger this request, by clicking "Retry"\n'
+ 'If you\'re running your own instance of Web Check, then you can '
+ 'resolve this issue, by increasing the timeout limit in the '
+ '`API_TIMEOUT_LIMIT` environmental variable to a higher value (in milliseconds), '
+ 'or if you\'re hosting on Vercel increase the maxDuration in vercel.json.\n\n'
+ `The public instance currently has a lower timeout of ${TIMEOUT}ms `
+ 'in order to keep running costs affordable, so that Web Check can '
+ 'remain freely available for everyone.';

// A middleware function used by all API routes on all platforms
const commonMiddleware = (handler) => {

// Create a timeout promise, to throw an error if a request takes too long
const createTimeoutPromise = (timeoutMs) => {
return new Promise((_, reject) => {
setTimeout(() => {
reject(new Error(`Request timed-out after ${timeoutMs} ms`));
}, timeoutMs);
});
};

// Vercel
const vercelHandler = async (request, response) => {
const queryParams = request.query || {};
Expand All @@ -21,7 +55,12 @@ const commonMiddleware = (handler) => {
const url = normalizeUrl(rawUrl);

try {
const handlerResponse = await handler(url, request);
// Race the handler against the timeout
const handlerResponse = await Promise.race([
handler(url, request),
createTimeoutPromise(TIMEOUT)
]);

if (handlerResponse.body && handlerResponse.statusCode) {
response.status(handlerResponse.statusCode).json(handlerResponse.body);
} else {
Expand All @@ -30,7 +69,12 @@ const commonMiddleware = (handler) => {
);
}
} catch (error) {
response.status(500).json({ error: error.message });
let errorCode = 500;
if (error.message.includes('timed-out') || response.statusCode === 504) {
errorCode = 408;
error.message = `${error.message}\n\n${timeoutErrorMsg}`;
}
response.status(errorCode).json({ error: error.message });
}
};

Expand All @@ -51,7 +95,12 @@ const commonMiddleware = (handler) => {
const url = normalizeUrl(rawUrl);

try {
const handlerResponse = await handler(url, event, context);
// Race the handler against the timeout
const handlerResponse = await Promise.race([
handler(url, event, context),
createTimeoutPromise(TIMEOUT)
]);

if (handlerResponse.body && handlerResponse.statusCode) {
callback(null, handlerResponse);
} else {
Expand All @@ -71,11 +120,7 @@ const commonMiddleware = (handler) => {
};

// The format of the handlers varies between platforms
// E.g. Netlify + AWS expect Lambda functions, but Vercel or Node needs standard handler
const platformEnv = (process.env.PLATFORM || '').toUpperCase(); // Has user set platform manually?

const nativeMode = (['VERCEL', 'NODE'].includes(platformEnv) || process.env.VERCEL || process.env.WC_SERVER);

const nativeMode = (['VERCEL', 'NODE'].includes(PLATFORM));
return nativeMode ? vercelHandler : netlifyHandler;
};

Expand Down
10 changes: 6 additions & 4 deletions api/sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ const xml2js = require('xml2js');
const handler = async (url) => {
let sitemapUrl = `${url}/sitemap.xml`;

const hardTimeOut = 5000;

try {
// Try to fetch sitemap directly
let sitemapRes;
try {
sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 });
sitemapRes = await axios.get(sitemapUrl, { timeout: hardTimeOut });
} catch (error) {
if (error.response && error.response.status === 404) {
// If sitemap not found, try to fetch it from robots.txt
const robotsRes = await axios.get(`${url}/robots.txt`, { timeout: 5000 });
const robotsRes = await axios.get(`${url}/robots.txt`, { timeout: hardTimeOut });
const robotsTxt = robotsRes.data.split('\n');

for (let line of robotsTxt) {
Expand All @@ -28,7 +30,7 @@ const handler = async (url) => {
return { skipped: 'No sitemap found' };
}

sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 });
sitemapRes = await axios.get(sitemapUrl, { timeout: hardTimeOut });
} else {
throw error; // If other error, throw it
}
Expand All @@ -40,7 +42,7 @@ const handler = async (url) => {
return sitemap;
} catch (error) {
if (error.code === 'ECONNABORTED') {
return { error: 'Request timed out after 5000ms' };
return { error: `Request timed-out after ${hardTimeOut}ms` };
} else {
return { error: error.message };
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-check",
"version": "1.1.0",
"version": "1.1.2",
"private": false,
"description": "All-in-one OSINT tool for analyzing any website",
"repository": "github:lissy93/web-check",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const ExpandableRow = (props: RowProps) => {
{ rowList?.map((row: RowProps, index: number) => {
return (
<SubRow key={`${row.lbl}-${index}`}>
<span className="lbl" title={row.title}>{row.lbl}</span>
<span className="lbl" title={row.title?.toString()}>{row.lbl}</span>
<span className="val" title={row.val} onClick={() => copyToClipboard(row.val)}>
{formatValue(row.val)}
</span>
Expand Down Expand Up @@ -199,7 +199,7 @@ const Row = (props: RowProps) => {
if (children) return <StyledRow key={`${lbl}-${val}`}>{children}</StyledRow>;
return (
<StyledRow key={`${lbl}-${val}`}>
{ lbl && <span className="lbl" title={title}>{lbl}</span> }
{ lbl && <span className="lbl" title={title?.toString()}>{lbl}</span> }
<span className="val" title={val} onClick={() => copyToClipboard(val)}>
{formatValue(val)}
</span>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Results/BlockLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const BlockListsCard = (props: {data: any, title: string, actionButtons: any }):
const blockLists = props.data.blocklists;
return (
<Card heading={props.title} actionButtons={props.actionButtons}>
{ blockLists.map((blocklist: any) => (
{ blockLists.map((blocklist: any, blockIndex: number) => (
<Row
title={blocklist.serverIp}
lbl={blocklist.server}
val={blocklist.isBlocked ? '❌ Blocked' : '✅ Not Blocked'} />
val={blocklist.isBlocked ? '❌ Blocked' : '✅ Not Blocked'}
key={`blocklist-${blockIndex}-${blocklist.serverIp}`}
/>
))}
</Card>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/Results/DnsServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const DnsServerCard = (props: {data: any, title: string, actionButtons: any }):
return (
<Card heading={props.title} actionButtons={props.actionButtons} styles={cardStyles}>
{dnsSecurity.dns.map((dns: any, index: number) => {
return (<>
return (<div key={`dns-${index}`}>
{ dnsSecurity.dns.length > 1 && <Heading as="h4" size="small" color={colors.primary}>DNS Server #{index+1}</Heading> }
<Row lbl="IP Address" val={dns.address} key={`ip-${index}`} />
{ dns.hostname && <Row lbl="Hostname" val={dns.hostname} key={`host-${index}`} /> }
<Row lbl="DoH Support" val={dns.dohDirectSupports ? '✅ Yes*' : '❌ No*'} key={`doh-${index}`} />
</>);
</div>);
})}
{dnsSecurity.dns.length > 0 && (<small>
* DoH Support is determined by the DNS server's response to a DoH query.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Results/ServerStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ span.val {
const ServerStatusCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => {
const serverStatus = props.data;
return (
<Card heading={props.title} actionButtons={props.actionButtons} styles={cardStyles}>
<Card heading={props.title.toString()} actionButtons={props.actionButtons} styles={cardStyles}>
<Row lbl="" val="">
<span className="lbl">Is Up?</span>
{ serverStatus.isUp ? <span className="val up">✅ Online</span> : <span className="val down">❌ Offline</span>}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Results/TlsCipherSuites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TlsCard = (props: {data: any, title: string, actionButtons: any }): JSX.El
<Card heading={props.title} actionButtons={props.actionButtons}>
{ cipherSuites.length && cipherSuites.map((cipherSuite: any, index: number) => {
return (
<ExpandableRow lbl={cipherSuite.title} val="" rowList={cipherSuite.fields} />
<ExpandableRow key={`tls-${index}`} lbl={cipherSuite.title} val="" rowList={cipherSuite.fields} />
);
})}
{ !cipherSuites.length && (
Expand Down
11 changes: 9 additions & 2 deletions src/components/Results/TlsClientSupport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ const TlsCard = (props: {data: any, title: string, actionButtons: any }): JSX.El
const scanId = props.data?.id;
return (
<Card heading={props.title} actionButtons={props.actionButtons}>
{clientSupport.map((support: any) => {
return (<ExpandableRow lbl={support.title} val={support.value || '?'} rowList={support.fields} />)
{clientSupport.map((support: any, index: number) => {
return (
<ExpandableRow
key={`tls-client-${index}`}
lbl={support.title}
val={support.value || '?'}
rowList={support.fields}
/>
)
})}
{ !clientSupport.length && (
<div>
Expand Down
8 changes: 7 additions & 1 deletion src/components/Results/TlsIssueAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ const TlsCard = (props: {data: any, title: string, actionButtons: any }): JSX.El
<Card heading={props.title} actionButtons={props.actionButtons}>
{ tlsResults.length > 0 && tlsResults.map((row: any, index: number) => {
return (
<Row lbl={row.lbl} val={row.val} plaintext={row.plaintext} listResults={row.list} />
<Row
lbl={row.lbl}
val={row.val}
plaintext={row.plaintext}
listResults={row.list}
key={`tls-issues-${index}`}
/>
);
})}
<Expandable>
Expand Down
1 change: 1 addition & 0 deletions src/components/misc/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import colors from 'styles/colors';
interface Props {
children: ReactNode;
title?: string;
key?: string;
}

interface State {
Expand Down
Loading

0 comments on commit 9b1feca

Please sign in to comment.