簡體   English   中英

angular為什么要給app-root html標簽添加ng-version屬性

[英]Why does angular add ng-version attribute to the app-root html tag

今天發現Angular在app-root中添加了如下版本信息:

<app-root _nghost-c0="" ng-version="5.2.0">

甚至當我在生產環境中構建時,它似乎也存在。 我不知道在那里添加該信息的主要目標是什么? 公開顯示 angular 版本不是安全問題嗎? 謝謝

Angular 使用此屬性來標記用於引導應用程序的元素。

另見https://github.com/angular/angular/commit/a4de214e2be5048f1261d043cc467a5ecaa5c909

隱藏它只會是通過默默無聞的安全,這不是安全。

這是一個老問題,但仍然相關,並且接受的答案可能會產生誤導。 根據 Miško Hevery 的說法:“這是故意的,所以像占卜這樣的工具可以檢測到它是一個有角度的頁面,並可以提供有用的用戶界面。”

這本身不是安全問題,但隱藏它也不是“默默無聞的安全”,因為這意味着您采取的所有安全措施。 事實上,使用隱匿性是一種很好的做法,因為它使攻擊者更難收集(偵察)信息,但絕不能僅依賴於此。

Go 到您的根組件並添加這段代碼以刪除ng-version屬性:

@Component({
    selector: '[data-app]',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent {
    constructor(private _elementRef: ElementRef) {
    }

    ngOnInit(): void {
        this._elementRef.nativeElement.removeAttribute("ng-version");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM