Как я могу обойти X-Frame-Options - PullRequest
       46

Как я могу обойти X-Frame-Options

1 голос
/ 17 октября 2019

Я пытаюсь при нажатии на ссылку показать веб-сайт в iframe, но у меня проблема с x-frame-option. Затем я использую x-frame-bypass. Это работает, когда я использую в HTML , как показано ниже.

HTML

<html>

<head>
<title></title>
<script src="https://unpkg.com/@ungap/custom-elements-builtin"></script>
<script type="module" src="https://unpkg.com/x-frame-bypass"></script>
</head>
<body>
<iframe is="x-frame-bypass" src="https://news.ycombinator.com/" name="myIframe"></iframe>

</body>
</html>

Но, когда я пытаюсь щелкнуть ссылку и открыть ее в iframeне работает. Я использую угловой. Пример кода, как показано ниже.

index.html

<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <script src="https://unpkg.com/@ungap/custom-elements-builtin"></script>
  <script type="module" src="https://unpkg.com/x-frame-bypass"></script>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <my-app>Loading...</my-app>
</body>
</html>

app.component.html

<div style="text-align:center">
  <h1>
   Test Open URL in Iframe
  </h1>
  <a class="link-call" (click)="onTest('https://news.ycombinator.com/')" style="background:red;padding: 14px 25px;color:white;cursor:pointer">test</a>
  </div>


<iframe is="x-frame-bypass" width="100%" height="100%" frameBorder="0" [src]="urlSafe"></iframe>

app.component.ts

name = 'Set iframe source';
  url: string;
  urlSafe: SafeResourceUrl;

  constructor(public sanitizer: DomSanitizer) { }

  ngOnInit() {

  }
  onTest(url){
    this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(url);
  }

Это DEMO для справки

...