English 中文(简体)
如何保护或保障进入Django Rest_framework的APIC线路? [复制]
原标题:How to protect or secure API routes access Django Rest_framework? [duplicate]
  • 时间:2020-06-05 04:45:39
  •  标签:
  • django

我在一段时间内一直在绕过这个问题,但迄今却可以找到令人满意的解决办法。

We are currently in the process of creating a new public API, which will be used by widgets to get information but also to post back information to the system (like a contact form). As the widgets will be implementend as web components and can be implemented on any page, we don t have control over how the widgets are delivered.

现在面临的问题是:我们如何能够保护APIC免受不想要的提交(除了一般形式验证之外)的提交,以便我们能够确信它不是以这种形式提交的,就是它向APIC提供一种法律指导?

我的关切是,本案中的所有事项都是可以证明的(例如,打上一个表格,并把它作为头脑、验证原主......),因为可以很容易地向邮政员提出。 我对你的任何经历和向正确方向倾斜感到非常高兴。

问题回答

我认为你可以尝试:

  • Rate limit based on IP
  • Rate limits on general insertions
  • Require email validation after send (if you have this data)
  • Save sender IP and check with old data, to know if someoe is abusing (a monitoring tip, but maybe is not bad idea)
  • Captcha to avoid malicious senders (but not at all)

你们是否采取了类似行动? 也许通过看到你的话,我们可以看到什么是失踪的。

由于公之于众,并且允许任何系统进入,情况也变得复杂。 也许,评估认证制度,并从植被本身认证,将按钥匙计价的气候。

If you have a public API without authentication,
all you can do is make access as hard as possible for hackers.

换言之,在门上设置更多/复杂的锁......,但任何锁可上<>。

"Lock" code using the URI

The method we used to keep a WebComponent "safe",
was to load the WebComponent from a long URI:

(Modern browers no t 2048 nature URI limit any more)

https://domain/p1/p2/customeElements/define/secure-api/HTMLElement/p7/p8/webcomponent.js

然后,内容代码decodes URI to

let p = [domain,p1,p2,"customElements","define","secure-api","HTMLElement",p7,p8]

to execute JavaScript:

<><>条码>window[p[3]][p[4](p[5]],等值扩展窗口[p[6]]{......

More locks

如果你在BtoA/AtoB和Sting.reverse()转换中投放。

你们已经阻止了最潜在的黑客。

More locks

By generating webcomponent.js server-side to use the /domain/ part,
that long URI can be the (unique) handshake between Server and Client

More complex locks

Since all state is in the URI, it is easy to apply an address shifting mechanism,
every request can be a different URI (makes PostMan unusable and a real pain to debug also :-)

[and we applied some other trickery I won t explain here]

It won t keep hackers out, but will delay them long enough for the majority to give up.

And a mousetrap

In our code/URI encoding we also included a reference to a unique "mousetrap" URI.
If we detect 404 activity in that subdir, we know someone is actively picking a lock.
And.. we can interactively lead/direct them to more mousetraps.

迄今为止,我们只有一次尝试。

One telephone call (because we know the buyers Domain) was enough to make them stop.

Hello IT manager of [very-big-well-known] IT company X,
if we detect hacking attempts from your company IP address nn.nn.nn.nn,
by law we would have to report this to the authorities

HTH





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...