Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
gcs-signed-urls
Advanced tools
Allow uploads directly from the browser to Google Cloud Storage while controlling access with Nodejs and signed urls.
I created this NPM module so that I can create web apps that allow users to upload directly to Google Cloud Storage. Using Signed URLs I am able to control access with Node.js and a private key. Because there is not a Node.js SDK for Google Cloud Storage, the cryptographic signatures were coded using Node.js's crypto module to Google's specification. This integration alleviates much of the maintenance required in storing and handing file uploads in web apps while at the same time not complicating the uploading process by acting as a middleman between the user and Google Cloud Storage.
NOTE: you need to create a google service account.
Simple example: http://gcs-signed-urls.herokuapp.com/.
For more advanced examples with xhr uploads, see https://github.com/sfarthin/crop-rotate-and-sample-in-browser.
npm install gcs-signed-urls
After you create a service account you should recieve a .p12 file. Convert the .p12 (key and certificate in one) to an ascii formatted .pem which can be read as text. Use this command:
openssl pkcs12 -in *.p12 -out google-services-private-key.pem -nodes -clcerts
The password is always "notasecret"
Your all set! Now you will be able to run the example app.
First create your CloudStorage instance with your gcs information.
var CloudStorage = require("gcs-signed-urls")("/path/to/google-services-private-key.pem", "*****@developer.gserviceaccount.com", "my_bucket_name")
You can also store gcs information in environment variables so you do not need to specify it in your application.
var CloudStorage = require("gcs-signed-urls")()
Set variables like this:
$ export GOOGLE_SERICES_EMAIL=*****@developer.gserviceaccount.com
$ export GCS_STORAGE_BUCKET=my-bucket
$ export GCS_PRIVATE_KEY=`cat path/to/google-services-private-key.pem`
This method creates an object representing the fields of an HTML form.
filename - Filename given to the file uploaded. Mime type is determined given the extension.
key - The Google Cloud key.
isAttachment - This sets content disposition to be an attachment, causing the browser to download the file (with the given filename) rather than show the file inside the browser.
customFields - Set custom "x-goog-meta-" headers.
<form action="http://my_bucket.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="<%=key%>">
<input type="hidden" name="bucket" value="my_bucket">
<input type="hidden" name="GoogleAccessId" value="*****@developer.gserviceaccount.com">
<input type="hidden" name="policy" value="<%=fields.policy%>">
<input type="hidden" name="signature" value="<%=fields.signature%>">
<input name="file" type="file">
<input type="submit" value="Upload">
</form>
Direct upload from Node.js using the same options as uploadRequest.
Takes an acl option and sets that as the default acl of an object. The options are: project-private private public-read public-read-write authenticated-read bucket-owner-read bucket-owner-full-control
See https://developers.google.com/storage/docs/accesscontrol#extension
Sets the xml cors policy
The tests and example require environoment variables to be set.
$ export GOOGLE_SERICES_EMAIL=*****@developer.gserviceaccount.com
$ export GCS_STORAGE_BUCKET=my-bucket
$ export GCS_PRIVATE_KEY=`cat google-services-private-key.pem`
To run test
npm test
To run example on port 3001
npm start
heroku create
heroku config:set GOOGLE_SERICES_EMAIL=***@developer.gserviceaccount.com
heroku config:set GCS_STORAGE_BUCKET=my bucket
heroku config:set GCS_PRIVATE_KEY=`cat google-services-private-key.pem`
git push heroku master
FAQs
Allow uploads directly from the browser to Google Cloud Storage while controlling access with Nodejs and signed urls.
The npm package gcs-signed-urls receives a total of 8 weekly downloads. As such, gcs-signed-urls popularity was classified as not popular.
We found that gcs-signed-urls demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.