@@ -301,27 +301,39 @@ private module Request {
301301 override Http:: Server:: RequestInputKind getKind ( ) { result = Http:: Server:: bodyInputKind ( ) }
302302 }
303303
304- /**
305- * A method call on `request` which returns the rack env.
306- * This is a hash containing all the information about the request. Values
307- * under keys starting with `HTTP_` are user-controlled.
308- */
309- private class EnvCall extends RequestMethodCall {
310- EnvCall ( ) { this .getMethodName ( ) = [ "env" , "filtered_env" ] }
311- }
304+ private module Env {
305+ abstract private class Env extends DataFlow:: LocalSourceNode { }
306+
307+ /**
308+ * A method call on `request` which returns the rack env.
309+ * This is a hash containing all the information about the request. Values
310+ * under keys starting with `HTTP_` are user-controlled.
311+ */
312+ private class RequestEnvCall extends DataFlow:: CallNode , Env {
313+ RequestEnvCall ( ) { this .getMethodName ( ) = [ "env" , "filtered_env" ] }
314+ }
312315
313- /**
314- * A read of a user-controlled parameter from the request env.
315- */
316- private class EnvHttpAccess extends DataFlow:: CallNode , Http:: Server:: RequestInputAccess:: Range {
317- EnvHttpAccess ( ) {
318- this = any ( EnvCall c ) .getAMethodCall ( "[]" ) and
319- this .getArgument ( 0 ) .getConstantValue ( ) .getString ( ) .regexpMatch ( "^HTTP_.+" )
316+ private import codeql.ruby.frameworks.Rack
317+
318+ private class RackEnv extends Env {
319+ RackEnv ( ) { this = any ( Rack:: AppCandidate app ) .getEnv ( ) .getALocalUse ( ) }
320320 }
321321
322- override Http:: Server:: RequestInputKind getKind ( ) { result = Http:: Server:: headerInputKind ( ) }
322+ /**
323+ * A read of a user-controlled parameter from the request env.
324+ */
325+ private class EnvHttpAccess extends DataFlow:: CallNode , Http:: Server:: RequestInputAccess:: Range {
326+ EnvHttpAccess ( ) {
327+ this = any ( Env c ) .getAMethodCall ( "[]" ) and
328+ exists ( string key | key = this .getArgument ( 0 ) .getConstantValue ( ) .getString ( ) |
329+ key .regexpMatch ( "^HTTP_.+" ) or key = "PATH_INFO"
330+ )
331+ }
323332
324- override string getSourceType ( ) { result = "ActionDispatch::Request#env[]" }
333+ override Http:: Server:: RequestInputKind getKind ( ) { result = Http:: Server:: headerInputKind ( ) }
334+
335+ override string getSourceType ( ) { result = "ActionDispatch::Request#env[]" }
336+ }
325337 }
326338}
327339
0 commit comments