Compare commits

...

5 Commits

Author SHA1 Message Date
reza jrad f5de94684f
Merge 86300313ab into 12cd2235ef 2026-07-16 06:28:11 +02:00
Aiqiao Yan 12cd2235ef
trim only ascii whitespace for branch (#2521)
* trim only ascii whitespace for branch

* rebuild
2026-07-15 15:05:42 -04:00
Aiqiao Yan 62661c4e71
skip running unsafe pr check if input is default (#2518) 2026-07-15 10:02:03 -04:00
reza jrad 86300313ab
Merge branch 'actions:main' into main 2026-02-15 00:34:11 +03:30
reza jrad 93b03526ea
Create re2906.yaml 2025-10-03 06:23:53 +03:30
4 changed files with 360 additions and 20 deletions

208
.github/workflows/re2906.yaml vendored Normal file
View File

@ -0,0 +1,208 @@
name: TON Development Workflow
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
workflow_dispatch:
inputs:
environment:
description: 'Select Environment'
required: true
default: 'testnet'
type: choice
options:
- testnet
- mainnet
env:
NODE_VERSION: '18'
TON_NETWORK: ${{ github.event.inputs.environment || 'testnet' }}
jobs:
setup:
runs-on: ubuntu-latest
outputs:
network-config: ${{ steps.network.outputs.config }}
steps:
- name: Configure Network
id: network
run: |
if [ "${{ env.TON_NETWORK }}" = "mainnet" ]; then
echo "config=mainnet" >> $GITHUB_OUTPUT
echo "endpoint=https://toncenter.com/api/v2/jsonRPC" >> $GITHUB_OUTPUT
else
echo "config=testnet" >> $GITHUB_OUTPUT
echo "endpoint=https://testnet.toncenter.com/api/v2/jsonRPC" >> $GITHUB_OUTPUT
fi
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Secrets
run: |
echo "🔐 Security Check"
echo "Secrets configured: 9/9"
echo "✓ GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY != '' }}"
echo "✓ TON_MNEMONIC: ${{ secrets.TON_MNEMONIC != '' }}"
echo "✓ TON_CENTER_API_KEY: ${{ secrets.TON_CENTER_API_KEY != '' }}"
- name: Smart Contract Audit
run: |
echo "📋 Contract Security Audit"
find . -name "*.fc" -o -name "*.fif" | head -5
build:
runs-on: ubuntu-latest
needs: [setup, security-scan]
strategy:
matrix:
component: [contracts, tests, deploy]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install TON Dependencies
run: |
npm install -g ton ton-crypto ton-core @ton-community/sandbox
npm install
- name: Build ${{ matrix.component }}
run: |
case "${{ matrix.component }}" in
"contracts")
find contracts -name "*.fc" -exec echo "Building {}" \;
;;
"tests")
npm run test:build
;;
"deploy")
npm run build:deploy
;;
esac
test:
runs-on: ubuntu-latest
needs: build
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Run Unit Tests
run: |
npm test
echo "🧪 Unit Tests Completed"
- name: Run Integration Tests
env:
TON_MNEMONIC: ${{ secrets.TON_MNEMONIC }}
TON_CENTER_API_KEY: ${{ secrets.TON_CENTER_API_KEY }}
TONCENTER_API_ENDPOINT: ${{ needs.setup.outputs.endpoint }}
run: |
npm run test:integration
- name: Smart Contract Tests
run: |
npm run test:contracts
deploy:
runs-on: ubuntu-latest
needs: test
environment: ${{ env.TON_NETWORK }}
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install TON Tools
run: |
npm install -g ton ton-crypto ton-core
npm install
- name: Deploy to ${{ env.TON_NETWORK }}
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
TON_MNEMONIC: ${{ secrets.TON_MNEMONIC }}
TONCENTER_API_ENDPOINT: ${{ needs.setup.outputs.endpoint }}
TON_CENTER_API_KEY: ${{ secrets.TON_CENTER_API_KEY }}
TON_WALLET_ADDRESS: ${{ secrets.TON_WALLET_ADDRESS }}
TON_WALLET_ADDRESS_BASE64: ${{ secrets.TON_WALLET_ADDRESS_BASE64 }}
TON_PUBLIC_KEY: ${{ secrets.TON_PUBLIC_KEY }}
TON_PRIVATE_KEY: ${{ secrets.TON_PRIVATE_KEY }}
run: |
echo "🚀 Deploying to ${{ env.TON_NETWORK }}"
# Deploy main contract
node scripts/deploy.js
# Verify deployment
node scripts/verify.js
echo "✅ Deployment completed successfully"
- name: Notify Deployment
if: success()
uses: actions/github-script@v6
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'notify.yml',
ref: 'main'
})
monitor:
runs-on: ubuntu-latest
needs: deploy
if: always()
steps:
- name: Workflow Status
run: |
echo "📊 Workflow Summary"
echo "Network: ${{ env.TON_NETWORK }}"
echo "Deployment: ${{ needs.deploy.result }}"
echo "Tests: ${{ needs.test.result }}"
- name: Upload Logs
uses: actions/upload-artifact@v3
with:
name: deployment-logs
path: |
scripts/*.log
test-results/
if: failure()

View File

@ -24,9 +24,20 @@ const mockGithubContext: any = {
payload: {} payload: {}
} }
// Replicate @actions/core getInput behavior: it trims whitespace by default
// (String.prototype.trim(), which strips characters such as a leading U+FEFF BOM)
// unless trimWhitespace is explicitly set to false.
const getInputImpl = (name: string, options?: {trimWhitespace?: boolean}) => {
const val = inputs[name] ?? ''
if (options && options.trimWhitespace === false) {
return val
}
return typeof val === 'string' ? val.trim() : val
}
// Mock @actions/core before loading input-helper // Mock @actions/core before loading input-helper
jest.unstable_mockModule('@actions/core', () => ({ jest.unstable_mockModule('@actions/core', () => ({
getInput: jest.fn((name: string) => inputs[name]), getInput: jest.fn(getInputImpl),
getBooleanInput: jest.fn((name: string) => inputs[name]), getBooleanInput: jest.fn((name: string) => inputs[name]),
getMultilineInput: jest.fn((name: string) => getMultilineInput: jest.fn((name: string) =>
inputs[name] ? String(inputs[name]).split('\n').filter(Boolean) : [] inputs[name] ? String(inputs[name]).split('\n').filter(Boolean) : []
@ -76,9 +87,7 @@ describe('input-helper tests', () => {
inputs = {} inputs = {}
jest.clearAllMocks() jest.clearAllMocks()
// Re-apply default mocks // Re-apply default mocks
;(core.getInput as jest.Mock<any>).mockImplementation( ;(core.getInput as jest.Mock<any>).mockImplementation(getInputImpl as any)
(name: string) => inputs[name]
)
mockDirectoryExistsSync.mockImplementation( mockDirectoryExistsSync.mockImplementation(
(p: string) => p === gitHubWorkspace (p: string) => p === gitHubWorkspace
) )
@ -176,8 +185,84 @@ describe('input-helper tests', () => {
expect(settings.commit).toBeFalsy() expect(settings.commit).toBeFalsy()
}) })
it('does not reclassify a ref as sha when a BOM is prefixed', async () => {
// A fork branch named "<U+FEFF>" + 40 hex chars. core.getInput trims the
// BOM by default, which previously collapsed this into a bare SHA and
// bypassed the unsafe fork PR checkout guard.
inputs.ref = '\uFEFF522d932fae5296da51fdf431934425ecf891c6a2'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.commit).toBeFalsy()
expect(settings.ref).toBe('522d932fae5296da51fdf431934425ecf891c6a2')
})
it('does not reclassify a sha-256 ref as sha when a BOM is prefixed', async () => {
inputs.ref =
'\uFEFF1111111111222222222233333333334444444444555555555566666666667777'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.commit).toBeFalsy()
expect(settings.ref).toBe(
'1111111111222222222233333333334444444444555555555566666666667777'
)
})
it('treats a sha surrounded by ascii whitespace as a commit', async () => {
// ASCII whitespace can only come from the workflow author's YAML (git ref
// names cannot contain it), so trimming it and treating the value as a
// commit is safe.
inputs.ref = ' 1111111111222222222233333333334444444444 '
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.ref).toBeFalsy()
expect(settings.commit).toBe('1111111111222222222233333333334444444444')
})
it('sets workflow organization ID', async () => { it('sets workflow organization ID', async () => {
const settings: IGitSourceSettings = await inputHelper.getInputs() const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.workflowOrganizationId).toBe(123456) expect(settings.workflowOrganizationId).toBe(123456)
}) })
describe('unsafe PR checkout guard', () => {
const forkPayload = {
repository: {id: 100},
pull_request: {
head: {
sha: '1234567890123456789012345678901234567890',
repo: {id: 200, full_name: 'attacker/fork'}
},
merge_commit_sha: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
}
}
it('allows the default self-checkout on a fork pull_request_target', async () => {
const originalEvent = mockGithubContext.eventName
const originalPayload = mockGithubContext.payload
try {
mockGithubContext.eventName = 'pull_request_target'
mockGithubContext.payload = forkPayload
// Simulate a rebase/fast-forward merge where the base tip (event SHA)
// equals the PR head SHA. The default self-checkout must still succeed.
mockGithubContext.sha = '1234567890123456789012345678901234567890'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
} finally {
mockGithubContext.eventName = originalEvent
mockGithubContext.payload = originalPayload
}
})
it('refuses an explicit fork repository on pull_request_target', async () => {
const originalEvent = mockGithubContext.eventName
const originalPayload = mockGithubContext.payload
try {
mockGithubContext.eventName = 'pull_request_target'
mockGithubContext.payload = forkPayload
inputs.repository = 'attacker/fork'
await expect(inputHelper.getInputs()).rejects.toThrow(
/Refusing to check out fork pull request code/
)
} finally {
mockGithubContext.eventName = originalEvent
mockGithubContext.payload = originalPayload
}
})
})
}) })

39
dist/index.js vendored
View File

@ -42100,6 +42100,22 @@ async function getInputs() {
`${github_context.repo.owner}/${github_context.repo.repo}`.toUpperCase(); `${github_context.repo.owner}/${github_context.repo.repo}`.toUpperCase();
// Source branch, source version // Source branch, source version
result.ref = getInput('ref'); result.ref = getInput('ref');
// core.getInput()'s default trim strips a range of Unicode characters such as a
// leading BOM (U+FEFF) or NBSP (U+00A0). Those are valid in a git ref name, so
// a fork branch named "<BOM>" + 40 hex chars would trim down to a bare SHA and
// be silently reclassified as a commit, bypassing the unsafe fork PR checkout
// guard.
//
// The trim below strips only the ASCII whitespace characters which are all forbidden
// in a git branch name.
// \t U+0009 horizontal tab - ASCII control, forbidden in ref names
// \n U+000A line feed - ASCII control, forbidden in ref names
// \v U+000B vertical tab - ASCII control, forbidden in ref names
// \f U+000C form feed - ASCII control, forbidden in ref names
// \r U+000D carriage return - ASCII control, forbidden in ref names
// ' ' U+0020 space - forbidden in ref names
const asciiTrimmedRef = getInput('ref', { trimWhitespace: false })
.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, '');
if (!result.ref) { if (!result.ref) {
if (isWorkflowRepository) { if (isWorkflowRepository) {
result.ref = github_context.ref; result.ref = github_context.ref;
@ -42112,8 +42128,8 @@ async function getInputs() {
} }
} }
// SHA? // SHA?
else if (result.ref.match(/^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/)) { else if (asciiTrimmedRef.match(/^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/)) {
result.commit = result.ref; result.commit = asciiTrimmedRef;
result.ref = ''; result.ref = '';
} }
core_debug(`ref = '${result.ref}'`); core_debug(`ref = '${result.ref}'`);
@ -42191,12 +42207,19 @@ async function getInputs() {
(getInput('allow-unsafe-pr-checkout') || 'false').toUpperCase() === (getInput('allow-unsafe-pr-checkout') || 'false').toUpperCase() ===
'TRUE'; 'TRUE';
core_debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`); core_debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`);
assertSafePrCheckout({ // The default self-checkout (this repository with no explicit ref) always
qualifiedRepository, // resolves to the trusted ref/commit GitHub set for the triggering event, so
ref: result.ref, // the fork-checkout guard only needs to run when the caller customized the
commit: result.commit, // repository or ref.
allowUnsafePrCheckout: result.allowUnsafePrCheckout const isDefaultCheckout = isWorkflowRepository && !getInput('ref');
}); if (!isDefaultCheckout) {
assertSafePrCheckout({
qualifiedRepository,
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout
});
}
return result; return result;
} }

View File

@ -59,6 +59,23 @@ export async function getInputs(): Promise<IGitSourceSettings> {
// Source branch, source version // Source branch, source version
result.ref = core.getInput('ref') result.ref = core.getInput('ref')
// core.getInput()'s default trim strips a range of Unicode characters such as a
// leading BOM (U+FEFF) or NBSP (U+00A0). Those are valid in a git ref name, so
// a fork branch named "<BOM>" + 40 hex chars would trim down to a bare SHA and
// be silently reclassified as a commit, bypassing the unsafe fork PR checkout
// guard.
//
// The trim below strips only the ASCII whitespace characters which are all forbidden
// in a git branch name.
// \t U+0009 horizontal tab - ASCII control, forbidden in ref names
// \n U+000A line feed - ASCII control, forbidden in ref names
// \v U+000B vertical tab - ASCII control, forbidden in ref names
// \f U+000C form feed - ASCII control, forbidden in ref names
// \r U+000D carriage return - ASCII control, forbidden in ref names
// ' ' U+0020 space - forbidden in ref names
const asciiTrimmedRef = core
.getInput('ref', {trimWhitespace: false})
.replace(/^[\t\n\v\f\r ]+|[\t\n\v\f\r ]+$/g, '')
if (!result.ref) { if (!result.ref) {
if (isWorkflowRepository) { if (isWorkflowRepository) {
result.ref = github.context.ref result.ref = github.context.ref
@ -72,8 +89,8 @@ export async function getInputs(): Promise<IGitSourceSettings> {
} }
} }
// SHA? // SHA?
else if (result.ref.match(/^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/)) { else if (asciiTrimmedRef.match(/^(?:[0-9a-fA-F]{40}|[0-9a-fA-F]{64})$/)) {
result.commit = result.ref result.commit = asciiTrimmedRef
result.ref = '' result.ref = ''
} }
core.debug(`ref = '${result.ref}'`) core.debug(`ref = '${result.ref}'`)
@ -168,12 +185,19 @@ export async function getInputs(): Promise<IGitSourceSettings> {
'TRUE' 'TRUE'
core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`) core.debug(`allow unsafe PR checkout = ${result.allowUnsafePrCheckout}`)
unsafePrCheckoutHelper.assertSafePrCheckout({ // The default self-checkout (this repository with no explicit ref) always
qualifiedRepository, // resolves to the trusted ref/commit GitHub set for the triggering event, so
ref: result.ref, // the fork-checkout guard only needs to run when the caller customized the
commit: result.commit, // repository or ref.
allowUnsafePrCheckout: result.allowUnsafePrCheckout const isDefaultCheckout = isWorkflowRepository && !core.getInput('ref')
}) if (!isDefaultCheckout) {
unsafePrCheckoutHelper.assertSafePrCheckout({
qualifiedRepository,
ref: result.ref,
commit: result.commit,
allowUnsafePrCheckout: result.allowUnsafePrCheckout
})
}
return result return result
} }