После обновления до 7.2.20 ошибка cors

Добрый день. После обновления до 7.2.20 при входе по rest api выдает ошибку

java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

Добрый день!
Ошибка возникает в момент получения access token?
Какая у вас версия аддона rest api прописана в build.gradle?

appComponent('com.haulmont.addon.restapi:restapi-global:7.2.4')

Добрый день.
Да, ошибка возникает при получении access token. restapi версия 7.2.4.

При возврате на версию cuba 7.2.19 все работает

В новом проекте у вас это воспроизводится? Можете привести шаги для получения ошибки и полный стектрейс?
Я сейчас сделал новый проект, получил в нём токен, и всё прошло нормально.

Новый пустой проект только с подключенным rest-api аддоном.
rest.zip (105.6 КБ)

Шаги по воспроизведению:

  1. Запустить проект.
  2. Вызвать метод получения токена POST на localhost:8080/app/rest/v2/oauth/token?grant_type=password&username=admin&password=admin с базовой авторизацией.

Ожидаемый результат: возвращается json с токенами.
Фактический результат: возвращается html страница с ошибкой. В логах приложения ничего нет.

<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> When allowCredentials is true, allowedOrigins cannot contain the special value &quot;*&quot; since that cannot be set on the &quot;Access-Control-Allow-Origin&quot; response header. To allow credentials to a set of origins, list them explicitly or consider using &quot;allowedOriginPatterns&quot; instead.</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value &quot;*&quot; since that cannot be set on the &quot;Access-Control-Allow-Origin&quot; response header. To allow credentials to a set of origins, list them explicitly or consider using &quot;allowedOriginPatterns&quot; instead.
	org.springframework.web.cors.CorsConfiguration.validateAllowCredentials(CorsConfiguration.java:473)
	org.springframework.web.cors.CorsConfiguration.checkOrigin(CorsConfiguration.java:577)
	org.springframework.web.cors.DefaultCorsProcessor.checkOrigin(DefaultCorsProcessor.java:174)
	org.springframework.web.cors.DefaultCorsProcessor.handleInternal(DefaultCorsProcessor.java:116)
	org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:95)
	org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:87)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92)
	org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
	org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
	org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)
	org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
	org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74)
	com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93)
</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" /><h3>Apache Tomcat/9.0.38</h3></body></html>

Причина ошибки видимо в связке allowCredentials=true и allowedOrigins=* что используется по умолчанию через свойство cuba.rest.allowedOrigins.

Там для этого появилось новое свойство allowedOriginPatterns что поддерживает эту комбинацию.

Как обходной временный путь надо создать rest-dispatcher-spring.xml и переопределить бин:

<bean id="cuba_RestCorsConfig" class="org.springframework.web.cors.CorsConfiguration">
    <!--<property name="allowedOrigins" value="${cuba.rest.allowedOrigins}"/>-->
    <property name="allowedOriginPatterns" value="${cuba.rest.allowedOrigins}"/>
    <property name="allowedHeaders" value="*"/>
    <property name="allowedMethods" value="*"/>
    <property name="allowCredentials" value="true"/>
    <property name="exposedHeaders">
        <list>
            <value>X-Total-Count</value>
            <value>Content-Disposition</value>
        </list>
    </property>
</bean>
1 симпатия

Спасибо, удалось получить ошибку. Завели тикет. В ближайшие дни постараемся выпустить фикс для restapi аддона.

1 симпатия