Skip to content

fix: use json.Marshal in CreateResult instead of string concatenation - #274

Closed
rubrx wants to merge 1 commit into
microcks:masterfrom
rubrx:fix/create-test-result-json-marshal
Closed

fix: use json.Marshal in CreateResult instead of string concatenation#274
rubrx wants to merge 1 commit into
microcks:masterfrom
rubrx:fix/create-test-result-json-marshal

Conversation

@rubrx

@rubrx rubrx commented May 4, 2026

Copy link
Copy Markdown

CreateTestResult was building JSON with string concatenation, which could break or allow injection if inputs had quotes/backslashes.

Switched to a typed struct + json.Marshal for safe escaping, and properly unmarshaled filteredOperations, operationsHeaders, and oAuth2Context before combining...

Tests:

  1. Malicious input test to ensure no field injection
  2. Verify secretName is omitted when empty (omitempty)

fixes #266

@rubrx
rubrx requested review from Harsh4902, lbroudoux and yada as code owners May 4, 2026 12:29
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

👋 @rubrx

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

Signed-off-by: Krie <112789870+R-Kri@users.noreply.github.com>
@rubrx
rubrx force-pushed the fix/create-test-result-json-marshal branch from 412502e to 27738af Compare May 4, 2026 12:33
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 30 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation.

There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this pull request forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions Bot added the stale State due to inactivity label Jun 4, 2026

@Vaishnav88sk Vaishnav88sk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rebase and resolve the conflicts

if len(filteredOperations) > 0 && ensureValidOperationsList(filteredOperations) {
input += (", \"filteredOperations\": " + filteredOperations)
var ops []string
_ = json.Unmarshal([]byte(filteredOperations), &ops)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The unmarshal errors are silently discarded. If ensureValidOperationsList says "valid" but the value isn't a []string (e.g. array of objects), the field is dropped instead of sent — a silent behavior regression vs the old code that forwarded the raw string. At minimum fall back to embedding the raw string, or return an error. I don't think we should swallow the unmarshal error.

Same concern applies to R353 and R358.

_ = json.Unmarshal([]byte(operationsHeaders), &headers)
payload.OperationsHeaders = headers
}
if len(oAuth2Context) > 0 && ensureValieOAuth2Context(oAuth2Context) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

minor nit: ensureValieOAuth2Context has a typo ("Valie"); consider renaming while you're here. Also update wherever applicabel.

@Caesarsage

Copy link
Copy Markdown
Contributor

As per my comment here #266 (comment)

I believe this PR can be close

@Harsh4902 Harsh4902 closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale State due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: use json.Marshal in CreateTestResult instead of string concatenation

4 participants