Consolidated ASP Classic MVC framework from best components
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.

111 lignes
4.5KB

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

Powered by TurnKey Linux.