2010-05-19 5 views

답변

4

HttpApp.pas에서 TCookie에 대해 이야기하면 HttpOnly를 지원하는 속성이 내장되어 있지 않습니다.

TCookie.GetHeaderValue: string; 구현에서 httpApp.pas를 확인하여 확인할 수 있습니다.

그러나 쿠키는 헤더에 설정되어 있으며 TWebResponse에는 CustomHeaders 속성이 있습니다. 호출 할 수있는 곳 Response.CustomHeaders.Add(MyCookieValue);

다음 클래스는 쿠키를 올바르게 생성하는 데 사용할 수있는 HttpOnly를 지원하는 TCookie의 수정 된 버전입니다.

unit CookieGen; 

interface 
uses 
Sysutils,Classes,HttpApp; 
type 
    TCookieGenerator = class(TObject) 
    private 
    FName: string; 
    FValue: string; 
    FPath: string; 
    FDomain: string; 
    FExpires: TDateTime; 
    FSecure: Boolean; 
    FHttpOnly: Boolean; 
    protected 
    function GetHeaderValue: string; 
    public 
    property Name: string read FName write FName; 
    property Value: string read FValue write FValue; 
    property Domain: string read FDomain write FDomain; 
    property Path: string read FPath write FPath; 
    property Expires: TDateTime read FExpires write FExpires; 
    property Secure: Boolean read FSecure write FSecure; 
    property HttpOnly : Boolean read FHttpOnly write FHttpOnly; 
    property HeaderValue: string read GetHeaderValue; 
    end; 

implementation 

{ TCookieGenerator } 

function TCookieGenerator.GetHeaderValue: string; 
begin 
    Result := Format('%s=%s; ', [HTTPEncode(FName), HTTPEncode(FValue)]); 
    if Domain <> '' then 
    Result := Result + Format('domain=%s; ', [Domain]); { do not localize } 
    if Path <> '' then 
    Result := Result + Format('path=%s; ', [Path]);  { do not localize } 
    if Expires > -1 then 
    Result := Result + 
     Format(FormatDateTime('"expires="' + sDateFormat + ' "GMT; "', Expires), { do not localize } 
     [DayOfWeekStr(Expires), MonthStr(Expires)]); 
    if Secure then Result := Result + 'secure; '; { do not localize } 
    if HttpOnly then Result := Result + 'HttpOnly'; { do not localize } 
    if Copy(Result, Length(Result) - 1, MaxInt) = '; ' then 
    SetLength(Result, Length(Result) - 2); 

end; 

end. 
0

> 만료되면 잘못된 헤더를 생성 할 수있는 원래의 HTTPApp.pas TCookie.GetHeaderValue() 메소드 -1주의 사항과 시스템/애플리케이션이 시간 분리 콜론 기호 이외 "". TCookie.GetHeaderValue() 메서드는 "Expires"필드의 서식을 지정하기 위해 상수 sDateFormat을 사용합니다. "다음,이 만료 시간이 다른 문자를 사용하여 형식의 것,하지 :

const 
    sDateFormat = '"%s", dd "%s" yyyy hh:nn:ss'; 

사용자가 콜론 기호 이외의 다른 응용 프로그램 TimeSeparator 변수를 변경하는 경우는": "sDateFormat 상수가 잘못 정의되어 있는지 밝혀 : RFC 1123 ("Wdy, DD Mon YYYY HH : MM : SS GMT"형식)에 지정된대로. Google 크롬 25+는 콜론 기호 이외의 시간 구분 기호로 쿠키를 거부하므로이를 사용하는 웹 응용 프로그램의 완전한 실패를 초래합니다. 올바른 GetHeaderValue() 메소드는 다음과 같아야합니다.

function TCookieGenerator.GetHeaderValue: string; 
const 
    _DateFormat = '"%s", dd "%s" yyyy hh":"nn":"ss'; // this is the correct constant. HTTPApp.pas wrongly declares it as sDateFormat = '"%s", dd "%s" yyyy hh:nn:ss'; 
begin 
    Result := Format('%s=%s; ', [HTTPEncode(FName), HTTPEncode(FValue)]); 
    if Domain <> '' then 
    Result := Result + Format('domain=%s; ', [Domain]); { do not localize } 
    if Path <> '' then 
    Result := Result + Format('path=%s; ', [Path]);  { do not localize } 
    if Expires > -1 then 
    Result := Result + 
     Format(FormatDateTime('"expires="' + _DateFormat + ' "GMT; "', Expires), { do not localize } 
     [DayOfWeekStr(Expires), MonthStr(Expires)]); 
    if Secure then Result := Result + 'secure; '; { do not localize } 
    if HttpOnly then Result := Result + 'HttpOnly'; { do not localize } 
    if Copy(Result, Length(Result) - 1, MaxInt) = '; ' then 
    SetLength(Result, Length(Result) - 2); 
end; 

이에 대한 QC# 113139를 제출했습니다.

관련 문제