Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

120 linhas
5.0KB

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

Powered by TurnKey Linux.