An invalid domain [.test.com] was specified for this cookie 原因分析
java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
以上博客说明了解决办法以及可能的原因,现在就根据log查看tomcat源码看看是异常的原因以及在tomcat8.5上cookie name的规则。
Rfc6265CookieProcessor源码的167-197行代码如下
private void validateDomain(String domain) {
int i = 0;
int prev = -1;
int cur = -1;
char[] chars = domain.toCharArray();
while (i < chars.length) {
prev = cur;
cur = chars[i];
if (!domainValid.get(cur)) {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidDomain", domain));
}
// labels must start with a letter or number
if ((prev == '.' || prev == -1) && (cur == '.' || cur == '-')) {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidDomain", domain));
}
// labels must end with a letter or number
if (prev == '-' && cur == '.') {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidDomain", domain));
}
i++;
}
// domain must end with a label
if (cur == '.' || cur == '-') {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidDomain", domain));
}
}
domain规则如下
1、必须是1-9、a-z、A-Z、. 、- (注意是-不是_)这几个字符组成
2、必须是数字或字母开头
上篇文章使用.test.com报错就是因为使用”.”开头
3、必须是数字或字母结尾
path的规则源码及规则
private void validatePath(String path) {
char[] chars = path.toCharArray();
for (int i = 0; i < chars.length; i++) {
char ch = chars[i];
if (ch < 0x20 || ch > 0x7E || ch == ';') {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidPath", path));
}
}
}
1、字符必须是在 0x20-0x7E之间,并且不能出现”;”号
cookie value 源码及规则
private void validateCookieValue(String value) {
int start = 0;
int end = value.length();
if (end > 1 && value.charAt(0) == '"' && value.charAt(end - 1) == '"') {
start = 1;
end--;
}
char[] chars = value.toCharArray();
for (int i = start; i < end; i++) {
char c = chars[i];
if (c < 0x21 || c == 0x22 || c == 0x2c || c == 0x3b || c == 0x5c || c == 0x7f) {
throw new IllegalArgumentException(sm.getString(
"rfc6265CookieProcessor.invalidCharInValue", Integer.toString(c)));
}
}
}
1、会自动去除开头和结尾的引号”
2、如果包含以下规则字符则校验失败:
c < 0x21 || c == 0x22 || c == 0x2c || c == 0x3b || c == 0x5c || c == 0x7f
An invalid domain [.test.com] was specified for this cookie 原因分析的更多相关文章
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie解决方法
当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名上存取用户信息. 比如有三个domain分别为test.com,cml.test.com,b.test.com这 ...
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
https://blog.csdn.net/cml_blog/article/details/52135115 当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名 ...
- tomcat 8.5 及其 9.0 response写cookie 设置damain为 [.test.com] 出错 An invalid domain [.test.com] was specified for this cookie
抛出异常: java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cooki ...
- SIP/2.0 403 Forbidden(Invalid domain in From: header)
一.错误场景 FreeSWITCH通过网关和一台支持SIP的网关设备互联,一个呼叫发过去,收到这个错误. FreeSWITCH的地址是192.168.1.99. 网关设备的地址是192.168.1.2 ...
- Invalid bound statement (not found):xxx错误的可能原因
1,报错信息 log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvir ...
- Js添加、读取、删除cookie,判断cookie是否有效,指定domain域下主路径path下设置cookie,设置expires过期时间
有时我们需要用cookie保存用户名,记录登录状态,如何正确判断该机用户cookie是否存在呢?不能简单使用a!=”这样的写法. 正确方法是:判断是否存在名为username3的cookie,使用do ...
- springboot 1.5.x 使用tomcat8设置cookie的domain以dot开头报错
"C:\Program Files\Java\jdk1.7.0_75\bin\java" -XX:TieredStopAtLevel=1 -noverify -Dspring.ou ...
- 记一次升级Tomcat
总述 JDK都要出12了,而我们项目使用的jdk却仍然还停留在JDK1.6.为了追寻技术的发展的脚步,我这边准备将项目升级到JDK1.8.而作为一个web项目,我们的容器使用的是Tomcat. ...
- 踩坑tomcat8.5的cookie机制
https://www.pomelolee.com/1601.html tomcat升级到8.5版本 发现登录和退出报错,报错日志为下 [http-nio-8080-exec-20] 2016 Aug ...
随机推荐
- 词向量表示:word2vec与词嵌入
在NLP任务中,训练数据一般是一句话(中文或英文),输入序列数据的每一步是一个字母.我们需要对数据进行的预处理是:先对这些字母使用独热编码再把它输入到RNN中,如字母a表示为(1, 0, 0, 0, ...
- 2层感知机(神经网络)实现非线性回归(非线性拟合)【pytorch】
import torch import numpy import random from torch.autograd import Variable import torch.nn.function ...
- Java 理解类加载过程 -- 自定义加载器
类加载器可以看下我的收藏: https://www.cnblogs.com/dongguacai/p/5879931.html 现在准备一个字节码文件: 自定义加载器: package com.xzl ...
- Javascript-异步详解
- ES6中对数组的扩展
hello,大家好,我又来了. 前面讲了字符串和数值的扩展,今天要讲的是:数组的扩展.不知道大家能否跟得上这个节奏,你们在阅读中对讲解有存在疑惑,记得留言提出来,要真正地理解,否则白白 ...
- Junit借助Groboutils Core进行并发测试
本文参考:http://www.voidcn.com/article/p-ybnvuffh-ke.html:转载请注明出处 junit是无法进行并发测试,但是又有需要并发测试的场景怎么办呢?此时可以借 ...
- 批量查询PDF文本并导出结果的小工具
效果: 批量查询指定关键字 & 指定目录下PDF文件中的文本,并导出文件路径和关键字所在文本行. 下载: 链接: https://pan.baidu.com/s/1sK2OMMgGX26l7P ...
- php正则验证手机、邮箱
//验证电话private function reg_phone($phone){ if (preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189] ...
- Centos史上新版最详细步骤-Linux无脑命令式oracle11g静默安装
1. 关闭selinux 1.1 sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config 1.2 或者 ...
- 安装 wbemcli
安装环境 建立自己的目录后, wget http://vault.centos.org/6.0/os/x86_64/Packages/sblim-wbemcli- ...