明知头是可以被欺骗

明知头是可以被欺骗

本文介绍了PHP驱动的API如何鉴别真正的客户端(引荐)跨域(明知头是可以被欺骗)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP,你怎么安全验证 API调用 跨域,用以下标准:

Using PHP, how do you securely authenticate an API call, cross-domain, with the following criteria:


  1. 必须从给定domain.com/page称为(没有其他域)

  2. 必须有一个给定的键

一些背景资料:请仔细回答之前阅读...

我的Web应用程序将通过类似下面的呼叫显示在客户的网站一个JavaScript小部件。因此,我们在谈论跨域认证的脚本送达,但只有正版客户端和唯一指定的URL!

My web application will display a javascript widget on a client's website via a call like the one below. So we're talking about cross-domain authentication for a script to be served but only to genuine client and for a given URL only!

目前,小部件可以通过客户的网站包括,通过JavaScript的一个单行。

At the moment the widget can be included by the CLIENT's website, by a single-line of javascript.

示例client-website.com/page/with/my-widget

<head>
...
<script src="//ws.my-webappserver.com/little-widget/?key=api_key"></script>
...
</head>

现在,在现实中这并不直接调用JavaScript,但它坐落在做一些认证的目的,实际的JavaScript前我的远程服务器上的PHP脚本。

Now, in reality this does not call javascript directly but a PHP script on my remote server which sits in front of the actual javascript for the purpose of doing some authentication.

以上调用背后的PHP脚本确实这首:

The PHP script behind the above call does this first:


  1. 检查该API密钥($ _REQUEST [钥匙])在数据库中匹配用户的记录。

  2. 检查引用对阵记录URL($ _ SERVER ['HTTP_REFERER'])数据库中的***。

这是简化,但在本质上的服务器看起来像

This is simplified, but in essence the server looks like:

if ($_SERVER['HTTP_REFERER'] !== "http://client-website.com/page/with/my-widget")
  && $_REQUEST["Key"] == "the_long_api_key") {
    header("Content-type: application/x-javascript");
    echo file_get_contents($thewidgetJS_in_secret_location_on_server);
} else {
  //pretend to be a 404 page not found or some funky thing like that
}

***窗口小部件只允许某些网站上运行/页

***The widget is only allowed to run on CERTAIN websites/pages

现在,这里有一个问题:

Now, here's the problem:


  1. 关键是在客户端,以便任何人都可以查看源代码,并获得关键

  2. 引荐例如可以被欺骗(由卷曲)

和一个小障碍:
我不能告诉客户坚持一个PHP脚本中的关键的服务器上,因为它们可以运行任何服务器端语言!

And a little snag:I can't tell the clients to stick the key inside a php script on their server because they could be running any server side language!

那么,怎样才能使我的Web服务由给定域/页的安全和方便进出?

So how can I make my web service secure and only accessible by a given domain/page?

任何帮助将是非常美联社preciated!

Any help would be really appreciated!

PS:小部件做一些上传到一种下拉框的 - 所以安全性是关键此处

ps: The widget does some uploading to a kind of drop box - so security is key here!

推荐答案

ID推荐使用白名单的方式对这个问题,我不完全肯定这将解决这个问题,但是我已经使用了支付处理这需要一个类似的技术你到白名单服务器的IP。

id recommend using a whitelist approach to this issue, i am not entirely sure this will solve the problem however i have used a similar technique for a payment processor which requires you to whitelist server-ips.

这篇关于PHP驱动的API如何鉴别真正的客户端(引荐)跨域(明知头是可以被欺骗)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 12:00