Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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

Powered by TurnKey Linux.