Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/core/common/mockProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { validatePassword } from "../utils/mockProcessor";
import { getServerMockResponse } from "../utils/mockServerResponseHelper";
import pathMatcher from "../utils/pathMatcher";
import { renderTemplate } from "../utils/templating";
import { getPostData } from "../utils/harFormatter";

class MockProcessor {
static process = async (
Expand Down Expand Up @@ -35,6 +36,7 @@ class MockProcessor {
statusCode: responseTemplate.statusCode,
urlParams,
headers: request.headers as Record<string, string> || {},
data: getPostData(request)
};
Comment on lines +39 to 40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Redact or remove logging of contextParams; adding data now risks leaking PII/secrets.

With data included, the existing console.log (Line 42) will emit request bodies and sensitive headers.

Suggested mitigation (replace the current log):

// Redacted debug logging
const { data: _redacted, headers, ...rest } = contextParams;
const redactedHeaders = Object.fromEntries(
  Object.entries(headers || {}).map(([k, v]) => [
    k,
    /authorization|cookie|token|key/i.test(k) ? '[REDACTED]' : v,
  ])
);
console.debug({ ...rest, headers: redactedHeaders });
🤖 Prompt for AI Agents
In src/core/common/mockProcessor.ts around lines 39-40, the patch adds request
data into contextParams which causes the existing console.log to emit request
bodies and sensitive headers; remove or redact sensitive fields before logging:
do not log the full data field, strip or rename it (e.g. omit data or set to
"[REDACTED]"), sanitize headers by replacing values for keys matching
authorization|cookie|token|key (case-insensitive) with "[REDACTED]", and log
only the remaining non-sensitive properties; update the
console.debug/console.log call to use the sanitized object instead of the raw
contextParams.


console.log({ contextParams });
Expand Down
14 changes: 14 additions & 0 deletions src/core/utils/templating/helpers/requestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ const requestHelpers = (params: MockContextParams) => {

return params.headers[param?.toLowerCase()] || defaultValue;
},
body: (key: string) => { // passes key
const rawData = params.data
const defaultResponse = ''
if(rawData && rawData.text) {
try {
// fix-me: handle url encoded params and other operations on body later
const parsedData = JSON.parse(rawData.text)
return parsedData[key] ?? defaultResponse
} catch (error) {
/* NOOP */
}
}
return defaultResponse
}
};
return helpers;
};
Expand Down
2 changes: 1 addition & 1 deletion src/test/dummy/mock1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const dummyMock1: Mock = {
foo: "bar",
"content-type": "application/json",
},
body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}" }}',
body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}", body: "{{body \'test\'}}" }',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Fix invalid JSON key: quote "body".

Unquoted property names make the response body invalid JSON.

Apply this diff:

-      body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}", body: "{{body \'test\'}}"  }',
+      body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}", "body": "{{body \'test\'}}"  }',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}", body: "{{body \'test\'}}" }',
body: '{"Hello":"There","mockId":"1", "statusCode": {{ statusCode }}, "method": "{{ method }}", "urlParams": "{{ urlParam \'userId\' }}", "header": "{{ header \'userid\' \'test\' }}", "body": "{{body \'test\'}}" }',
🤖 Prompt for AI Agents
In src/test/dummy/mock1.ts around line 21, the JSON string assigned to the body
contains an unquoted property name body which makes it invalid JSON; update the
string so the property name "body" is quoted (and ensure any inner quotes are
properly escaped or the surrounding string delimiter adjusted) so the entire
value is valid JSON.

},
],
};
Expand Down
2 changes: 2 additions & 0 deletions src/types/internal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Request } from "har-format";
import { RequestMethod } from ".";

export interface MockContextParams {
urlParams: Record<string, string>;
method: RequestMethod;
statusCode: number;
headers: Record<string, string>;
data: Request["postData"]
}
Comment on lines +1 to 10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Verify har-format is declared in package.json (dev dep is fine).

Ensures the type import resolves in CI.

Run:


🏁 Script executed:

#!/bin/bash
fd -a package.json | xargs -I{} rg -nC2 -H '"har-format"' {}

Length of output: 0


🏁 Script executed:

#!/bin/bash
set -euo pipefail

found=false
while IFS= read -r -d '' file; do
  found=true
  echo "=== $file ==="
  if command -v rg >/dev/null 2>&1; then
    rg -nC2 -H '"har-format"' "$file" || echo "no match in $file"
  else
    grep -n '"har-format"' "$file" || echo "no match in $file"
  fi
done < <(find . -type f -name package.json -print0)

if [ "$found" = false ]; then
  echo "no package.json files found"
fi

Length of output: 57


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# find package.json via git or find
files="$(git ls-files -- package.json 2>/dev/null || true)"
if [ -z "$files" ]; then
  files="$(find . -type f -name 'package.json' -print 2>/dev/null || true)"
fi

if [ -z "$files" ]; then
  echo "no package.json files found"
  exit 0
fi

for f in $files; do
  echo "=== $f ==="
  if command -v jq >/dev/null 2>&1; then
    jq -r '["dependencies","devDependencies","peerDependencies","optionalDependencies"] | .[] as $k | (.[$k] // {}) | keys[]' "$f" 2>/dev/null | sort -u | rg -n --hidden -F 'har-format' || echo "har-format not listed in deps of $f"
  else
    if grep -q '"har-format"' "$f"; then
      echo "har-format entry:"
      grep -n '"har-format"' "$f" || true
    else
      echo "har-format not found in $f"
    fi
  fi
done

Length of output: 66


Add har-format to package.json (devDependency OK)
Type import in src/types/internal.ts (import { Request } from "har-format") is not declared in package.json; add "har-format" as a dependency/devDependency so the type import resolves in CI.

🤖 Prompt for AI Agents
In src/types/internal.ts around lines 1 to 10, the code imports Request from
"har-format" but the package is not declared in package.json, causing CI type
resolution failures; add "har-format" to package.json (as a devDependency is
fine) and run your package manager install (e.g., npm install --save-dev
har-format or pnpm add -D har-format) so the type import resolves in CI; commit
the updated package.json and lockfile.