267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#
proc wapp-allow-xorigin-params {} {
global wapp
if {![dict exists $wapp .qp] && ![dict get $wapp SAME_ORIGIN]} {
wappInt-decode-query-params
}
}
# Set the content-security-policy.
#
# The default content-security-policy is very strict: "default-src 'self'"
# The default policy prohibits the use of in-line javascript or CSS.
#
# Provide an alternative CSP as the argument. Or use "off" to disable
# the CSP completely.
#
proc wapp-content-security-policy {val} {
global wapp
if {$val=="off"} {
dict unset wapp .csp
} else {
dict set wapp .csp $val
}
}
# Examine the bodys of all procedures in this program looking for
# unsafe calls to "wapp". Return a text string containing warnings.
# Return an empty string if all is ok.
#
# This routine is advisory only. It misses some constructs that are
# dangerous and flags others that are safe.
|
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
+
|
# invoking [error].
#
proc wappInt-handle-request {chan useCgi} {
global wapp
dict set wapp .reply {}
dict set wapp .mimetype {text/html; charset=utf-8}
dict set wapp .reply-code {200 Ok}
dict set wapp .csp {default-src 'self'}
# Set up additional CGI environment values
#
if {![dict exists $wapp HTTP_HOST]} {
dict set wapp BASE_URL {}
} elseif {[dict exists $wapp HTTPS]} {
dict set wapp BASE_URL https://[dict get $wapp HTTP_HOST]
|
700
701
702
703
704
705
706
707
708
709
710
711
712
713
|
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
|
+
+
+
|
puts $chan "Connection: close\r"
}
if {[dict exists $wapp .reply-extra]} {
foreach {name value} [dict get $wapp .reply-extra] {
puts $chan "$name: $value\r"
}
}
if {[dict exists $wapp .csp]} {
puts $chan "Content-Security-Policy: [dict get $wapp .csp]\r"
}
set mimetype [dict get $wapp .mimetype]
puts $chan "Content-Type: $mimetype\r"
if {[dict exists $wapp .new-cookies]} {
foreach {nm val} [dict get $wapp .new-cookies] {
if {[regexp {^[a-z][-a-z0-9_]*$} $nm]} {
if {$val==""} {
puts $chan "Set-Cookie: $nm=; HttpOnly; Path=/; Max-Age=1\r"
|