packages feed

dhscanner-kbapi 2.0.0 → 3.0.0

raw patch · 7 files changed

+116/−10 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- WithControlFlowReachableSinks: DbWrite :: Sink
- WithDataFlowPath: Column :: String -> Column
- WithDataFlowPath: DbWriteDataFlowPath :: DBWriteDataFlowContent -> Content
- WithDataFlowPath: Model :: String -> Model
- WithDataFlowPath: data Column
- WithDataFlowPath: data Model
- WithDataFlowPath: instance Data.Aeson.Types.FromJSON.FromJSON WithDataFlowPath.Column
- WithDataFlowPath: instance Data.Aeson.Types.FromJSON.FromJSON WithDataFlowPath.Model
- WithDataFlowPath: instance Data.Aeson.Types.ToJSON.ToJSON WithDataFlowPath.Column
- WithDataFlowPath: instance Data.Aeson.Types.ToJSON.ToJSON WithDataFlowPath.Model
- WithDataFlowPath: instance GHC.Internal.Classes.Eq WithDataFlowPath.Column
- WithDataFlowPath: instance GHC.Internal.Classes.Eq WithDataFlowPath.Model
- WithDataFlowPath: instance GHC.Internal.Classes.Ord WithDataFlowPath.Column
- WithDataFlowPath: instance GHC.Internal.Classes.Ord WithDataFlowPath.Model
- WithDataFlowPath: instance GHC.Internal.Generics.Generic WithDataFlowPath.Column
- WithDataFlowPath: instance GHC.Internal.Generics.Generic WithDataFlowPath.Model
- WithDataFlowPath: instance GHC.Internal.Show.Show WithDataFlowPath.Column
- WithDataFlowPath: instance GHC.Internal.Show.Show WithDataFlowPath.Model
+ Common: Column :: String -> Column
+ Common: Model :: String -> Model
+ Common: data Column
+ Common: data Model
+ Common: instance Data.Aeson.Types.FromJSON.FromJSON Common.Column
+ Common: instance Data.Aeson.Types.FromJSON.FromJSON Common.Model
+ Common: instance Data.Aeson.Types.ToJSON.ToJSON Common.Column
+ Common: instance Data.Aeson.Types.ToJSON.ToJSON Common.Model
+ Common: instance GHC.Internal.Classes.Eq Common.Column
+ Common: instance GHC.Internal.Classes.Eq Common.Model
+ Common: instance GHC.Internal.Classes.Ord Common.Column
+ Common: instance GHC.Internal.Classes.Ord Common.Model
+ Common: instance GHC.Internal.Generics.Generic Common.Column
+ Common: instance GHC.Internal.Generics.Generic Common.Model
+ Common: instance GHC.Internal.Show.Show Common.Column
+ Common: instance GHC.Internal.Show.Show Common.Model
+ Kbapi: FoundDBReads :: Content -> QueryResult
+ Kbapi: SelectDBReads :: Features -> Query
+ WithControlFlowReachableSinks: DBWrite :: Sink
+ WithControlFlowReachableSinks: Import :: Sink
+ WithDBReads: Content :: Word -> [Match] -> Content
+ WithDBReads: DBRead :: Location -> DBRead
+ WithDBReads: Features :: Location -> Model -> Column -> Word -> Word -> Features
+ WithDBReads: Match :: DBRead -> [Location] -> Match
+ WithDBReads: [column] :: Features -> Column
+ WithDBReads: [dbRead] :: Match -> DBRead
+ WithDBReads: [endpointToDBRead] :: Match -> [Location]
+ WithDBReads: [endpoint] :: Features -> Location
+ WithDBReads: [matches] :: Content -> [Match]
+ WithDBReads: [maxNumInterProceduralHops] :: Features -> Word
+ WithDBReads: [maxNumMatches] :: Features -> Word
+ WithDBReads: [model] :: Features -> Model
+ WithDBReads: [total] :: Content -> Word
+ WithDBReads: data Content
+ WithDBReads: data DBRead
+ WithDBReads: data Features
+ WithDBReads: data Match
+ WithDBReads: instance Data.Aeson.Types.FromJSON.FromJSON WithDBReads.Content
+ WithDBReads: instance Data.Aeson.Types.FromJSON.FromJSON WithDBReads.DBRead
+ WithDBReads: instance Data.Aeson.Types.FromJSON.FromJSON WithDBReads.Features
+ WithDBReads: instance Data.Aeson.Types.FromJSON.FromJSON WithDBReads.Match
+ WithDBReads: instance Data.Aeson.Types.ToJSON.ToJSON WithDBReads.Content
+ WithDBReads: instance Data.Aeson.Types.ToJSON.ToJSON WithDBReads.DBRead
+ WithDBReads: instance Data.Aeson.Types.ToJSON.ToJSON WithDBReads.Features
+ WithDBReads: instance Data.Aeson.Types.ToJSON.ToJSON WithDBReads.Match
+ WithDBReads: instance GHC.Internal.Classes.Eq WithDBReads.Content
+ WithDBReads: instance GHC.Internal.Classes.Eq WithDBReads.DBRead
+ WithDBReads: instance GHC.Internal.Classes.Eq WithDBReads.Features
+ WithDBReads: instance GHC.Internal.Classes.Eq WithDBReads.Match
+ WithDBReads: instance GHC.Internal.Classes.Ord WithDBReads.Content
+ WithDBReads: instance GHC.Internal.Classes.Ord WithDBReads.DBRead
+ WithDBReads: instance GHC.Internal.Classes.Ord WithDBReads.Features
+ WithDBReads: instance GHC.Internal.Classes.Ord WithDBReads.Match
+ WithDBReads: instance GHC.Internal.Generics.Generic WithDBReads.Content
+ WithDBReads: instance GHC.Internal.Generics.Generic WithDBReads.DBRead
+ WithDBReads: instance GHC.Internal.Generics.Generic WithDBReads.Features
+ WithDBReads: instance GHC.Internal.Generics.Generic WithDBReads.Match
+ WithDBReads: instance GHC.Internal.Show.Show WithDBReads.Content
+ WithDBReads: instance GHC.Internal.Show.Show WithDBReads.DBRead
+ WithDBReads: instance GHC.Internal.Show.Show WithDBReads.Features
+ WithDBReads: instance GHC.Internal.Show.Show WithDBReads.Match
+ WithDataFlowPath: DBWriteDataFlowPath :: DBWriteDataFlowContent -> Content

Files

dhscanner-kbapi.cabal view
@@ -28,7 +28,7 @@     fundamental modifications to the structure or specification     of code facts. -version:            2.0.0+version:            3.0.0 license:            GPL-3.0-only license-file:       LICENSE author:             OrenGitHub@@ -49,12 +49,14 @@      exposed-modules:         Kbapi,+        Common,         WithHttpHandlers,         WithControlFlowReachableSinks,         WithConstStrings,         WithComments,         WithDataFlowPath,-        WithSanitizers+        WithSanitizers,+        WithDBReads      build-depends:         aeson >= 2.2 && < 2.4,
json-schema-creator/Main.hs view
@@ -24,12 +24,14 @@ import Kbapi ( Query, QueryResult )  -- project qualified imports+import qualified Common import qualified WithHttpHandlers import qualified WithControlFlowReachableSinks import qualified WithConstStrings import qualified WithComments import qualified WithDataFlowPath import qualified WithSanitizers+import qualified WithDBReads  -- every query module names its type Features : qualify the schema name qualifiedAs :: String -> SchemaOptions@@ -40,6 +42,9 @@  instance ToSchema Location +instance ToSchema Common.Model+instance ToSchema Common.Column+ instance ToSchema WithHttpHandlers.Features where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithHttpHandlers") instance ToSchema WithHttpHandlers.HttpVerb instance ToSchema WithHttpHandlers.AuthFilter@@ -78,14 +83,17 @@ instance ToSchema WithDataFlowPath.Content where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithDataFlowPath") instance ToSchema WithDataFlowPath.PlainDataFlowContent instance ToSchema WithDataFlowPath.DBWriteDataFlowContent-instance ToSchema WithDataFlowPath.Model-instance ToSchema WithDataFlowPath.Column  instance ToSchema WithSanitizers.Features where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithSanitizers") instance ToSchema WithSanitizers.Content where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithSanitizers") instance ToSchema WithSanitizers.IfThenElse instance ToSchema WithSanitizers.PartCall instance ToSchema WithSanitizers.FlowStep++instance ToSchema WithDBReads.Features where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithDBReads")+instance ToSchema WithDBReads.Content where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithDBReads")+instance ToSchema WithDBReads.Match where declareNamedSchema = genericDeclareNamedSchema (qualifiedAs "WithDBReads")+instance ToSchema WithDBReads.DBRead  -- openapi3 ignores tagSingleConstructors : describe the tagged Sanitizer -- through a mirror ( drop it once Sanitizer has a second constructor )
+ src/Common.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveAnyClass #-}++module Common++where++-- general imports+import GHC.Generics+import Data.Aeson++-- | A 1st party database model, by its class name ( e.g. @Post@ ).+data Model = Model String deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )+-- | A column of a 'Model', by its name ( e.g. @title@ ).+data Column = Column String deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
src/Kbapi.hs view
@@ -54,6 +54,7 @@ import qualified WithConstStrings import qualified WithComments import qualified WithSanitizers+import qualified WithDBReads  data Query    = SelectHttpHandlers WithHttpHandlers.Features@@ -62,6 +63,7 @@    | SelectConstStrings WithConstStrings.Features    | SelectComments WithComments.Features    | SelectSanitizers WithSanitizers.Features+   | SelectDBReads WithDBReads.Features    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )  data QueryResult@@ -71,4 +73,5 @@    | FoundCommentsInFunction WithComments.Content    | FoundDataFlowPath WithDataFlowPath.Content    | FoundSanitizers WithSanitizers.Content+   | FoundDBReads WithDBReads.Content    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
src/WithControlFlowReachableSinks.hs view
@@ -30,7 +30,8 @@    | OpenRedirect    | SSRF    | SQL-   | DbWrite+   | DBWrite+   | Import    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )  data Content
+ src/WithDBReads.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveAnyClass #-}++module WithDBReads++where++-- general imports+import GHC.Generics+import Data.Aeson++-- project imports+import Location+import Common++-- |+--+-- * The reads of 'column' of the 1st party 'model' that 'endpoint'+--   reaches within 'maxNumInterProceduralHops' calls ( @0@ : reads+--   'endpoint' itself contains ), at most 'maxNumMatches' of them.+--+-- * 'model' and 'column' are spelled as a 'WithDataFlowPath.DBWriteDataFlowPath'+--   reports them : ask this query on an endpoint after another endpoint+--   was found to store user input in that column ( stored, or second+--   order, taint ).+--+-- * A read of every column ( @select *@ ) is a read of 'column' too.+--+-- Code snippet ( PHP, Laravel ):+--+-- @+-- public function show( Request $request, $slug ) {+--     $post = Post::select( \'title\', \'body\' )->where( \'slug\', $slug )->first();+--     return view( \'posts.show\', [ \'post\' => $post ] );+-- }+-- @+--+-- With @endpoint@ = @show@, @model@ = @Post@, @column@ = @title@, the read is+-- the @Post::select( .. )->first()@ call, contained in @show@.+--+data Features+   = Features+     {+        endpoint :: Location,+        model :: Model,+        column :: Column,+        maxNumInterProceduralHops :: Word,+        maxNumMatches :: Word+     }+     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++data Content+   = Content+     {+        total :: Word,+        matches :: [ Match ]+     }+     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++-- |+--+-- * 'dbRead' : the read call, whose value holds the column. It is the @from@+--   of a 'WithDataFlowPath.Features' query towards a sink 'endpoint' reaches.+--+-- * 'endpointToDBRead' : the call sites from 'endpoint' down to the call+--   that holds 'dbRead', 'endpoint' side first ; @[]@ when 'endpoint'+--   contains the read. Together with the data flow path from 'dbRead' it+--   is the read side of a stored taint finding.+--+data Match+   = Match+     {+        dbRead :: DBRead,+        endpointToDBRead :: [ Location ]+     }+     deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )++-- | A database read : the location of the read call.+data DBRead = DBRead Location deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )
src/WithDataFlowPath.hs view
@@ -11,6 +11,7 @@  -- project imports import Location+import Common  data Features    = Features@@ -28,14 +29,14 @@ -- -- * When 'to' writes to a database and the path reaches the value of --   one of its columns, the knowledge base says which model and column---   the value is stored in ( 'DbWriteDataFlowPath' ), e.g.+--   the value is stored in ( 'DBWriteDataFlowPath' ), e.g. --   @Post::where( 'id', $id )->update( [ 'title' => $title ] )@ --   stores @$title@ in model @Post@, column @title@. -- data Content    = NoDataFlowPath    | PlainDataFlowPath PlainDataFlowContent-   | DbWriteDataFlowPath DBWriteDataFlowContent+   | DBWriteDataFlowPath DBWriteDataFlowContent    deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )  data PlainDataFlowContent@@ -53,6 +54,3 @@          dbWriteDataFlowPath :: [ Location ]      }      deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )--data Model = Model String deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )-data Column = Column String deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )