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ů.

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

Powered by TurnKey Linux.