Skip to content

Port socket-python-cli#268

Merged
jdalton merged 23 commits intomainfrom
action-cmd
Feb 5, 2025
Merged

Port socket-python-cli#268
jdalton merged 23 commits intomainfrom
action-cmd

Conversation

@typicode
Copy link
Contributor

@typicode typicode commented Dec 10, 2024

Summary

This PR is a port of socket-python-cli as of https://github.com/SocketDev/socket-python-cli/tree/6d4fc56faee68d3a4764f1f80f84710635bdaf05

It's focused on GitHub Action support due to time constraint and only function required for it were ported.

However, file names, classes, functions and logic are mapped 1:1 as much as possible. While in some places it may differ from the usual JavaScript approach, it should allow easier debugging and porting of new functionalities/bug fixes from socket-python-cli.

Socket SDK and Octokit were used to provide accurate TS typing of responses for API calls out of the box.

Usage

See https://github.com/socketdev-demo/javascript-threats/blob/main/.github/workflows/socket.yml for usage reference

There are some differences though. In socket.yml, some data like changed files is created using shell scripts and then passed using environment variables.

When possible, this port creates this data using JavaScript instead of shell code. In particular, these environment variables don't need to be provided:

  • CHANGED_FILES (1 2)
  • EVENT_ACTION (1)

How to test:

npm run build && GITHUB_EVENT_NAME="pull_request" GITHUB_EVENT_NAME="issue_comment" GITHUB_REF="refs/pull/268/merge" GITHUB_REPOSITORY="SocketDev/socket-cli" node bin/cli.js action --githubEventBefore=bfb9afbadb597138aefb85bbe62ba7171ba32650 --githubEventAfter=2089b9a19c23506a4fe9c391df139e80456d82c5

Note: a valid socket API passed as an env variable may be needed

Action

The following step must be defined in the action file:

  - steps:
     - name: Get PR State
        if: github.event_name == 'pull_request'
        run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV

Signed-off-by: typicode <typicode@gmail.com>
@jdalton jdalton added the enhancement New feature or request label Dec 11, 2024
@jdalton
Copy link
Contributor

jdalton commented Dec 11, 2024

Thank you @typicode! Lets have a call to walk through this soon

@jdalton jdalton force-pushed the main branch 12 times, most recently from febdc37 to 2089b9a Compare December 14, 2024 18:40
@jdalton jdalton self-requested a review December 14, 2024 18:56
@jdalton jdalton force-pushed the main branch 2 times, most recently from 88098db to 9aa1da8 Compare January 23, 2025 18:52
@socket-security
Copy link

socket-security bot commented Jan 30, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@octokit/rest@21.1.0 None +14 6.5 MB gr2m, kfcampbell, nickfloyd, ...1 more
npm/@types/ndjson@2.0.4 None +1 6.74 kB types
npm/ndjson@2.0.0 None +7 113 kB contra
npm/simple-git@3.27.0 shell Transitive: environment, filesystem +4 1.02 MB steveukx

View full report↗︎

@socket-security-staging
Copy link

socket-security-staging bot commented Jan 30, 2025

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@octokit/rest@21.1.0 None +14 6.5 MB octokitbot
npm/@types/ndjson@2.0.4 None +1 6.74 kB types
npm/ndjson@2.0.0 None +7 113 kB contra
npm/simple-git@3.27.0 shell Transitive: environment, filesystem +4 1.02 MB steveukx

View full report↗︎

@socket-security-staging
Copy link

socket-security-staging bot commented Jan 30, 2025

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Unstable ownership npm/fast-content-type-parse@2.0.1 ⚠︎

View full report↗︎

Next steps

What is unstable ownership?

A new collaborator has begun publishing package versions. Package stability and security risk may be elevated.

Try to reduce the number of authors you depend on to reduce the risk to malicious actors gaining access to your supply chain. Packages should remove inactive collaborators with publishing rights from packages on npm.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/fast-content-type-parse@2.0.1

@typicode typicode marked this pull request as ready for review January 31, 2025 11:46
Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com>
@jdalton jdalton merged commit bb7b16f into main Feb 5, 2025
7 of 15 checks passed
@jdalton jdalton deleted the action-cmd branch February 5, 2025 18:55
@jdalton
Copy link
Contributor

jdalton commented Feb 5, 2025

Thank you @typicode 🎉 !

jdalton added a commit that referenced this pull request Feb 5, 2025
Signed-off-by: typicode <typicode@gmail.com>
Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com>
Co-authored-by: John-David Dalton <jdalton@users.noreply.github.com>
jdalton added a commit that referenced this pull request Feb 5, 2025
Signed-off-by: typicode <typicode@gmail.com>
Signed-off-by: John-David Dalton <jdalton@users.noreply.github.com>
Co-authored-by: John-David Dalton <jdalton@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants