25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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

Powered by TurnKey Linux.