【问题标题】:KeyCloak server responds with IllegalArgumentException:An invalid control character was present in the cookie value or attributeKeyCloak 服务器以 IllegalArgumentException 响应:cookie 值或属性中存在无效的控制字符
【发布时间】:2018-05-21 15:42:30
【问题描述】:

我正在尝试使用 KeyCloak 集成来部署和测试简单的 Spring Boot 应用程序。我正在关注这个官方教程:https://blog.keycloak.org/2017/05/easily-secure-your-spring-boot.html。但是我在浏览器中收到错误“此页面无法正常工作”(未显示 KeyCloak 登录页面)并且 KeyCloak 抛出此异常:

IllegalArgumentException:    An invalid control character was present in the 
cookie value or attribute

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.13.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <keycloak.version>3.3.0.Final</keycloak.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.keycloak.bom</groupId>
            <artifactId>keycloak-adapter-bom</artifactId>
            <version>${keycloak.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

这是异常日志:

09:55:18,976 ERROR [io.undertow.request] (default task-7) UT005071: Undertow 
req
uest failed HttpServerExchange{ GET /auth/ request {Accept= 
[text/html,applicatio
n/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8], Accept- 
Langu
age=[en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7], Cache-Control=[max-age=0], 
Accept-Enc
 oding=[gzip, deflate, br], User-Agent=[Mozilla/5.0 (Windows NT 6.1; Win64; 
x64)
 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36], 
Conn
ection=[keep-alive], Cookie=[OAuth_Token_Request_State=2132636f-ed6a-44e2- 
915b-9
cefed4dc446; JSESSIONID=D0DA2ADDBE8F62E55C9F65EB71BE85A0], Referer= 
[http://local
host:8080/], Upgrade-Insecure-Requests=[1], Host=[localhost:8080]} response 
{Cac
he-Control=[no-cache, must-revalidate, no-transform, no-store], X-Powered- 
By=[Un
dertow/1], Server=[WildFly/11], X-XSS-Protection=[1; mode=block], X-Frame- 
Option s=[SAMEORIGIN], Content-Security-Policy=[frame-src 'self'; frame 
ancestors 
'self
'; object-src 'none';], Date=[Wed, 23 May 2018 03:55:18 GMT], Connection= 
[keep-a
live], X-Robots-Tag=[none], X-Content-Type-Options=[nosniff], Content-Type= 
[text
/html;charset=utf-8], Content-Length=[2740]}}: 
 java.lang.IllegalArgumentExceptio
 n: UT000173: An invalid control character [1087] was present in the cookie 
 value
 or attribute
    at io.undertow.util.LegacyCookieSupport.isHttpSeparator(LegacyCookieSupp
  ort.java:142)
    at io.undertow.util.LegacyCookieSupport.isHttpToken(LegacyCookieSupport.
 java:163)
    at io.undertow.util.LegacyCookieSupport.adjustedCookieVersion(LegacyCook
 ieSupport.java:248)
    at io.undertow.server.Connectors.getCookieString(Connectors.java:154)
    at io.undertow.server.Connectors.flattenCookies(Connectors.java:99)
    at io.undertow.server.protocol.http.HttpResponseConduit.processWrite(Htt
 pResponseConduit.java:161)
    at io.undertow.server.protocol.http.HttpResponseConduit.write(HttpRespon
 seConduit.java:596)
    at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.write(Abstr
 actFixedLengthStreamSinkConduit.java:106)
    at org.xnio.conduits.Conduits.writeFinalBasic(Conduits.java:132)
    at io.undertow.conduits.AbstractFixedLengthStreamSinkConduit.writeFinal(
  AbstractFixedLengthStreamSinkConduit.java:175)
    at org.xnio.conduits.ConduitStreamSinkChannel.writeFinal(ConduitStreamSi
 nkChannel.java:104)
    at io.undertow.channels.DetachableStreamSinkChannel.writeFinal(Detachabl
 eStreamSinkChannel.java:195)
    at io.undertow.server.HttpServerExchange$WriteDispatchChannel.writeFinal
 (HttpServerExchange.java:2042)
    at io.undertow.servlet.spec.ServletOutputStreamImpl.writeBufferBlocking(
 ServletOutputStreamImpl.java:568)
    at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputS
 treamImpl.java:603)
    at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter
 (HttpServletResponseImpl.java:479)
    at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpSer
 vletResponseImpl.java:568)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest
  (ServletInitialHandler.java:339)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(Servlet
 InitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInit
 ialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInit
 ialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.cal
 l(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(Context
 ClassLoaderSetupAction.java:43)
    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAct
 ion.lambda$create$0(SecurityContextThreadSetupAction.java:105)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java : 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoServi

ce$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java: 1508) 在 io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(Se rvletInitialHandler.java:272) 在 io.undertow.servlet.handlers.ServletInitialHandler.access$000(Servlet InitialHandler.java:81) 在 io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(Se rvletInitialHandler.java:104) 在 io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)

    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:8
12)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:624)
    at java.lang.Thread.run(Thread.java:748)

如果我清除浏览数据 keycloak 将起作用,但无论如何在我部署我的应用程序并单击“我的产品”后,我再次遇到相同的异常......

有什么猜测吗?

【问题讨论】:

  • 您使用的是哪个版本?我在 Keycloak 和 Spring 中都找不到该消息。
  • @KoheiTAMURA 我正在使用 keycloak-3.3.0.Final 和 SpringBoot v.1.5.13.RELEASE
  • IllegalArgumentException 是从 Undertow 中的 LegacyCookieSupport.isV0Separator()LegacyCookieSupport.isHttpSeparator() 抛出的。您可能有一个无效的 cookie。另见:github.com/undertow-io/undertow/blob/master/core/src/main/java/…
  • @KoheiTAMURA 伙计,我可以拥有你的 facebook 或 smth 吗?我在身份验证方面很新,从未使用过 JBoss。可能是因为我连接到公司网络?顺便说一句,在我安装 keycloak 3.3.0 之前,我首先安装了 keycloak 4.4.0.Beta 和 SpringBoot 2.2.0。在我遇到错误之后,我关注了官方文档,发现在教程中他们使用 keycloak-3.3.0 而 SpringBoot 2 还不支持 keycloak 适配器。
  • 你能提供异常的堆栈跟踪吗?如果有,请编辑您的问题并添加(粘贴)它。

标签: java spring-boot keycloak


【解决方案1】:

哈哈!解决方案很愚蠢...我的电脑名称...我的电脑名称是 Talgat-ПК。 П 和 К 是俄语字母...在我将其重命名为 Talgat-PC 后,一切都开始正常工作了。

【讨论】:

    【解决方案2】:

    日期区域时间设置可能有误。您可以将“-Duser.language=en -Duser.country=US”设置为系统变量

    【讨论】:

      猜你喜欢
      • 2012-02-24
      • 2018-01-24
      • 1970-01-01
      • 2019-03-02
      • 2020-04-21
      • 2012-09-23
      • 2020-10-09
      • 2017-06-10
      • 1970-01-01
      相关资源
      最近更新 更多