Skip to content
Snippets Groups Projects
Commit 25111b46 authored by stuebinm's avatar stuebinm
Browse files

linter: allow unrestricted domain scopes

parent 8a0a463f
No related branches found
No related tags found
No related merge requests found
...@@ -3,23 +3,16 @@ ...@@ -3,23 +3,16 @@
"Assemblies":[], "Assemblies":[],
"ScriptInject":null, "ScriptInject":null,
"AllowScripts":false, "AllowScripts":false,
"MaxLintLevel":"Warning", "MaxLintLevel":"Fatal",
"DontCopyAssets":false, "DontCopyAssets":false,
"UriSchemas": [ "UriSchemas": {
["https", { "world": {
"scope" : ["website"],
"allowed" : ["media.ccc.de", "streaming.media.ccc.de", "static.rc3.world", "cdn.c3voc.de", "pretalx.c3voc.de"],
"blocked" : ["blocked.com"],
"prefix" : "https:\/\/rc3.world\/2021\/wa_dereferrer\/"
}],
["https", {
"scope" : ["audio"],
"allowed" : ["cdn.c3voc.de", "media.ccc.de", "streaming.media.ccc.de", "static.rc3.world", "live.dort.c3voc.de"]
}],
["world", {
"scope" : ["map"], "scope" : ["map"],
"substs" : { "substs" : {
} }
}] },
] "https": {
"scope" : [ "website", "audio" ]
}
}
} }
...@@ -23,6 +23,7 @@ data Substitution = ...@@ -23,6 +23,7 @@ data Substitution =
Prefixed { prefix :: Text, blocked :: [Text], allowed :: [Text], scope :: [String] } Prefixed { prefix :: Text, blocked :: [Text], allowed :: [Text], scope :: [String] }
| DomainSubstitution { substs :: Map Text Text, scope :: [String] } | DomainSubstitution { substs :: Map Text Text, scope :: [String] }
| Allowed { scope :: [String], allowed :: [Text] } | Allowed { scope :: [String], allowed :: [Text] }
| Unrestricted { scope :: [String] }
deriving (Generic, Show) deriving (Generic, Show)
...@@ -32,7 +33,7 @@ instance FromJSON Substitution where ...@@ -32,7 +33,7 @@ instance FromJSON Substitution where
, rejectUnknownFields = True , rejectUnknownFields = True
} }
type SchemaSet = [(Text, Substitution)] type SchemaSet = Map Text Substitution
extractDomain :: Text -> Maybe Text extractDomain :: Text -> Maybe Text
...@@ -78,20 +79,17 @@ applySubsts s substs uri = do ...@@ -78,20 +79,17 @@ applySubsts s substs uri = do
$ Left VarsDisallowed $ Left VarsDisallowed
parts@(schema, _, _) <- note NotALink $ parseUri uri parts@(schema, _, _) <- note NotALink $ parseUri uri
let rules = filter ((==) schema . fst) substs let rule = M.lookup schema substs
case nonEmpty (map (applySubst parts . snd) rules) of case map (applySubst parts) rule of
Nothing -> Left (SchemaDoesNotExist schema) Nothing -> Left (SchemaDoesNotExist schema)
Just results -> case rights (toList results) of Just result -> result
suc:_ -> Right suc
_ -> minimum results
where where
note = maybeToRight note = maybeToRight
applySubst (schema, domain, rest) rule = do applySubst (schema, domain, rest) rule = do
unless (symbolVal s `elem` scope rule) unless (symbolVal s `elem` scope rule)
$ Left (WrongScope schema $ Left (WrongScope schema
(fmap fst . filter (elem (symbolVal s) . scope . snd) $ substs)) (map fst . filter (elem (symbolVal s) . scope . snd) $ toPairs substs))
case rule of case rule of
DomainSubstitution table _ -> do DomainSubstitution table _ -> do
prefix <- note (DomainDoesNotExist (schema <> toText "://" <> domain)) prefix <- note (DomainDoesNotExist (schema <> toText "://" <> domain))
...@@ -105,3 +103,4 @@ applySubsts s substs uri = do ...@@ -105,3 +103,4 @@ applySubsts s substs uri = do
|| toText "streamproxy.rc3.world" `T.isSuffixOf` domain || toText "streamproxy.rc3.world" `T.isSuffixOf` domain
then Right uri then Right uri
else Left (DomainIsBlocked domains) else Left (DomainIsBlocked domains)
Unrestricted _ -> Right uri
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment