Consolidated ASP Classic MVC framework from best components
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

114 řádky
4.7KB

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

Powered by TurnKey Linux.