How do I restrict JSON access?

前端 未结 8 757
时光取名叫无心
时光取名叫无心 2020-11-30 23:24

I have a web application that pulls data from my newly created JSON API.

My static HTML pages dynamically calls the JSON API via JavaScript from the static HTML page

8条回答
  •  不知归路
    2020-12-01 00:15

    The usual method for restricting access to your domain is prepend the content with something that runs infinitely.

    For example:

    while(1);{"json": "here"} // google uses this method
    for (;;);{"json": "here"} // facebook uses this method
    

    So when you fetch this via XMLHttpRequest or any other method that is restricted solely to your domain, you know that you need to parse out the infinite loop. But if it is fetched via script node:

    
    

    It will fail because the script will never get beyond the first statement.

提交回复
热议问题