
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@nativescript-community/https
Advanced tools
Easily integrate the most reliable native networking libraries with the latest and greatest HTTPS security features.
Plugin version 2.0.0 bumps
AFNetworking
on iOS to 4.0.0 which no longer relies onUIWebView
. Make sure to runpod repo update
to get the latestAFNetworking
pod on your development machine.
What the flip is SSL pinning and all this security mumbo jumbo?
How to make your apps more secure with SSL pinning.
Do I have to use SSL pinning?
No. This plugin works out of the box without any security configurations needed. Either way you'll still benefit from all the features listed above.
git clone https://github.com/nativescript-community/https
cd https
npm run demo.ios
npm run demo.android
tns-platform-declarations
for Android and iOS to your references.d.ts
!/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
We also recommend adding "skipLibCheck": true,
to your tsconfig.json
.
More information on that can be found here.
Install the plugin:
tns plugin add @nativescript-community/https
GET
methodimport * as Https from '@nativescript-community/https';
Https.request({
url: 'https://httpbin.org/get',
method: 'GET',
timeout: 30, // seconds (default 10)
})
.then(function (response) {
console.log('Https.request response', response);
})
.catch(function (error) {
console.error('Https.request error', error);
});
Create a folder called assets
in your projects app
folder like so <project>/app/assets
. Using chrome, go to the URL where the SSL certificate resides. View the details then drag and drop the certificate image into the assets
folder.
import { knownFolders } from 'file-system';
import * as Https from '@nativescript-community/https';
let dir = knownFolders.currentApp().getFolder('assets');
let certificate = dir.getFile('httpbin.org.cer').path;
Https.enableSSLPinning({ host: 'httpbin.org', certificate });
Once you've enabled SSL pinning you CAN NOT re-enable with a different host
or certificate
file.
import * as Https from '@nativescript-community/https';
Https.disableSSLPinning();
All requests after calling this method will no longer utilize SSL pinning until it is re-enabled once again.
There is a new option called useLegacy
. You can set of every request options.
When using that option the request will behave more like {N} http module.
content
returned by a request is not the resulting string but an object. It follows HTTPContent format for the most part. You can call toJSON
or toFile
. The only difference is that toFile
returns a Promise<File>
which means that it is async and run in a background thread!content
too allowing you to read its content.By default basic Cookie support is enabled to work like in {N} http
module.
In the future more options will be added
import { knownFolders, path } from '@nativescript/core/file-system';
import * as Https from '@nativescript-community/https';
Https.setCache({
diskLocation: path.join(knownFolders.documents().path, 'httpcache'),
diskSize: 10 * 1024 * 1024, // 10 MiB
});
/// later on when calling your request you can use the cachePolicy option
If you set the Content-Type
header to "multipart/form-data"
the request body will be evaluated as a multipart form data. Each body parameter is expected to be in this format:
{
data: any
parameterName: string,
fileName?: string
contentType?: string
}
if fileName
and contentType
are set then data is expected to be either a NSData
on iOS or a native.Array<number>
on Android.
export interface HttpsSSLPinningOptions {
host: string;
certificate: string;
allowInvalidCertificates?: boolean;
validatesDomainName?: boolean;
commonName?: string;
}
import { HttpRequestOptions } from 'tns-core-modules/http';
export interface HttpsRequestOptions extends HTTPOptions {
useLegacy?: boolean;
cachePolicy?: 'noCache' | 'onlyCache' | 'ignoreCache';
onProgress?: (current: number, total: number) => void;
}
SSLPinning Option | Description |
---|---|
host: string | This must be the request domain name eg sales.company.org . |
commonName?: string | Default: options.host, set if certificate CN is different from the host eg *.company.org (Android specific) |
certificate: string | The uri path to your .cer certificate file. |
allowInvalidCertificates?: boolean | Default: false . This should always be false if you are using SSL pinning. Set this to true if you're using a self-signed certificate. |
validatesDomainName?: boolean | Default: true . Determines if the domain name should be validated with your pinned certificate. |
Requests Option | Description |
---|---|
useLegacy?: boolean | Default: false . [IOS only] set to true in order to get the response data (when status >= 300)in the content directly instead of response.body.content . |
`cachePolicy?: 'noCache' | 'onlyCache' |
onProgress?: (current: number, total: number) => void | [IOS only] Set the progress callback. |
Since you're probably shipping a certificate with your app (like our demo does),
make sure it's bundled by Webpack as well. You can do this by adding the certificate(s) with the CopyWebpackPlugin
.
iOS
TroubleshootingPlease educate yourself on iOS's App Transport Security before starting beef!
If you try and hit an https
route without adding it to App Transport Security's whitelist it will not work!
You can bypass this behavior by adding the following to your projects Info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
This plugin does not add
NSAllowsArbitraryLoads
to your projectsInfo.plist
for you.
Android
troubleshootingIf you app crashes with a message that it's doing too much networkin on the main thread,
then pass the option allowLargeResponse
with value true
to the request
function.
Who | Why |
---|---|
Robert Laverty | For creating and maintaining this plugin for a long time, before transfering it to me, with the help of Jeff Whelpley of GetHuman. |
AFNetworking | AFNetworking A delightful networking framework for iOS, OS X, watchOS, and tvOS. |
Square | okhttp An HTTP+HTTP/2 client for Android and Java applications. |
FAQs
Nativescript plugin for https requests
The npm package @nativescript-community/https receives a total of 45 weekly downloads. As such, @nativescript-community/https popularity was classified as not popular.
We found that @nativescript-community/https demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 20 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.