Skip to content

Conversation

@marle3003
Copy link
Owner

Potential fix for https://github.com/marle3003/mokapi/security/code-scanning/45

The safest way to fix this issue is to avoid interpolating untrusted data directly into single-quoted strings using %s. Instead, use fmt.Sprintf("%q", ... ), which escapes both single and double quotes as required, or sanitize the input specifically by escaping single quotes ('\'), and, just as crucially, also escape backslashes first (\\\). In Go, strconv.Quote is the idiomatic method for quoting strings safely; it produces a double-quoted, safely escaped literal.

The fix will be to update the single line where the error message string is created so that name is safely quoted, replacing '%s' (which is a single-quoted string) with %q (Go double-quoted and escaped), or using strconv.Quote(name). We'll also add the necessary import for "strconv" in schema/json/parser/parser_object.go.

This addresses all variants since they flow through the same pattern of unsafely embedding a potentially untrusted string into a quoted context.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@marle3003 marle3003 marked this pull request as ready for review December 13, 2025 10:33
@marle3003 marle3003 merged commit cf32e10 into main Dec 13, 2025
9 checks passed
@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.86%. Comparing base (25bbbc8) to head (0ec5a34).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
schema/json/parser/parser_object.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #779      +/-   ##
==========================================
- Coverage   70.87%   70.86%   -0.01%     
==========================================
  Files         457      457              
  Lines       41293    41293              
==========================================
- Hits        29267    29264       -3     
- Misses       9863     9865       +2     
- Partials     2163     2164       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants