You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 line
4.9KB

  1. <%
  2. '=======================================================================================================================
  3. ' Controller Registry
  4. ' Provides a whitelist of valid controllers to prevent code injection attacks
  5. '=======================================================================================================================
  6. Class ControllerRegistry_Class
  7. Private m_controllers
  8. Private Sub Class_Initialize()
  9. Set m_controllers = Server.CreateObject("Scripting.Dictionary")
  10. m_controllers.CompareMode = 1 ' vbTextCompare for case-insensitive
  11. ' Register all valid controllers here
  12. ' Format: m_controllers.Add "controllername", True
  13. RegisterController "homecontroller"
  14. RegisterController "errorcontroller"
  15. RegisterController "importcontroller"
  16. RegisterController "businessescontroller"
  17. RegisterController "todaycontroller"
  18. RegisterController "industriescontroller"
  19. RegisterController "areascontroller"
  20. RegisterController "exportcontroller"
  21. RegisterController "dashboardcontroller"
  22. RegisterController "bulklogcontroller"
  23. End Sub
  24. Private Sub Class_Terminate()
  25. Set m_controllers = Nothing
  26. End Sub
  27. '---------------------------------------------------------------------------------------------------------------------
  28. ' Register a controller as valid
  29. '---------------------------------------------------------------------------------------------------------------------
  30. Public Sub RegisterController(controllerName)
  31. Dim key : key = LCase(Trim(controllerName))
  32. If Not m_controllers.Exists(key) Then
  33. m_controllers.Add key, True
  34. End If
  35. End Sub
  36. '---------------------------------------------------------------------------------------------------------------------
  37. ' Check if a controller is registered (valid)
  38. '---------------------------------------------------------------------------------------------------------------------
  39. Public Function IsValidController(controllerName)
  40. Dim key : key = LCase(Trim(controllerName))
  41. IsValidController = m_controllers.Exists(key)
  42. End Function
  43. '---------------------------------------------------------------------------------------------------------------------
  44. ' Get list of all registered controllers
  45. '---------------------------------------------------------------------------------------------------------------------
  46. Public Function GetRegisteredControllers()
  47. GetRegisteredControllers = m_controllers.Keys()
  48. End Function
  49. '---------------------------------------------------------------------------------------------------------------------
  50. ' Validate controller name format (alphanumeric and underscore only)
  51. '---------------------------------------------------------------------------------------------------------------------
  52. Public Function IsValidControllerFormat(controllerName)
  53. If IsEmpty(controllerName) Or Len(controllerName) = 0 Then
  54. IsValidControllerFormat = False
  55. Exit Function
  56. End If
  57. Dim i, ch
  58. For i = 1 To Len(controllerName)
  59. ch = Mid(controllerName, i, 1)
  60. ' Allow a-z, A-Z, 0-9, and underscore
  61. If Not ((ch >= "a" And ch <= "z") Or _
  62. (ch >= "A" And ch <= "Z") Or _
  63. (ch >= "0" And ch <= "9") Or _
  64. ch = "_") Then
  65. IsValidControllerFormat = False
  66. Exit Function
  67. End If
  68. Next
  69. IsValidControllerFormat = True
  70. End Function
  71. '---------------------------------------------------------------------------------------------------------------------
  72. ' Validate action name format (alphanumeric and underscore only)
  73. '---------------------------------------------------------------------------------------------------------------------
  74. Public Function IsValidActionFormat(actionName)
  75. If IsEmpty(actionName) Or Len(actionName) = 0 Then
  76. IsValidActionFormat = False
  77. Exit Function
  78. End If
  79. Dim i, ch
  80. For i = 1 To Len(actionName)
  81. ch = Mid(actionName, i, 1)
  82. ' Allow a-z, A-Z, 0-9, and underscore
  83. If Not ((ch >= "a" And ch <= "z") Or _
  84. (ch >= "A" And ch <= "Z") Or _
  85. (ch >= "0" And ch <= "9") Or _
  86. ch = "_") Then
  87. IsValidActionFormat = False
  88. Exit Function
  89. End If
  90. Next
  91. IsValidActionFormat = True
  92. End Function
  93. End Class
  94. ' Singleton instance
  95. Dim ControllerRegistry_Class__Singleton
  96. Function ControllerRegistry()
  97. If IsEmpty(ControllerRegistry_Class__Singleton) Then
  98. Set ControllerRegistry_Class__Singleton = New ControllerRegistry_Class
  99. End If
  100. Set ControllerRegistry = ControllerRegistry_Class__Singleton
  101. End Function
  102. %>

Powered by TurnKey Linux.