Skip to content

Commit

Permalink
Merge pull request #60 from KnpLabs/change/add-support-for-wildcards-…
Browse files Browse the repository at this point in the history
…in-authorized-domains

Add support for wildcards in worker renderer authorized domains
  • Loading branch information
alexpozzi authored Jun 16, 2021
2 parents d59c8c0 + 1905da9 commit 4e1e0d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apt-get update \
&& apt-get update \
&& apt-get install -y \
procps=2:3.3.12-3+deb9u1 \
google-chrome-stable=91.0.4472.101-1 \
google-chrome-stable=91.0.4472.106-1 \
fonts-ipafont-gothic=00303-16 \
fonts-wqy-zenhei=0.9.45-6 \
fonts-thai-tlwg=1:0.6.3-1 \
Expand Down
6 changes: 2 additions & 4 deletions src/worker/renderers/chrome/browserRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import { T, anyPass, complement, cond, equals, find, ifElse, isNil, pipe, replac
const resolveRequestDomain = req => req.url().match(/^(https?:\/\/)?(?<host>[^/]+)/).groups.host

// isMatchingDomain :: String -> String -> Boolean
const isMatchingDomain = input => anyPass([
equals('*'),
value => test(new RegExp(`${value}$`, 'i'), input),
])
const isMatchingDomain = input => value =>
test(new RegExp(`^${replace('*', '.*', value)}$`, 'i'), input)

// isRequestDomainAuthorized :: [String] -> Request -> Boolean
const isRequestDomainAuthorized = authorizedRequestDomains => pipe(
Expand Down
4 changes: 2 additions & 2 deletions src/worker/renderers/chrome/browserRequestHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('worker :: renderer :: browserRequestHandler', () => {
const configuration = {
worker: {
renderer: {
authorized_request_domains: ['example.com'],
authorized_request_domains: ['*.example.com'],
authorized_request_resources: ['*'],
redirections: [],
},
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('worker :: renderer :: browserRequestHandler', () => {
const configuration = {
worker: {
renderer: {
authorized_request_domains: ['example.com'],
authorized_request_domains: ['*.example.com'],
authorized_request_resources: ['document'],
redirections: [],
},
Expand Down

0 comments on commit 4e1e0d9

Please sign in to comment.