Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

112 lignes
4.6KB

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

Powered by TurnKey Linux.