diff --git a/src/components/Results/Cookies.tsx b/src/components/Results/Cookies.tsx index dcfff0e..a4f59e8 100644 --- a/src/components/Results/Cookies.tsx +++ b/src/components/Results/Cookies.tsx @@ -1,13 +1,31 @@ import { Card } from 'components/Form/Card'; import { ExpandableRow } from 'components/Form/Row'; +import { Cookie } from 'utils/result-processor'; + +export const parseHeaderCookies = (cookiesHeader: string[]): Cookie[] => { + if (!cookiesHeader || !cookiesHeader.length) return []; + const cookies = cookiesHeader.flatMap(cookieHeader => { + return cookieHeader.split(/,(?=\s[A-Za-z0-9]+=)/).map(cookieString => { + const [nameValuePair, ...attributePairs] = cookieString.split('; ').map(part => part.trim()); + const [name, value] = nameValuePair.split('='); + const attributes: Record = {}; + attributePairs.forEach(pair => { + const [attributeName, attributeValue = ''] = pair.split('='); + attributes[attributeName] = attributeValue; + }); + return { name, value, attributes }; + }); + }); + return cookies; +}; const CookiesCard = (props: { data: any, title: string, actionButtons: any}): JSX.Element => { - const cookies = props.data.cookies; + const headerCookies = parseHeaderCookies(props.data.headerCookies) || []; + const clientCookies = props.data.clientCookies || []; return ( - { cookies.length === 0 &&

No cookies found.

} { - cookies.map((cookie: any, index: number) => { + headerCookies.map((cookie: any, index: number) => { const attributes = Object.keys(cookie.attributes).map((key: string) => { return { lbl: key, val: cookie.attributes[key] } }); @@ -16,6 +34,14 @@ const CookiesCard = (props: { data: any, title: string, actionButtons: any}): JS ) }) } + { + clientCookies.map((cookie: any) => { + const nameValPairs = Object.keys(cookie).map((key: string) => { return { lbl: key, val: cookie[key] }}); + return ( + + ); + }) + }
); } diff --git a/src/utils/result-processor.ts b/src/utils/result-processor.ts index 9119278..11994e1 100644 --- a/src/utils/result-processor.ts +++ b/src/utils/result-processor.ts @@ -140,25 +140,6 @@ export type Cookie = { attributes: Record; }; -export const parseCookies = (cookiesHeader: string[]): {cookies: Cookie[]} => { - if (!cookiesHeader || !cookiesHeader.length) return {cookies: []}; - - const cookies = cookiesHeader.flatMap(cookieHeader => { - return cookieHeader.split(/,(?=\s[A-Za-z0-9]+=)/).map(cookieString => { - const [nameValuePair, ...attributePairs] = cookieString.split('; ').map(part => part.trim()); - const [name, value] = nameValuePair.split('='); - const attributes: Record = {}; - attributePairs.forEach(pair => { - const [attributeName, attributeValue = ''] = pair.split('='); - attributes[attributeName] = attributeValue; - }); - return { name, value, attributes }; - }); - }); - - return { cookies }; -}; - export const parseRobotsTxt = (content: string): { robots: RowProps[] } => { const lines = content.split('\n'); const rules: RowProps[] = [];