siprec icon indicating copy to clipboard operation
siprec copied to clipboard

body truncated

Open FredL45 opened this issue 2 months ago • 7 comments

Hello, I'm using your last version of SipRec server with an audiocodes virtual sbc. It's look like the body is trucated as you can see in the following debug. As you retrieve the body and the body size from the sipgo pack, I think that the issue comes from sipgo/sip/message.go

Sep 09 21:11:27 debian siprec-server[83038]: {"body_size":2464,"branch":"z9hG4bKac311994078","call_id":"[email protected]","from_tag":"1c1818087822","level":"info","message":"Processing SIPREC INVITE with large metadata","siprec":true,"timestamp":"2026-09-09T21:11:27.150521475+02:00","transport":"udp"} Sep 09 21:11:27 debian siprec-server[83038]: {"full_body":""--boundary_ac14d5\r\nContent-Type: application/sdp\r\n\r\nv=0\r\no=AudiocodesGW 1644952274 165864691 IN IP4 192.168.100.21\r\ns=SBC-Call\r\nc=IN IP4 192.168.100.21\r\nt=0 0\r\nm=audio 7716 RTP/AVP 8 101\r\nc=IN IP4 192.168.100.21\r\na=ptime:20\r\na=sendonly\r\na=label:1\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15,16\r\nm=audio 7720 RTP/AVP 8 101\r\nc=IN IP4 192.168.100.21\r\na=ptime:20\r\na=sendonly\r\na=label:2\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15,16\r\n\r\n--boundary_ac14d5\r\nContent-Type: application/rs-metadata\r\nContent-Disposition: recording-session\r\n\r\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\r\n\u003crecording xmlns=\"urn:ietf:params:xml:ns:recording:1\" xmlns:ac=\"http://AudioCodes\"\u003e\r\n \u003cdatamode\u003ecomplete\u003c/datamode\u003e\r\n \u003cgroup group_id=\"AAAAAAAAAIPgAAAAS9TpbA==\"\u003e\r\n \u003cassociate-time\u003e2026-09-09T21:11:26\u003c/associate-time\u003e\r\n \u003c/group\u003e\r\n \u003csession session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003cgroup-ref\u003eAAAAAAAAAIPgAAAAS9TpbA==\u003c/group-ref\u003e\r\n \u003c/session\u003e\r\n \u003cparticipant participant_id=\"+yuvxd5+qkznRi4kqbN/eQ==\"\u003e\r\n \u003cnameID aor=\"[email protected]\"\u003e\r\n \u003cname xml:lang=\"en\"\u003eLAVIGNE Frederic\u003c/name\u003e\r\n \u003c/nameID\u003e\r\n \u003c/participant\u003e\r\n \u003cparticipant participant_id=\"uCE1QysmqkxxVDjXizgoaA==\"\u003e\r\n \u003cnameID aor=\"[email protected]\"\u003e\u003c/nameID\u003e\r\n \u003c/participant\u003e\r\n \u003cstream stream_id=\"AAAAAADEG4PgAAAAS9TpbA==\" session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003clabel\u003e1\u003c/label\u003e\r\n \u003c/stream\u003e\r\n \u003cstream stream_id=\"AAAAAAGkKoPgAAAAS9TpbA==\" session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003clabel\u003e2\u003c/label\u003e\r\n \u003c/stream\u003e\r\n \u003csessionrecordingassoc session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003cassociate-time\u003e2026-09-09T21:11:26\u003c/associate-time\u003e\r\n \u003c/sessionrecordingassoc\u003e\r\n \u003cparticipantsessionassoc participant_id=\"+yuvxd5+qkznRi4kqbN/eQ==\" session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003cassociate-time\u003e2026-09-09T21:11:26\u003c/associate-time\u003e\r\n \u003c/participantsessionassoc\u003e\r\n \u003cparticipantsessionassoc participant_id=\"uCE1QysmqkxxVDjXizgoaA==\" session_id=\"AAAAAAAAAAC2aHpsnHeCzQ==\"\u003e\r\n \u003cassociate-time\u003e2026-09-09T21:11:26\u003c/associate-time\u003e\r\n \u003c/participantsessionassoc\u003e\r\n \u003cparticipantstreamassoc participant_id=\"+yuvxd5+qkznRi4kqbN/eQ==\"\u003e\r\n \u003csend\u003eAAAAAADEG4PgAAAAS9TpbA==\u003c/send\u003e\r\n \u003crecv\u003eAAAAAAGkKoPgAAAAS9TpbA==\u003c/recv\u003e\r\n \u003c/participantstreamassoc\u003e\r\n \u003cparticipantstreamassoc participant_id=\"uCE1QysmqkxxVDjXizgoaA==\"\u003e\r\n \u003csend\u003eAAAAAAGkKoPgAAAAS9TpbA==\u003c/send\u003e\r\n \u003crecv\u003eAAAAAADEG4PgAAAAS9TpbA==\u003c/recv\u003e\r\n \u003c/participantstreamass"","has_crlf":true,"has_lone_lf":false,"last_80_bytes":""bA==\u003c/send\u003e\r\n \u003crecv\u003eAAAAAADEG4PgAAAAS9TpbA==\u003c/recv\u003e\r\n \u003c/participantstreamass"","level":"debug","message":"Raw body line-ending check","timestamp":"2026-09-09T21:11:27.15077553+02:00"} Sep 09 21:11:27 debian siprec-server[83038]: {"level":"debug","message":"Extracted SDP part from SIPREC multipart","sdp_size":438,"timestamp":"2026-09-09T21:11:27.150923427+02:00"} Sep 09 21:11:27 debian siprec-server[83038]: {"error":"unexpected EOF","level":"warning","message":"Failed to read multipart section","timestamp":"2026-09-09T21:11:27.15097698+02:00"} Sep 09 21:11:27 debian siprec-server[83038]: {"error":"multipart: NextPart: EOF","level":"warning","message":"Failed to iterate multipart SIPREC body","timestamp":"2026-09-09T21:11:27.150995529+02:00"} Sep 09 21:11:27 debian siprec-server[83038]: {"error":"SIPREC INVITE missing mandatory rs-metadata part","level":"warning","message":"Rejecting SIPREC INVITE without rs-metadata part","siprec":true,"timestamp":"2026-09-09T21:11:27.151037779+02:00"}

FredL45 avatar Sep 09 '26 19:09 FredL45

looking into it now

loreste avatar Sep 09 '26 20:09 loreste

Hey Fred, thanks for the detailed logs — that made tracking this down a lot easier.

Turns out the issue was in our CRLF normalizer. We have a layer that converts bare \n to \r\n for compatibility with sipgo's parser, but it was doing that across the entire UDP packet — body included. When your AudioCodes SBC sends the multipart body with bare LF line endings, the normalizer expands them, making the body longer than what Content-Length says. sipgo then reads exactly Content-Length bytes and chops the rest off, which is why you see the XML cut mid-tag and the multipart reader hitting EOF before it finds the rs-metadata part.

The fix (merged in #45) now only normalizes the SIP header section and leaves the body untouched, so Content-Length stays accurate and the full multipart payload gets through.

If you get a chance to test with the latest build, let me know how it goes.

loreste avatar Sep 09 '26 20:09 loreste

Hey Lance, All is working fine, though Audiocodes do not follow the RFC 7865 for the Application Type but only for the XML body, I have to create a manipulation to replace application/rs-metadata with application/rs-metadata+xml

I tried to modify the mediaType check in parser.go

		if strings.EqualFold(mediaType, "application/rs-metadata") ||
		strings.EqualFold(mediaType, "application/rs-metadata+xml") {

But it doesn't work because custom_server.go handles only application/rs-metadata+xml. It's really easy to adapt the code because there are a lot of SBC using application/rs-metadata rather than application/rs-metadata+xml.

lines 1968 and 2279 : Replace "Accept": "application/sdp, application/rs-metadata+xml, multipart/mixed", with "Accept": "application/sdp, application/rs-metadata+xml, application/rs-metadata, multipart/mixed",

line 4245 : Insert before default

		case "application/rs-metadata":
			if err := security.ValidateSize(data, security.MaxMetadataSize, "SIPREC metadata"); err != nil {
				s.logger.WithError(err).Warn("SIPREC metadata exceeds size limit")
				continue
			}
			rsMetadata = append([]byte(nil), data...)
			s.logger.WithField("metadata_size", len(rsMetadata)).Debug("Extracted rs-metadata part from SIPREC multipart")

Finaly, adapt the mediaType check in parser.go

I think that the manipulation is easier but I don't understand how you validate the service with Audiocodes without a manipulation applied in outbound on the SRS IP-Group

ManSet INI extract

[ MsgManSet ]

FORMAT Index = Name;
MsgManSet 0 = "SRS - RFC7865";

[ \MsgManSet ]


[ MessageManipulations ]

FORMAT Index = ManSetName, ManIndex, ManipulationName, MessageType, Condition, ActionSubject, ActionType, ActionValue, RowRole, Active;
MessageManipulations 0 = "SRS - RFC7865", 0, "rs-metadata store", "invite.request", "body.application/rs-metadata exists", "var.session.rs-metadata", 0, "body.application/rs-metadata", 0, 1;
MessageManipulations 1 = "SRS - RFC7865", 1, "rs-metadata+xml create", "invite.request", "var.session.rs-metadata exists", "body.application/rs-metadata+xml", 0, "var.session.rs-metadata", 0, 1;
MessageManipulations 2 = "SRS - RFC7865", 2, "rs-metadata delete", "invite.request", "var.session.rs-metadata exists", "body.application/rs-metadata", 1, "", 0, 1;

[ \MessageManipulations ]

FredL45 avatar Sep 10 '26 08:09 FredL45

Hey Fred,

Glad the truncation fix is working. And yeah, you're right — we should just accept both application/rs-metadata and application/rs-metadata+xml server-side instead of making people add SBC manipulations. Plenty of SBCs use the short form, AudioCodes being the obvious one.

Your analysis of the touch points is correct. I'll get that in — it's a small change across extractSiprecContent, the Accept headers, and parser.go. The UPDATE handler at line 3036 already does a strings.Contains on "rs-metadata" so that path is fine as-is.

As for how we were testing against AudioCodes without the manipulation — honestly, most of our AudioCodes testing so far was against firmware versions that happened to send +xml, and the multipart path just worked. Your VE firmware is clearly using the shorter MIME type. Appreciate you flagging it with the exact lines and the ManSet workaround, that saves me some back and forth.

I'll push the fix and update the thread once it's in.

loreste avatar Sep 10 '26 10:09 loreste

Hey Fred,

After thinking about it more, I'm going to hold off on adding application/rs-metadata support server-side. RFC 7865 §9.1 explicitly registers the type as application/rs-metadata+xml — the +xml suffix isn't cosmetic, it's the actual registered MIME type. If we start accepting the short form we're basically working around a non-compliant SBC and that's a rabbit hole I'd rather not go down.

Your ManSet manipulation is actually the right fix here — it keeps the SBC sending what the RFC says it should, and you don't have to touch the server. Glad you got it sorted, and thanks for sharing the manipulation rules — that'll be useful for anyone else running into the same thing with AudioCodes firmware that uses the short type.

To answer your question about how we tested without the manipulation: our AudioCodes testing was mostly against Mediant firmware that already sent application/rs-metadata+xml out of the box, so we never ran into it. Sounds like your VE build defaults to the shorter form. Just one of those firmware-version quirks.

loreste avatar Sep 10 '26 10:09 loreste

You're right. Your service strictly follows the RFC, and Audiocode doesn't. That's why I provide you with the manipulation to apply on the outbound side of the SRS trunk. For your information, this virtual cluster is running the last Audiocodes LTS (7.40A.606.123).

FredL45 avatar Sep 10 '26 12:09 FredL45

Understood

On Thu, Sep 10, 2026, 8:30 AM Fred @.***> wrote:

FredL45 left a comment (loreste/siprec#44) https://github.com/loreste/siprec/issues/44#issuecomment-5618691273

You're right. Your service strictly follows the RFC, and Audiocode doesn't. That's why I provide you with the manipulation to apply on the outbound side of the SRS trunk. For your information, this virtual cluster is running the last Audiocodes LTS (7.40A.606.123).

— Reply to this email directly, view it on GitHub https://github.com/loreste/siprec/issues/44?email_source=notifications&email_token=ABOBAMCFDUT72KU4PVNLZED5OKNFJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNRRHA3DSMJSG4Z2M4TFMFZW63VMON2GC5DFL5RWQYLOM5S2KZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5618691273, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOBAMHDRP26BWW4BWWXEQD5OKNFJAVCNFSNUABFKJSXA33TNF2G64TZHM4DGMBWGIZTIOBUHNEXG43VMU5TKNBQGM3TEOJWGM42C5QC . You are receiving this because you modified the open/close state.Message ID: @.***>

loreste avatar Sep 10 '26 16:09 loreste