選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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

Powered by TurnKey Linux.