Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add html formatting support in request response findings #1484

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { action } from '@ember/object';
import type IntlService from 'ember-intl/services/intl';

import type AnalysisModel from 'irene/models/analysis';
import type { VulnerableApiFinding } from 'irene/utils/parse-vulnerable-api-finding';
import {
indentHTML,
type VulnerableApiFinding,
} from 'irene/utils/parse-vulnerable-api-finding';

export interface FileDetailsVulnerabilityAnalysisDetailsFindingsVulnerableApiSignature {
Element: HTMLDivElement;
Expand All @@ -17,6 +20,7 @@ export interface FileDetailsVulnerabilityAnalysisDetailsFindingsVulnerableApiSig
interface FormattedResult {
value: string;
isJSON?: boolean;
isHTML?: boolean;
}

interface VulnerabilityDetails {
Expand All @@ -40,82 +44,34 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsVulnerableAp
}

get currentVulnerabilityDetails() {
return [
{
label: this.intl.t('url'),
value: this.url,
},
{
label: this.intl.t('method'),
value: this.vulnerabilityRequest?.method,
},
{
label: this.intl.t('severity'),
value: this.args.currentVulnerability?.severity,
},
{
label: this.intl.t('confidence'),
value: this.args.currentVulnerability?.confidence,
},
{
label: this.intl.t('issueDetails'),
value: this.args.currentVulnerability?.description,
},
];
}

get isRequestHeadersEmpty() {
const headers = this.vulnerabilityRequest?.headers;

return headers && Object.keys(headers).length === 0;
}

get isResponseHeadersEmpty() {
const headers = this.args.currentVulnerability?.response?.headers;

return headers && Object.keys(headers).length === 0;
}

get isRequestParamsEmpty() {
const params = this.vulnerabilityRequest?.params;

return params && Object.keys(params).length === 0;
}

get isRequestBodyEmpty() {
const body = this.vulnerabilityRequest?.body;

return body === "''" || body === '';
}

get isResponseBodyEmpty() {
const body = this.vulnerabilityResponse?.text;

return body === "''" || body === '';
}

get isRequestCookiesEmpty() {
const cookies = this.vulnerabilityRequest?.cookies;

return cookies && Object.keys(cookies).length === 0;
}

get isResponseCookiesEmpty() {
const cookies = this.vulnerabilityResponse?.cookies;

return cookies && Object.keys(cookies).length === 0;
}

get responseStatusCode() {
const statusCode = this.vulnerabilityResponse?.status_code;

return this.intl.t('statusCode') + ': ' + statusCode;
}

get responseMessage() {
const message = this.vulnerabilityResponse?.reason;

return this.intl.t('message') + ': ' + message;
const currentVulnerability = this.args.currentVulnerability || {};

if (Object.keys(currentVulnerability).length !== 0) {
return [
{
label: this.intl.t('url'),
value: this.url,
},
{
label: this.intl.t('method'),
value: this.vulnerabilityRequest?.method,
},
{
label: this.intl.t('severity'),
value: this.args.currentVulnerability?.severity,
},
{
label: this.intl.t('confidence'),
value: this.args.currentVulnerability?.confidence,
},
{
label: this.intl.t('issueDetails'),
value: this.args.currentVulnerability?.description,
},
];
} else {
return [];
}
}

get url() {
Expand All @@ -140,84 +96,117 @@ export default class FileDetailsVulnerabilityAnalysisDetailsFindingsVulnerableAp
.replace(/(^['"])|(['"]$)/g, '')
.replace(/\\n/g, '\n');

// Check if it's HTML content
if (
sanitizedString.includes('<!DOCTYPE html') ||
sanitizedString.includes('<html') ||
sanitizedString.toLowerCase().includes('<!doctype html')
) {
return {
value: indentHTML(sanitizedString),
isJSON: false,
isHTML: true,
};
}

// Try to parse as JSON first
try {
const parsed = JSON.parse(sanitizedString);

return {
value: JSON.stringify(parsed, null, 2),
isJSON: true,
isHTML: false,
};
} catch {
// If JSON parsing fails, return the sanitized string
return {
value: sanitizedString,
isJSON: false,
isHTML: false,
};
}
}

getWhiteSpaceStyle(formattedBody: {
isJSON?: boolean;
isHTML?: boolean;
}): string {
return formattedBody.isJSON || formattedBody.isHTML
? 'pre-wrap'
: 'pre-line';
}

get vulnerabilityDetails() {
const request = this.args.currentVulnerability?.request;
const response = this.args.currentVulnerability?.response;

const formattedRequestBody = this.getFormattedText(request?.body);
const formattedResponseBody = this.getFormattedText(response?.text);

const reqBodyWhitespaceStyle =
this.getWhiteSpaceStyle(formattedRequestBody);

const resBodyWhitespaceStyle = this.getWhiteSpaceStyle(
formattedResponseBody
);

return [
{
title: this.intl.t('requestBody'),
value: formattedRequestBody.value,
isEmpty: this.isRequestBodyEmpty,
isEmpty: !request?.body,
copyIcon: true,
whiteSpace: formattedRequestBody.isJSON ? 'pre-wrap' : 'pre-line',
whiteSpace: reqBodyWhitespaceStyle,
},
{
title: this.intl.t('requestHeaders'),
value: request?.headers,
isEmpty: this.isRequestHeadersEmpty,
isEmpty: !request?.headers,
copyIcon: true,
isKeyValuePair: true,
},
{
title: this.intl.t('requestParameters'),
value: request?.params,
isEmpty: this.isRequestParamsEmpty,
isEmpty: !request?.params || Object.keys(request.params).length === 0,
copyIcon: true,
isKeyValuePair: true,
},
{
title: this.intl.t('requestCookies'),
value: request?.cookies,
isEmpty: this.isRequestCookiesEmpty,
isEmpty: !request?.cookies || Object.keys(request.cookies).length === 0,
copyIcon: true,
isKeyValuePair: true,
},
{
title: this.intl.t('response'),
value: `${this.responseStatusCode}\n${this.responseMessage}`,
value: response?.status_code,
isEmpty: !response?.status_code,
copyIcon: false,
},
{
title: this.intl.t('responseHeaders'),
value: response?.headers,
isEmpty: this.isResponseHeadersEmpty,
isEmpty:
!response?.headers || Object.keys(response.headers).length === 0,
copyIcon: true,
isKeyValuePair: true,
},
{
title: this.intl.t('responseCookies'),
value: response?.cookies,
isEmpty: this.isResponseCookiesEmpty,
isEmpty:
!response?.cookies || Object.keys(response.cookies).length === 0,
copyIcon: true,
isKeyValuePair: true,
},
{
title: this.intl.t('responseBody'),
value: formattedResponseBody.value,
isEmpty: this.isResponseBodyEmpty,
whiteSpace: formattedResponseBody.isJSON ? 'pre-wrap' : 'pre-line',
isEmpty: !response?.text || response?.text === '""',
whiteSpace: resBodyWhitespaceStyle,
copyIcon: true,
},
] as VulnerabilityDetails[];
Expand Down
Loading
Loading