diff --git a/apps/capi/src/capi_handler_decoder.erl b/apps/capi/src/capi_handler_decoder.erl index e28b68e..b904b8c 100644 --- a/apps/capi/src/capi_handler_decoder.erl +++ b/apps/capi/src/capi_handler_decoder.erl @@ -95,11 +95,11 @@ decode_deadline(Deadline) -> decode_client_info(undefined) -> undefined; decode_client_info(ClientInfo) -> - #{ + genlib_map:compact(#{ <<"fingerprint">> => ClientInfo#domain_ClientInfo.fingerprint, <<"ip">> => ClientInfo#domain_ClientInfo.ip_address, <<"url">> => ClientInfo#domain_ClientInfo.url - }. + }). %% diff --git a/apps/capi/src/capi_handler_tokens.erl b/apps/capi/src/capi_handler_tokens.erl index 6cb5bb8..d7a49a7 100644 --- a/apps/capi/src/capi_handler_tokens.erl +++ b/apps/capi/src/capi_handler_tokens.erl @@ -81,10 +81,10 @@ process_request('CreatePaymentResource' = OperationID, Req, Context, Resolution) end end, - ClientInfo = maps:put(<<"ip">>, ClientIP, ClientInfo0), + ClientInfo1 = maps:put(<<"ip">>, ClientIP, ClientInfo0), try - ClientUrl = get_client_url(ClientInfo), - ok = validate_url(ClientUrl), + ClientUrl = get_client_url(ClientInfo1), + ClientInfo = maps:put(<<"url">>, ClientUrl, ClientInfo1), Data = maps:get(<<"paymentTool">>, Params), PartyID = capi_handler_utils:get_party_id(Context), ExternalID = maps:get(<<"externalID">>, Params, undefined), @@ -150,14 +150,17 @@ get_replacement_ip(ClientInfo) -> maps:get(<<"ip">>, ClientInfo, undefined). get_client_url(ClientInfo) -> - maps:get(<<"url">>, ClientInfo, undefined). + case maps:get(<<"url">>, ClientInfo, undefined) of + undefined -> + undefined; + Url -> + delete_query_params(Url) + end. -validate_url(undefined) -> - ok; -validate_url(Url) -> - case capi_utils:validate_url(Url) of - ok -> - ok; +delete_query_params(Url) -> + case capi_utils:delete_url_query_params(Url) of + {ok, UrlWithoutParams} -> + UrlWithoutParams; {error, Error, Description} -> _ = logger:notice("Unexpected client info url reason: ~p ~p", [Error, Description]), throw({ok, logic_error(invalidRequest, <<"Client info url is invalid">>)}) diff --git a/apps/capi/src/capi_utils.erl b/apps/capi/src/capi_utils.erl index 175b419..18ec701 100644 --- a/apps/capi/src/capi_utils.erl +++ b/apps/capi/src/capi_utils.erl @@ -11,7 +11,7 @@ -export([base64url_to_map/1]). -export([map_to_base64url/1]). --export([validate_url/1]). +-export([delete_url_query_params/1]). -export([parse_deadline/1]). -export([parse_lifetime/1]). @@ -52,13 +52,14 @@ base64url_to_map(Base64) when is_binary(Base64) -> map_to_base64url(Map) when is_map(Map) -> jose_base64url:encode(jsx:encode(Map)). --spec validate_url(binary()) -> ok | uri_string:error(). -validate_url(Url) -> +-spec delete_url_query_params(binary()) -> {ok, binary()} | uri_string:error(). +delete_url_query_params(Url) -> case uri_string:parse(Url) of {error, _, _} = Error -> Error; - UriMap when is_map(UriMap) -> - ok + UriMap1 when is_map(UriMap1) -> + UriMap2 = maps:without([query, fragment], UriMap1), + {ok, uri_string:recompose(UriMap2)} end. -spec to_universal_time(Timestamp :: binary()) -> TimestampUTC :: binary().