Skip to content

fix: return generic error details on AMF deserialization failures - #235

Merged
Alonza0314 merged 2 commits into
free5gc:mainfrom
arccat-114:fix/amf-deserialization-error-disclosure
Aug 18, 2026
Merged

fix: return generic error details on AMF deserialization failures#235
Alonza0314 merged 2 commits into
free5gc:mainfrom
arccat-114:fix/amf-deserialization-error-disclosure

Conversation

@arccat-114

Copy link
Copy Markdown
Contributor

Fixes #1128

Summary

Nine handlers in internal/sbi/api_communication.go (HTTPAMFStatusChangeSubscribeModify, HTTPCreateUEContext, HTTPEBIAssignment, HTTPRegistrationStatusUpdate, HTTPReleaseUEContext, HTTPUEContextTransfer, HTTPN1N2MessageTransfer, HTTPN1N2MessageSubscribe, HTTPAMFStatusChangeSubscribe) returned the raw Go error.Error() string in the Detail field of the ProblemDetails response on deserialization failure, exposing fully-qualified internal Go struct names to the client (GHSA-xw5p-5pgh-4xq5).

Changes

Keep the detailed error in the server log (unchanged) and return fixed client-facing messages instead:

  • request-body read failure: "Failed to read request body"
  • deserialization failure: "Failed to deserialize request body"

Validation

  • New test TestDeserializeErrorsDoNotLeakInternals covering all nine handlers: a truncated JSON body gets a 400 whose detail is the generic message. Before this fix the detail carried the raw deserialization error (red), with the fix it is the fixed message (green).
  • go test ./internal/sbi/: ok; go vet / gofmt: clean.

@d11nn

d11nn commented Aug 17, 2026

Copy link
Copy Markdown

Hi @arccat-114 ,
Please resolve linter error~

Use httptest.NewRequestWithContext to satisfy the noctx linter rule.
@arccat-114
arccat-114 force-pushed the fix/amf-deserialization-error-disclosure branch from 7769c71 to c3f4eaa Compare August 17, 2026 06:16
@d11nn

d11nn commented Aug 18, 2026

Copy link
Copy Markdown

@Alonza0314 LGTM

@Alonza0314

Copy link
Copy Markdown
Member

@arccat-114 Thanks for your improvement on error handling. How about using this statement:

fmt.Sprintf("xxxxx: %v\n", err)

Which will make the error message be clear as expected and also show the original error message for debug.

@arccat-114

This comment was marked as outdated.

Address review feedback: use fmt.Sprintf to log the deserialize failure
with context while keeping the original error, and keep the client-facing
detail generic.
@arccat-114

Copy link
Copy Markdown
Contributor Author

Follow-up: I went ahead and switched the log lines to fmt.Sprintf("Failed to deserialize request body: %v", err) (all nine deserialize-error paths). Original error stays in the server log, client-facing detail stays generic.

@d11nn

d11nn commented Aug 18, 2026

Copy link
Copy Markdown

@Alonza0314 LGTM

@Alonza0314

Copy link
Copy Markdown
Member

OK, I see. It looks good to me now.

@Alonza0314
Alonza0314 merged commit 778de0c into free5gc:main Aug 18, 2026
3 checks passed
@Alonza0314

Copy link
Copy Markdown
Member

@arccat-114
Thanks for your contribution. As your PR has been merged, don't forget to update your account in the contributor list at here.

Thanks again for your contribution.

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.

3 participants