Redirects in declarativeNetRequests to Local Resource - google-chrome

I am trying to redirect the request sent to https://site/script1.js to a modified script stored locally chrome-extension://ext_id/my_script.js.
(Basically trying to emulate the behaviour of webRequests.onBeforeRequest -> return redirect to local file)
My rules.json :
[
{
"id": 1,
"priority": 10,
"action":
{ "type": "redirect",
"redirect" : {"extensionPath" : "/my_script.js"}
},
"condition":
{"urlFilter": "https://site/script1.js",
"resourceTypes": ["script"]
}
}
]
If I change the action type to block the chrome dev tools shows the request as blocked, and the website doesnt load, however on redirects, nothing happens and the request goes through. It doesnt work for Images either.
Is there possibly a workaround for this (to modify the script a site receives from a request)?
Edit:
I'll just try to get an image to work first, the declarativeNetRequest Docs single out Redirects for a script.
The website (https://www.example.com/a/b) sends a request to https://cdn.example.com/file.jpg. I want that request to return a file `my_file.jpg' stored locally .
I have :
Rules.json
[
{
"id": 2,
"priority": 9,
"action":
{ "type": "redirect",
"redirect" : {"extensionPath" : "/my_file.jpg"}
},
"condition":
{"urlFilter": "https://cdn.example.com/file.jpg",
"resourceTypes": ["image"]
}
}
]
and Manifest.json includes:
"host_permissions": [
"https://www.example.com/*"
],
"web_accessible_resources":[
{
"resources": ["my_file.jpg"],
"matches" :["https://www.example.com/*"]
}
]

Related

Can my bot server retrieve any information in the app manifest?

I am adding a new static tab to an existing teams app.
One of the new features is that the chat will publish a deep link to the static tab. This is creating a dilemna when I am contemplating deployment.
Obviously I can’t put my entire application up here, but we can assume a situation like this:
The manifest I have in production that is in the App Store looks like this:
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.9/MicrosoftTeams.schema.json",
"manifestVersion": "1.9",
"version": "2.0.1",
"id": "23232322-7676-4848-5555-44444444444",
"packageName": "xxxxx",
"developer": {
"name": "xxxxx",
"websiteUrl": "https://www.xxxx.com/",
"privacyUrl": "https://www.xxxx.com/legal/privacy",
"termsOfUseUrl": "https://www.xxxxx.com/legal/privacy"
},
"icons": {
"color": "color.png",
"outline": "outline.png"
},
"name": {
"short": "abra",
"full": "abra cadabra"
},
"description": {
"short": "short",
"full": "full"
},
"accentColor": "#FFFFFF",
"bots": [
{
"botId": "11111111-2222-3333-4444-555555555555",
"scopes": [
"personal"
],
"commandLists": [
{
"scopes": [
"personal"
],
"commands": [
{
"title": "Test",
"description": "Test"
}
]
}
],
"supportsFiles": false,
"isNotificationOnly": false
}
],
"permissions": [
"identity",
"messageTeamMembers"
],
"validDomains": [
"token.botframework.com",
"teams.microsoft.com",
"*.ngroc.io"
]
}
And in my bot in response to the “Test” command I return a simple text message, i.e.
return await step.prompt('textPrompt', { prompt: 'In the next version we will have a test tab' })
Now in development, I have added the following section to the manifest (after “bots”)
"staticTabs": [
{
"entityId": "conversations",
"scopes": [
"personal"
]
},
{
"entityId": "testtab”,
"contentBotId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"name": “Go To Test Tab",
"scopes": [ "personal" ]
},
{
"entityId": "about",
"scopes": [
"personal"
]
}
],
And I have updated the value of the version from 2.0.1 to 2.1.0
Now, in response to the “Test” message I am returning an adaptiveCard that looks like this:
{
type: 'AdaptiveCard',
version: '1.3',
body: [],
actions: [
{
type: 'Action.OpenUrl',
title: 'Go To Test Tab',
url: ‘https://teams.microsoft.com/l/entity/23232322-7676-4848-5555-44444444444/testtab’
}
]
}
This works very nicely and when I press the “go to Test Tab” it opens up the test tab as desired.
My problem is with deploying.
If I submit my new manifest to the App Store, without updating my production server, those testing the new version will continue to get the message “In the next version we will have a test tab” and be missing the link to the new tab.
If I update my production server now, before the update in the App Store, my current users will get the adaptive card with the button that will fail if they press it.
Clearly, neither of these options are good.
Ideally, my response should be something like:
If tabExists() {
Return {… the adaptive card }
Else {
return await step.prompt('textPrompt', { prompt: 'In the next version we will have a ‘test tab })
}
However, I don't know how to write "tabExists()" - I was thinking maybe there was some way to access the version number from the bot manifest, or the list of static tabs, and use that information, but I am happy for alternative suggestions.
We can get the manifest version using below Graph API or using SDK method:
https://learn.microsoft.com/en-us/graph/api/appcatalogs-list-teamsapps?view=graph-rest-1.0&tabs=http#example-4-list-applications-with-a-given-id-and-return-the-submission-review-state
So, before sending the Adaptive Card or message, you can put a custom condition to check the manifest version and send the message accordingly.
You can check the manifest version as explained by Chetan, i tried the same and figured its actually not the best idea.
It always should be best practice to have a "production" and "test" server or something like that.
Having different manifest versions point to the same server and running checks which version you're on will more than likely lead to issues sooner or later.
I sometimes even have 3 different instances running (prod, staging, test) to try various builds and things.
You can check that in your code but imo its not advisable to do so.

Dynamic redirects with declarativeNetRequest

I want to use declarativeNetRequest to redirect all URLs from a domain to a URL with the initiator URL as an encoded parameter e.g.
http://www.google.com --> http://www.newsite.com?url=http%3A%2F%2Fwww.google.com
http://www.google.com?param1=true --> http://www.newsite.com?url=http%3A%2F%2Fwww.google.com%3Fparam1%3Dtrue
Something like...
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"url": `http://www.newsite.com?url=${encodeURIComponent(url)}`
}
}
}
Is this possible to do? If not is there another way to achieve this?
[
{
"id": 1,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "http://www.newsite.com?url=\\0"
}
},
"condition": {
"regexFilter": "^https://www.google.com(.*)",
"resourceTypes": ["main_frame"]
}
}
]
It won't URL encode it but I've found it's not really an issue provided the parameter is at the end. Also be careful to limit it to particular sites in the regex or else you could end up with an endless loop.

postman duplicate collection / export + re-import

relatively new to Postman, having problem with the following simple scenario - I have a collection of Postman requests that all point to a local IP where I am developing my application. Let's suppose I finished my local development, deployed the application on some other server, and want to repeat the requests I previously created on THAT server. I know that probably one way to do this would be to use variables.
Instead of that, though, I did an export of the collection, and did a manual edit of the exported JSON file, replacing all the old local IP's with the new server IP. Also changed the collection name, and ID to something arbitrary. While the import back to Postman works, and I see the requests, they all have the old IP still hanging there, as if my replace didn't work, or as if Postman somehow caches the requests and thinks that that new collection is the same as the old one. I also tried "Duplicating" a collection and exporting the duplicated one / replacing / importing again - but the behavior seems to be the same.
Did I miss something, or should I approach what I want to do differently?
Thank you.
duh, I am dumb enough to have been substituting the "raw" URL, while right below there were the old values for "host" and "port" that are the ones Postman constructs URL from:
{
"info": {
"_postman_id": "1499274a-07bc-4ed2-87d4-b10d0cef8f8f",
"name": "some-collection-DEVSERVER",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "login (success - bad locale)",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"username\" : \"TEST\",\n\t\"password\" : \"123456\",\n\t\"locale\" : \"asd\"\n}"
},
"url": {
"raw": "http://SERVER-IP:SERVER-PORT/new-path/login",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8081",
"path": [
"old-path",
"login"
]
}
},
"response": []
},
...
]
}
So, after suggestion to use variables I ended up creating two Collection variables "base-URL-LOCAL" and "base-URL-SERVER", that play the role of constants, and a third variable "base-url" which e.g. could have the value of {{base-URL-LOCAL}} (both initial and current values have to be updated). In my exported JSON collection, i substituted all "url" elements with something like the following:
"url": {
"raw": "{{base-url}}/login",
"host": [
"{{base-url}}"
],
"path": [
"login"
]
}
That way somebody who gets my collection won't have to have pre-defined environments set up, and will have to edit collection variables, setting e.g. base-url to {{base-URL-SERVER}}

MediaWiki API Incorrect User Rights

I'm battling with the WikiEditor extension of MediaWiki 1.27. When a user tries to use the fancy image upload button from the enhanced editor toolbar, I get the message "You must be logged in to upload files."
So far I've narrowed it down to the user rights returned from the API being incomplete. I've tested with the following two API calls:
The one WikiEditor uses: action=query&meta=userinfo&uiprop=rights
returns:
{
"batchcomplete": "",
"query": {
"userinfo": {
"id": 1006,
"name": "john_smith",
"rights": [
"read",
"createpage",
"createtalk",
"writeapi",
"editmyusercss",
"editmyuserjs",
"viewmywatchlist",
"editmywatchlist",
"viewmyprivateinfo",
"editmyprivateinfo",
"editmyoptions",
"autocreateaccount"
]
}
}
}
However, this API call: action=query&list=users&ususers=john_smith&usprop=rights returns:
{
"batchcomplete": "",
"query": {
"users": [
{
"userid": 1006,
"name": "john_smith",
"rights": [
"block",
"createaccount",
"delete",
"bigdelete",
"deletedhistory",
"deletedtext",
"undelete",
"editinterface",
"editusercss",
"edituserjs",
"editcontentmodel",
"import",
"importupload",
"move",
"move-subpages",
"move-rootuserpages",
"move-categorypages",
"patrol",
"autopatrol",
"protect",
"editprotected",
"rollback",
"upload",
"reupload",
"reupload-shared",
"unwatchedpages",
"autoconfirmed",
"editsemiprotected",
"ipblock-exempt",
"blockemail",
"markbotedits",
"apihighlimits",
"browsearchive",
"noratelimit",
"movefile",
"unblockself",
"suppressredirect",
"mergehistory",
"managechangetags",
"deleterevision",
"read",
"createpage",
"createtalk",
"writeapi",
"editmyusercss",
"editmyuserjs",
"viewmywatchlist",
"editmywatchlist",
"viewmyprivateinfo",
"editmyprivateinfo",
"editmyoptions",
"autocreateaccount",
"edit",
"minoredit",
"purge",
"sendemail",
"applychangetags",
"changetags"
]
}
]
}
}
I'm totally stumped and at a loss of why these two very similar API calls return a different set of rights. As a result, users are not able to upload images via the enhanced editor button.

Generate POSTMAN in webpage with JSON or something

I have a restAPI code from a programmer from JNE, company stands for delivery service.
They say that this API can be run in POSTMAN (Google Chrome Application)
It works fine in the POSTMAN, where in this application I just need to insert the request URL (which I have got from the JNE company) and two header of keys and values as follow;
KEY VALUE
----------------------------------------------
username mycompany
api key 4534645756864234523424
The method for this is POST and when I posted it, it gives me the results as how expected.
My problem now is, how can I run this code in my page, so that I don't need to run this in postman.
I am just this day going to learn JSON if anybody can help me out with this.
[UPDATE QUESTION 1]
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"dsfsdfsdfs98d98sdfsdf9898dsfs",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
From the update question above; my first question is: ]
In what format I have to save this file: JSON? or WHAT?
Should I save this file in one file with my webpage? or Can I save it as external file?
From the code above, I get the result as follow:
{
"detail": [
{
"code": "CGK10000",
"label": "JAKARTA"
},
{
"code": "CGK10100",
"label": "JAKARTA BARAT"
},
{
"code": "CGK10300",
"label": "JAKARTA PUSAT"
},
{
"code": "CGK10200",
"label": "JAKARTA SELATAN"
},
{
"code": "CGK10500",
"label": "JAKARTA TIMUR"
},
{
"code": "CGK10400",
"label": "JAKARTA UTARA"
}
]
}
If you have a look to the "label" it is generated from the key of the last string in the: "name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jak",
The result of the label from the last string of jak, is what I want to insert in a dropdown html tag, in where the user will choose that (the name of the location).
[Update with complete code]
POST /tracing/mycompany/origin/key/jak HTTP/1.1
Host: api.jne.co.id:8889
Content-Type: application/json
username: mycompany
api_key: 089a12ffb8cd5009bdfa4ba5bdb9ee26
{
"version":1,
"collections":
[
{
"id":"c8b12431-8586-cbdd-aef7-056ec177509a",
"name":"asdasdadasdasdasd",
"timestamp":1415593872130,
"requests":
[
{
"collectionId":"c8b12431-8586-cbdd-aef7-056ec177509a",
"id":"d1b2ed66-781d-d02e-c4eb-0416dd3e07a1",
"name":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"description":"",
"url":"http://api.jne.co.id:8889/tracing/mycompany/origin/key/jakarta",
"method":"POST",
"headers":"username: mycompany\napi_key:089a12ffb8cd5009bdfa4ba5bdb9ee26\n",
"data":
[
{
"key":"username",
"value":"mycompany",
"type":"text"
},
{
"key":"api_key",
"value":"089a12ffb8cd5009bdfa4ba5bdb9ee26",
"type":"text"
}
],
"dataMode":"params",
"timestamp":0,
"responses":[],
"version":2
}
]
}
],
"environments":[],
"headerPresets":[],
"globals":[]
}
I have saved this file as jne.json and jne.html but the browser just show the full code insted show the result as how the postman does. I think there are many things I am missing here.
The POST request would look something like the following
POST /tracing/mycompany/origin/key/jak HTTP/1.1
Host: api.jne.co.id:8889
Content-Type: application/json
username: mycompany
api_key: 089a12ffb8cd5009bdfa4ba5bdb9ee26
{
... your JSON ...
}
You can save JSON with the .json file extension. If your request is always the same you can save this file with your webpage, but normally an HTTP request is constructed before sending (that means you normally send different requests).
To fill the dropdown list you just have to parse the JSON response.