( lgr logger.Logger, r *http.Request, needsJoinRequest bool, strict bool, )
| 128 | var errJoinRequestTooLarge = errors.New("join request too large") |
| 129 | |
| 130 | func (s *RTCService) validateInternal( |
| 131 | lgr logger.Logger, |
| 132 | r *http.Request, |
| 133 | needsJoinRequest bool, |
| 134 | strict bool, |
| 135 | ) (livekit.RoomName, routing.ParticipantInit, int, error) { |
| 136 | if claims := GetGrants(r.Context()); claims == nil || claims.Video == nil { |
| 137 | return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied |
| 138 | } |
| 139 | |
| 140 | var params ValidateConnectRequestParams |
| 141 | useSinglePeerConnection := false |
| 142 | joinRequest := &livekit.JoinRequest{} |
| 143 | |
| 144 | wrappedJoinRequestBase64 := r.FormValue("join_request") |
| 145 | if wrappedJoinRequestBase64 == "" { |
| 146 | if needsJoinRequest { |
| 147 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("join_request is required") |
| 148 | } |
| 149 | |
| 150 | params.publish = r.FormValue("publish") |
| 151 | |
| 152 | attributesStrParam := r.FormValue("attributes") |
| 153 | if attributesStrParam != "" { |
| 154 | attrs, err := decodeAttributes(attributesStrParam) |
| 155 | if err != nil { |
| 156 | if strict { |
| 157 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot decode attributes") |
| 158 | } |
| 159 | lgr.Debugw("failed to decode attributes", "error", err) |
| 160 | // attrs will be empty here, so just proceed |
| 161 | } |
| 162 | params.attributes = attrs |
| 163 | } |
| 164 | } else { |
| 165 | useSinglePeerConnection = true |
| 166 | if wrappedProtoBytes, err := base64.URLEncoding.DecodeString(wrappedJoinRequestBase64); err != nil { |
| 167 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot base64 decode wrapped join request") |
| 168 | } else { |
| 169 | wrappedJoinRequest := &livekit.WrappedJoinRequest{} |
| 170 | if err := proto.Unmarshal(wrappedProtoBytes, wrappedJoinRequest); err != nil { |
| 171 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal wrapped join request") |
| 172 | } |
| 173 | |
| 174 | switch wrappedJoinRequest.Compression { |
| 175 | case livekit.WrappedJoinRequest_NONE: |
| 176 | if len(wrappedJoinRequest.JoinRequest) > http.DefaultMaxHeaderBytes { |
| 177 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errJoinRequestTooLarge |
| 178 | } |
| 179 | if err := proto.Unmarshal(wrappedJoinRequest.JoinRequest, joinRequest); err != nil { |
| 180 | return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal join request") |
| 181 | } |
| 182 | |
| 183 | case livekit.WrappedJoinRequest_GZIP: |
| 184 | protoBytes, err := DecompressGzip(wrappedJoinRequest.JoinRequest) |
| 185 | if err != nil { |
| 186 | switch { |
| 187 | case errors.Is(err, ErrGzipTooLarge): |
no test coverage detected