summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2018-10-15 10:28:23 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2018-10-15 10:28:23 (GMT)
commit4e90ee366b9b506e30bec5b99d0cc4d759ce2a44 (patch)
tree18480964fbd37db64c493ecb32c7eb2c6a8faf80 /library
parent76c979e748b7b450e7e38daf801ca1b7d725b074 (diff)
downloadtcl-4e90ee366b9b506e30bec5b99d0cc4d759ce2a44.zip
tcl-4e90ee366b9b506e30bec5b99d0cc4d759ce2a44.tar.gz
tcl-4e90ee366b9b506e30bec5b99d0cc4d759ce2a44.tar.bz2
Make it easier to extend cookiejar for policy reasons
Diffstat (limited to 'library')
-rw-r--r--library/http/cookiejar.tcl18
1 files changed, 18 insertions, 0 deletions
diff --git a/library/http/cookiejar.tcl b/library/http/cookiejar.tcl
index 1fc1ffe..309ca7a 100644
--- a/library/http/cookiejar.tcl
+++ b/library/http/cookiejar.tcl
@@ -589,6 +589,12 @@ package provide cookiejar \
return 0
}
+ # A defined extension point to allow users to easily impose extra policies
+ # on whether to accept cookies from a particular domain and path.
+ method policyAllow {operation domain path} {
+ return true
+ }
+
method storeCookie {options} {
db transaction {
if {[my BadDomain $options]} {
@@ -598,6 +604,10 @@ package provide cookiejar \
set persistent [dict exists $options expires]
dict with options {}
if {!$persistent} {
+ if {![my policyAllow session $domain $path]} {
+ log warn "bad cookie: $domain prohibited by user policy"
+ return
+ }
db eval {
INSERT OR REPLACE INTO sessionCookies (
secure, domain, path, key, value, originonly, creation,
@@ -612,6 +622,10 @@ package provide cookiejar \
log debug "defined session cookie for %s" \
[locn $secure $domain $path $key]
} elseif {$expires < $now} {
+ if {![my policyAllow delete $domain $path]} {
+ log warn "bad cookie: $domain prohibited by user policy"
+ return
+ }
db eval {
DELETE FROM persistentCookies
WHERE domain = $domain AND path = $path AND key = $key
@@ -627,6 +641,10 @@ package provide cookiejar \
log debug "deleted %d cookies for %s" \
$del [locn $secure $domain $path $key]
} else {
+ if {![my policyAllow set $domain $path]} {
+ log warn "bad cookie: $domain prohibited by user policy"
+ return
+ }
db eval {
INSERT OR REPLACE INTO persistentCookies (
secure, domain, path, key, value, originonly, expiry,