Skip to content

Commit

Permalink
lpeg_patterns/http.lua: Add Referrer_Policy pattern
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
daurnimator committed Jul 15, 2018
1 parent 0a20380 commit 5a94ab2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ UNRELEASED
- http: Cache-Control directives are case-normalised and grouped into pairs
- http: Strict_Transport_Security now returns a table and doesn't match on duplicates
- http: Public_Key_Pins capture format and validation
- http: New Expect_CT pattern
- http: New Expect_CT and Referrer_Policy patterns


0.4 - 2016-11-23
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ These patterns should be considered to have non stable APIs.
- `Expect_CT` (pattern)


#### [Referrer-Policy header](https://www.w3.org/TR/referrer-policy/#referrer-policy-header)

- `Referrer_Policy` (pattern)


### `phone`

- `phone` (pattern): includes detailed checking for:
Expand Down
11 changes: 11 additions & 0 deletions lpeg_patterns/http.lua
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,15 @@ _M.Alt_Used = uri.host * (P":" * uri.port)^-1
local expect_ct_directive = directive
_M.Expect_CT = no_dup(comma_sep_trim(expect_ct_directive))

-- https://www.w3.org/TR/referrer-policy/#referrer-policy-header
local policy_token = C"no-referrer"
+ C"no-referrer-when-downgrade"
+ C"strict-origin"
+ C"strict-origin-when-cross-origin"
+ C"same-origin"
+ C"origin"
+ C"origin-when-cross-origin"
+ C"unsafe-url"
_M.Referrer_Policy = comma_sep_trim(policy_token, 1)

return _M

0 comments on commit 5a94ab2

Please sign in to comment.