ASP Classic blog framework - BrainOrdure
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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

Powered by TurnKey Linux.