gpt4 book ai didi

security - aspnetcore 是否有一个带有 Controller 的银河大小的安全漏洞,或者我错过了什么?

转载 作者:行者123 更新时间:2023-12-05 02:46:57 26 4
gpt4 key购买 nike

在检查一位同事的库时,我看到了他描述的两种使用他的新 StatusController 的方法。要么覆盖 GetStatus 方法以返回更具体的数据,要么让默认实现正常工作。好吧,所以我做了覆盖,因为我还不确定他对后者的意思是什么并且它有效。另一位同事问我是否看过后者,我回答

“好吧,不,因为如果我只引用项目/nuget 而不以某种方式告诉框架它就不会工作”

“试试吧”

“好的,但如果它有效,我会感到震惊”。

我现在错了。

然后我继续通过间接引用尝试这个,它仍然有效。我故意不显示任何代码,因为它只是来自 Visual Studio MVC web 应用程序或 web API 的样板 Controller 代码,您可以在几分钟内完成。但让我举个例子。

假设我正在为 www.electioncomission.gov.us 编写应用程序我想对特定文件格式进行一些特殊的字符串解析,有一个 nuget 包可以帮助我,我们称之为 VotingMachineFormatParser 并且我不知道它使用了一个名为 Tviker(俄语为 Tweaker)的包,不知道为什么但是他们发现它很有用。 Tviker 内部有一个名为 GosudarstvennoyeVmeshatelStvoController 的 Controller 类,它执行某事 - 这意味着状态干扰。

如果您现在转到 www.electioncomission.gov.us/gosudarstvennoyevmeshatelstvo某些代码正在运行,正在执行任何操作。

我认为您应该使用应用程序部件的概念从另一个组件中拉入 Controller 。请问,我错过了什么?这肯定不是我认为的那个洞吧?

编辑:我没有包含任何代码,因为这就是重点,您不需要任何代码。我忘了说这是 .Net Core 3.1+ 的"new"行为,它以前不是那样工作的。从另一个组件中拉入 Controller 的唯一方法是通过 ApplicationParts。

只需重命名两个样板类即可轻松测试它。

让 VStudio 在 .NetCore 5 中创建样板 WebAPI 并选中 OpenAPI 复选框。在两个单独的文件夹中执行此操作,但其中一个将 WeatherForecastController 重命名为 ToldYouController,并将 WeatherForecast 类重命名(通过重构)为 WeatherForecast1。

在第一个项目中引用带有 ToldYouController 的项目,运行,您将在 Swagger 中看到两个 Controller ,您实际上只是引用来实现它!您可以通过间接引用来尝试此操作,它也会执行相同的操作。

最佳答案

.NET Core 3.x 为引用 MVC 的程序集自动注册应用程序部分。

来自 Andrew Locks blog :

Note that in ASP.NET Core 3.x, when you compile an assembly thatreferences ASP.NET Core, an assembly attribute is added to the output,[ApplicationPart]. ASP.NET Core 3.x apps look for this attribute onreferenced assemblies and registers them as application partsautomatically.

关于 ASP.NET Core documentation 上的 ApplicationPartAttribute :

Specifies an assembly to be added as an ApplicationPart.

In the ordinary case, MVC will generate ApplicationPartAttributeinstances on the entry assembly for each dependency that referencesMVC. Each of these assemblies is treated as an ApplicationPart.


由于 GosudarstvennoyeVmeshatelStvoController 是一个 Controller,它的程序集将引用 MVC,因此被注册为应用程序部分。

关于security - aspnetcore 是否有一个带有 Controller 的银河大小的安全漏洞,或者我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65235718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com