Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

117 lines
4.8KB

  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 "exportcontroller"
  20. RegisterController "dashboardcontroller"
  21. End Sub
  22. Private Sub Class_Terminate()
  23. Set m_controllers = Nothing
  24. End Sub
  25. '---------------------------------------------------------------------------------------------------------------------
  26. ' Register a controller as valid
  27. '---------------------------------------------------------------------------------------------------------------------
  28. Public Sub RegisterController(controllerName)
  29. Dim key : key = LCase(Trim(controllerName))
  30. If Not m_controllers.Exists(key) Then
  31. m_controllers.Add key, True
  32. End If
  33. End Sub
  34. '---------------------------------------------------------------------------------------------------------------------
  35. ' Check if a controller is registered (valid)
  36. '---------------------------------------------------------------------------------------------------------------------
  37. Public Function IsValidController(controllerName)
  38. Dim key : key = LCase(Trim(controllerName))
  39. IsValidController = m_controllers.Exists(key)
  40. End Function
  41. '---------------------------------------------------------------------------------------------------------------------
  42. ' Get list of all registered controllers
  43. '---------------------------------------------------------------------------------------------------------------------
  44. Public Function GetRegisteredControllers()
  45. GetRegisteredControllers = m_controllers.Keys()
  46. End Function
  47. '---------------------------------------------------------------------------------------------------------------------
  48. ' Validate controller name format (alphanumeric and underscore only)
  49. '---------------------------------------------------------------------------------------------------------------------
  50. Public Function IsValidControllerFormat(controllerName)
  51. If IsEmpty(controllerName) Or Len(controllerName) = 0 Then
  52. IsValidControllerFormat = False
  53. Exit Function
  54. End If
  55. Dim i, ch
  56. For i = 1 To Len(controllerName)
  57. ch = Mid(controllerName, i, 1)
  58. ' Allow a-z, A-Z, 0-9, and underscore
  59. If Not ((ch >= "a" And ch <= "z") Or _
  60. (ch >= "A" And ch <= "Z") Or _
  61. (ch >= "0" And ch <= "9") Or _
  62. ch = "_") Then
  63. IsValidControllerFormat = False
  64. Exit Function
  65. End If
  66. Next
  67. IsValidControllerFormat = True
  68. End Function
  69. '---------------------------------------------------------------------------------------------------------------------
  70. ' Validate action name format (alphanumeric and underscore only)
  71. '---------------------------------------------------------------------------------------------------------------------
  72. Public Function IsValidActionFormat(actionName)
  73. If IsEmpty(actionName) Or Len(actionName) = 0 Then
  74. IsValidActionFormat = False
  75. Exit Function
  76. End If
  77. Dim i, ch
  78. For i = 1 To Len(actionName)
  79. ch = Mid(actionName, i, 1)
  80. ' Allow a-z, A-Z, 0-9, and underscore
  81. If Not ((ch >= "a" And ch <= "z") Or _
  82. (ch >= "A" And ch <= "Z") Or _
  83. (ch >= "0" And ch <= "9") Or _
  84. ch = "_") Then
  85. IsValidActionFormat = False
  86. Exit Function
  87. End If
  88. Next
  89. IsValidActionFormat = True
  90. End Function
  91. End Class
  92. ' Singleton instance
  93. Dim ControllerRegistry_Class__Singleton
  94. Function ControllerRegistry()
  95. If IsEmpty(ControllerRegistry_Class__Singleton) Then
  96. Set ControllerRegistry_Class__Singleton = New ControllerRegistry_Class
  97. End If
  98. Set ControllerRegistry = ControllerRegistry_Class__Singleton
  99. End Function
  100. %>

Powered by TurnKey Linux.