Coder Social home page Coder Social logo

SetCookie() 存在Bug about webapiclient HOT 5 CLOSED

dotnetcore avatar dotnetcore commented on June 28, 2024
SetCookie() 存在Bug

from webapiclient.

Comments (5)

xljiulang avatar xljiulang commented on June 28, 2024

Cookie只支持单字节字符,格式为{key}={value},等号是关键字,如果{key}或{value}包含等号,应该在应用层处理。你的代码想处理等号,但没有考虑{key}包含等号的情况。

from webapiclient.

CodeForCSharp avatar CodeForCSharp commented on June 28, 2024

我的代码是按照浏览器默认情况去写的,并且也只是保证了基本正确而已,因为Cookie有很多特殊情况我的代码并没有处理。浏览器的默认设置是把第一个=当作分割符,所以在实践上应该是不会有人在Name里面加入=的。就标准来说,并没有规定什么关键字,而且=号并不特别,反而是逗号,分号,空格是不允许出现的。
这里参考的标准是NetSpace发布的Spec Spec
当然后面有更为严格的标准出现,那就是RFC6265,它规定了Name只能包含 !#$%&'*+-.^_|~ 这些其他字符,Value只能包含 !#$%&'()*+-./:<=>?@[]^_{|}~ 这些其他字符。
这里参考的标准是RFC 6265 第4.1.1节,里面引用的是RFC 2616的2.2节。
所以我觉得这个代码应该是满足我自己描述的需求的。

from webapiclient.

xljiulang avatar xljiulang commented on June 28, 2024

增加了一个代码提交,类似PHP的SetCookie和SetRawCookie两个Api,HeaderAttribute增加EncodeCookie属性用于选择使用SetCookie或SetRawCookie,默认为true;两个Api都调用HttpUtility的IEnumerable ParseCookie(string cookieValues, bool useUrlEncode)方法。

from webapiclient.

CodeForCSharp avatar CodeForCSharp commented on June 28, 2024

对了,我上面说这里还有很多特殊情况,我也一个个列出来,你看看你要不要去处理(这里指的是浏览器的一些行为,其实都是因为标准写的太烂,所以才那么多诡异的东西)。
1.Name或Value是空字符串应该也是可以被接受的。
2.不包含=的语句当作Name为空,比如value等价于=value。
3.控制字符不被允许。
4.允许出现空格和逗号之类的只要不是在value的前后就可以。
好像大概就这些吧,你可以考虑一下。

from webapiclient.

xljiulang avatar xljiulang commented on June 28, 2024

.net的Cookie类内部也做了验证处理,其实现为不支持空的name,value前后可以为空格。

from webapiclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.