packages feed

dhscanner-kbgen 1.0.23 → 1.0.24

raw patch · 2 files changed

+131/−69 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Kbgen: ClassNamedSuper :: Class -> SuperName -> ClassNamedSuper
- Kbgen: ClassNamedSuperCtor :: ClassNamedSuper -> Fact
- Kbgen: data ClassNamedSuper
- Kbgen: instance Data.Aeson.Types.FromJSON.FromJSON Kbgen.ClassNamedSuper
- Kbgen: instance Data.Aeson.Types.ToJSON.ToJSON Kbgen.ClassNamedSuper
- Kbgen: instance GHC.Classes.Eq Kbgen.ClassNamedSuper
- Kbgen: instance GHC.Classes.Ord Kbgen.ClassNamedSuper
- Kbgen: instance GHC.Generics.Generic Kbgen.ClassNamedSuper
- Kbgen: instance GHC.Show.Show Kbgen.ClassNamedSuper
+ Kbgen: CallMethodOfUntypedNamedParam :: Param -> ParamName -> MethodName -> CallMethodOfUntypedNamedParam
+ Kbgen: CallMethodOfUntypedNamedParamCtor :: CallMethodOfUntypedNamedParam -> Fact
+ Kbgen: data CallMethodOfUntypedNamedParam
+ Kbgen: instance Data.Aeson.Types.FromJSON.FromJSON Kbgen.CallMethodOfUntypedNamedParam
+ Kbgen: instance Data.Aeson.Types.ToJSON.ToJSON Kbgen.CallMethodOfUntypedNamedParam
+ Kbgen: instance GHC.Classes.Eq Kbgen.CallMethodOfUntypedNamedParam
+ Kbgen: instance GHC.Classes.Ord Kbgen.CallMethodOfUntypedNamedParam
+ Kbgen: instance GHC.Generics.Generic Kbgen.CallMethodOfUntypedNamedParam
+ Kbgen: instance GHC.Show.Show Kbgen.CallMethodOfUntypedNamedParam

Files

dhscanner-kbgen.cabal view
@@ -33,7 +33,7 @@         * explain in plain English your query's purpose
         * et voilà !
 
-version:            1.0.23
+version:            1.0.24
 license:            GPL-3.0-only
 license-file:       LICENSE
 author:             OrenGitHub
@@ -45,7 +45,7 @@ 
 common ghc_options
 
-    ghc-options: -Wall -O2
+    ghc-options: -Wall -Werror=incomplete-patterns -O2
 
 library
 
src/Kbgen.hs view
@@ -62,7 +62,7 @@     MethodOfClass(..),
     ClassHas1stPartySuper(..),
     ClassHas3rdPartySuper(..),
-    ClassNamedSuper(..),
+    CallMethodOfUntypedNamedParam(..),
     ArgiForCall(..),
     DataflowEdge(..),
     ConstBoolTrue(..),
@@ -309,21 +309,18 @@ -- This is how the fact will look inside the Prolog file
 --
 -- @
--- kb_call_method_of_class( Call, Method, Class ).
+-- kb_class_has_1st_party_super( Class, SuperName, SuperDefinedInFile ).
 -- @
 --
 -- __When should I use this fact__ ( motivation: [CVE-2024-53995](https://nvd.nist.gov/vuln/detail/CVE-2024-53995) )
 --
 -- @
+-- # authentication.py
+-- class LoginHandler(BaseHandler): ...
+--
 -- # index.py
 -- from tornado.web import RequestHandler
 -- class BaseHandler(RequestHandler): ...
---
--- # authentication.py
--- class LoginHandler(BaseHandler):
---     def post(self, ...):
---         n = self.get_query_argument("next", ...)
---         self.redirect(n or ...)
 -- @
 --
 -- See complete source example [here](https://github.com/SickChill/sickchill/blob/846adafdfab579281353ea08a27bbb813f9a9872/sickchill/views/authentication.py#L10),
@@ -333,45 +330,22 @@ -- __Writing a predicate with this fact and others__ ( motivation: [CVE-2024-53995](https://nvd.nist.gov/vuln/detail/CVE-2024-53995) )
 --
 -- @
--- user_controlled_query_argument( Call ) :-
---     kb_call_method_of_class( Call, \'get_query_argument\', Class ),
---     kb_class_has_3rd_party_super( Class, \'tornado.web.RequestHandler\'),
---     kb_arg_i_for_call( QueryParamName, 0, Call),
---     kb_const_string( QueryParamName, _ ).
+-- skip_level_subclass_of( Subclass, \'tornado.web.RequestHandler\' ) :-
+--     kb_class_def( Subclass, _, _ ),
+--     kb_class_has_1st_party_super( Subclass, ClassName, ClassDefinedInFile ),
+--     kb_class_def( Class, ClassName, ClassDefinedInFile )
+--     kb_class_has_3rd_party_super( Class, _, \'tornado.web.RequestHandler\' ).
 -- @
 --
 -- Other facts combined in this predicate:
 --
+--     * 'ClassDef'
 --     * 'ClassHas3rdPartySuper'
---     * 'ArgiForCall'
---     * 'ConstString'
 --
-data CallMethodOfClass = CallMethodOfClass
-    Call -- ^
-    MethodName -- ^
-    Class -- ^
-    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
-
--- |
---
--- Usage:
---
--- @
--- kb_subclass_of( Class, SuperName ).
--- @
---
--- * usually used with 'ClassResolvedSuper'
--- * for bounded inheritance of third party classes
---
--- ==== __Example:__
---
--- @
--- kb_class_name(Class,ClassName).
--- @
---
-data ClassNamedSuper = ClassNamedSuper
+data ClassHas1stPartySuper = ClassHas1stPartySuper
     Class -- ^
     Token.SuperName -- ^
+    SuperDefinedInFile -- ^
     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
 
 -- |
@@ -381,7 +355,7 @@ -- This is how the fact will look inside the Prolog file
 --
 -- @
--- kb_class_has_1st_party_super( Class, SuperName, SuperDefinedInFile ).
+-- kb_class_has_3rd_party_super( Class, SuperName, SuperQualifiedName ).
 -- @
 --
 -- __When should I use this fact__ ( motivation: [CVE-2024-53995](https://nvd.nist.gov/vuln/detail/CVE-2024-53995) )
@@ -412,12 +386,12 @@ -- Other facts combined in this predicate:
 --
 --     * 'ClassDef'
---     * 'ClassHas3rdPartySuper'
+--     * 'ClassHas1stPartySuper'
 --
-data ClassHas1stPartySuper = ClassHas1stPartySuper
+data ClassHas3rdPartySuper = ClassHas3rdPartySuper
     Class -- ^
     Token.SuperName -- ^
-    SuperDefinedInFile -- ^
+    SuperQualifiedName -- ^
     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
 
 -- |
@@ -427,18 +401,21 @@ -- This is how the fact will look inside the Prolog file
 --
 -- @
--- kb_class_has_3rd_party_super( Class, SuperName, SuperQualifiedName ).
+-- kb_call_method_of_class( Call, Method, Class ).
 -- @
 --
 -- __When should I use this fact__ ( motivation: [CVE-2024-53995](https://nvd.nist.gov/vuln/detail/CVE-2024-53995) )
 --
 -- @
--- # authentication.py
--- class LoginHandler(BaseHandler): ...
---
 -- # index.py
 -- from tornado.web import RequestHandler
 -- class BaseHandler(RequestHandler): ...
+--
+-- # authentication.py
+-- class LoginHandler(BaseHandler):
+--     def post(self, ...):
+--         n = self.get_query_argument("next", ...)
+--         self.redirect(n or ...)
 -- @
 --
 -- See complete source example [here](https://github.com/SickChill/sickchill/blob/846adafdfab579281353ea08a27bbb813f9a9872/sickchill/views/authentication.py#L10),
@@ -448,25 +425,74 @@ -- __Writing a predicate with this fact and others__ ( motivation: [CVE-2024-53995](https://nvd.nist.gov/vuln/detail/CVE-2024-53995) )
 --
 -- @
--- skip_level_subclass_of( Subclass, \'tornado.web.RequestHandler\' ) :-
---     kb_class_def( Subclass, _, _ ),
---     kb_class_has_1st_party_super( Subclass, ClassName, ClassDefinedInFile ),
---     kb_class_def( Class, ClassName, ClassDefinedInFile )
---     kb_class_has_3rd_party_super( Class, _, \'tornado.web.RequestHandler\' ).
+-- user_controlled_query_argument( Call ) :-
+--     kb_call_method_of_class( Call, \'get_query_argument\', Class ),
+--     kb_class_has_3rd_party_super( Class, \'tornado.web.RequestHandler\'),
+--     kb_arg_i_for_call( QueryParamName, 0, Call),
+--     kb_const_string( QueryParamName, _ ).
 -- @
 --
 -- Other facts combined in this predicate:
 --
---     * 'ClassDef'
---     * 'ClassHas1stPartySuper'
+--     * 'ClassHas3rdPartySuper'
+--     * 'ArgiForCall'
+--     * 'ConstString'
 --
-data ClassHas3rdPartySuper = ClassHas3rdPartySuper
+data CallMethodOfClass = CallMethodOfClass
+    Call -- ^
+    MethodName -- ^
     Class -- ^
-    Token.SuperName -- ^
-    SuperQualifiedName -- ^
     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
 
 -- |
+--
+-- __Name__
+--
+-- This is how the fact will look inside the Prolog file
+--
+-- @
+-- kb_call_method_of_untyped_named_param( Param, ParamName, MethodName ).
+-- @
+--
+-- __When should I use this fact__ ( motivation: [CVE-2024-47769](https://nvd.nist.gov/vuln/detail/CVE-2024-47769) )
+--
+-- @
+-- // corePublicRouter.js
+-- const express = require('express');
+-- const router = express.Router();
+--
+-- router.route('...').get(function (req, res) {
+--     const { ..., file } = req.params;
+--     const fileName = file;
+--     return res.sendFile(fileName, ...);
+-- }
+-- @
+--
+-- See complete source example [here](https://github.com/idurar/idurar-erp-crm/blob/d7b2215a17bb2b52acfdab8f1646685d13df9a00/backend/src/routes/coreRoutes/corePublicRouter.js#L8-L24),
+--
+-- __Writing a predicate with this fact and others__ ( motivation: [CVE-2024-47769](https://nvd.nist.gov/vuln/detail/CVE-2024-47769) )
+--
+-- @
+-- arbitrary_file_read( Call ) :-
+--     kb_call_resolved( Call, \'express.Router.route.get\'),
+--     kb_call_method_of_untyped_named_param( Param, \'res\', \'sendFile\' ),
+--     kb_arg_i_for_call( Lambda, 0, Call ),
+--     kb_param_i_of_callable( Param, 1, Lambda ).
+-- @
+--
+-- Other facts combined in this predicate:
+--
+--     * 'CallResolved'
+--     * 'ArgiForCall'
+--     * 'ParamiOfCallable'
+--
+data CallMethodOfUntypedNamedParam = CallMethodOfUntypedNamedParam
+    Param -- ^
+    Token.ParamName -- ^
+    MethodName -- ^
+    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
+
+-- |
 -- capture inheritance from third party classes
 data ClassAnnotation = ClassAnnotation
     Class -- ^
@@ -487,15 +513,49 @@ 
 -- |
 --
--- Usage:
+-- __Name__
 --
+-- This is how the fact will look inside the Prolog file
+--
 -- @
--- ArgiForCall( Arg, Index, Call ).
+-- kb_arg_i_for_call( Arg, Index, Call ).
 -- @
 --
+-- __When should I use this fact__ ( motivation: [CVE-2024-47769](https://nvd.nist.gov/vuln/detail/CVE-2024-47769) )
+--
+-- @
+-- // corePublicRouter.js
+-- const express = require('express');
+-- const router = express.Router();
+--
+-- router.route('...').get(function (req, res) {
+--     const { ..., file } = req.params;
+--     const fileName = file;
+--     return res.sendFile(fileName, ...);
+-- }
+-- @
+--
+-- See complete source example [here](https://github.com/idurar/idurar-erp-crm/blob/d7b2215a17bb2b52acfdab8f1646685d13df9a00/backend/src/routes/coreRoutes/corePublicRouter.js#L8-L24),
+--
+-- __Writing a predicate with this fact and others__ ( motivation: [CVE-2024-47769](https://nvd.nist.gov/vuln/detail/CVE-2024-47769) )
+--
+-- @
+-- arbitrary_file_read( Call ) :-
+--     kb_call_resolved( Call, \'express.Router.route.get\'),
+--     kb_call_method_of_untyped_named_param( Param, \'res\', \'sendFile\' ),
+--     kb_arg_i_for_call( Lambda, 0, Call ),
+--     kb_param_i_of_callable( Param, 1, Lambda ).
+-- @
+--
+-- Other facts combined in this predicate:
+--
+--     * 'CallResolved'
+--     * 'CallMethodOfUntypedNamedParam'
+--     * 'ParamiOfCallable'
+--
 -- ==== __Tip 💡__
 --
--- sometimes the index is irrelevant, see 'ArgForCall'
+-- sometimes the exact index is irrelevant, see 'ArgForCall'
 --
 data ArgiForCall = ArgiForCall
     Arg -- ^
@@ -621,7 +681,6 @@    | CallResolvedCtor CallResolved
    | ConstBoolTrueCtor ConstBoolTrue
    | MethodOfClassCtor MethodOfClass
-   | ClassNamedSuperCtor ClassNamedSuper
    | ClassAnnotationCtor ClassAnnotation
    | ParamiOfCallableCtor ParamiOfCallable
    | KeywordArgForCallCtor KeywordArgForCall
@@ -630,6 +689,7 @@    | CallableAnnotationCtor CallableAnnotation
    | ClassHas1stPartySuperCtor ClassHas1stPartySuper
    | ClassHas3rdPartySuperCtor ClassHas3rdPartySuper
+   | CallMethodOfUntypedNamedParamCtor CallMethodOfUntypedNamedParam
    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
 
 -- |
@@ -651,7 +711,6 @@ prologify (CallResolvedCtor content) = prologify_CallResolved content
 prologify (ConstBoolTrueCtor content) = prologify_ConstBoolTrue content
 prologify (MethodOfClassCtor content) = prologify_MethodOfClass content
-prologify (ClassNamedSuperCtor content) = prologifyClassNamedSuper content
 prologify (ClassAnnotationCtor content) = prologify_ClassAnnotation content
 prologify (ParamiOfCallableCtor content) = prologify_ParamiOfCallable content
 prologify (ParamResolvedTypeCtor content) = prologify_ParamResolvedType content
@@ -660,6 +719,7 @@ prologify (CallableAnnotationCtor content) = prologify_CallableAnnotation content
 prologify (ClassHas1stPartySuperCtor content) = prologify_ClassHas1stPartySuper content
 prologify (ClassHas3rdPartySuperCtor content) = prologify_ClassHas3rdPartySuper content
+prologify (CallMethodOfUntypedNamedParamCtor content) = prologify_CallMethodOfUntypedNamedParam content
 
 prologify_ParamResolvedType' :: Location -> String -> String
 prologify_ParamResolvedType' l fqn = printf "kb_param_has_type( %s, \'%s\' )." (locationify l) fqn
@@ -699,7 +759,7 @@ 
 prologify_CallResolved' :: Location -> Fqn.Fqn -> String
 prologify_CallResolved' call (Fqn.CallMethodOfClass _ m c) = prologify_CallResolved'' call m c 
-prologify_CallResolved' call fqn = printf "kb_call_resolved( %s, \'%s\' )." (locationify call) (show fqn)
+prologify_CallResolved' call fqn = printf "kb_call_resolved( %s, \'%s\' )." (locationify call) (prologifyFqn fqn)
 
 prologify_DataflowEdge :: DataflowEdge -> String
 prologify_DataflowEdge (DataflowEdge (From u) (To v)) = prologify_DataflowEdge' u v
@@ -740,12 +800,14 @@ prologify_ClassHas3rdPartySuper :: ClassHas3rdPartySuper -> String
 prologify_ClassHas3rdPartySuper (ClassHas3rdPartySuper (Class c) (Token.SuperName (Token.Named s _)) (SuperQualifiedName f)) = prologify_ClassHas3rdPartySuper' c s f
 
+prologify_CallMethodOfUntypedNamedParam :: CallMethodOfUntypedNamedParam -> String
+prologify_CallMethodOfUntypedNamedParam (CallMethodOfUntypedNamedParam p name method) = prologify_CallMethodOfUntypedNamedParam' p name method
 
-prologifyClassNamedSuper' :: Location -> String -> String
-prologifyClassNamedSuper' l s = printf "kb_class_has_named_super( %s, \'%s\' )." (locationify l) s
+prologify_CallMethodOfUntypedNamedParam' :: Param -> Token.ParamName -> MethodName -> String
+prologify_CallMethodOfUntypedNamedParam' (Param p) (Token.ParamName (Token.Named name _)) (MethodName m) = prologify_CallMethodOfUntypedNamedParam'' p name m
 
-prologifyClassNamedSuper :: ClassNamedSuper -> String
-prologifyClassNamedSuper (ClassNamedSuper (Class c) (Token.SuperName (Token.Named name _))) = prologifyClassNamedSuper' c name
+prologify_CallMethodOfUntypedNamedParam'' :: Location -> String -> String -> String
+prologify_CallMethodOfUntypedNamedParam'' p n m = printf "kb_call_method_of_untyped_named_param( %s, \'%s\', \'%s\' )." (locationify p) n m
 
 prologifyArgiForCall' :: Location -> Word -> Location -> String
 prologifyArgiForCall' a i c = printf "kb_arg_i_for_call( %s, %u, %s )." (locationify a) i (locationify c)