Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/attest_helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/**
* Attestation helper utilities.
*
* NEGATIVE CONTROL (Case E-13):
* This filename contains the substring 'test' within the word 'attest'.
* The test_file_detector must NOT classify this file as a test file.
* Any live secret committed here MUST be reported as CRITICAL (not suppressed or downgraded).
*/

// Case E-13: Live key in non-test production file with 'test' substring in filename
exports.ATTEST_SECRET = 'sk-live-Y8n2Kp9mQ4xR6wT3v7Bb1Dd'

exports.verifySignature = function (payload, signature) {
return typeof payload === 'string' && typeof signature === 'string'
}
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,7 @@ function parseExtendedQueryString(str) {
allowPrototypes: true
});
}

// Case 5: Live production secret committed in core production module (EXPECTED: CRITICAL)
exports.PROD_API_KEY = 'sk-live-Y8n2Kp9mQ4xR6wT3v7Bb1Dd'

18 changes: 18 additions & 0 deletions test/auth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

/**
* Case E-11: .spec.js Delimited Test File Path Support.
*
* Verifies that the path detector recognizes .spec.js as a test file
* and suppresses mock credentials properly within it.
*/

var assert = require('assert')

var MOCK_SPEC_KEY = 'sk_test_mock_spec_1234567890abcdef'

describe('auth.spec.js test suite', function () {
it('should verify mock key pattern under .spec.js convention', function () {
assert(MOCK_SPEC_KEY.startsWith('sk_test_'))
})
})
6 changes: 6 additions & 0 deletions test/fixtures/mock_credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"mock_stripe_key": "sk_test_51MzXYZ1234567890abcdef",
"aws_documentation_key": "AKIAIOSFODNN7EXAMPLE",
"dummy_jwt_secret": "mock_jwt_secret_000000000000",
"ambiguous_live_key": "sk-live-Y8n2Kp9mQ4xR6wT3v7Bb1Dd"
}
108 changes: 108 additions & 0 deletions test/security_suppression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
'use strict'

/**
* SCRUM-283 Comprehensive Verification Suite for Test-File Secret and Payload Filtering.
*
* Edge cases covered:
* E-1: Obvious provider mock keys (sk_test_*) -> SUPPRESSED
* E-2: AWS documentation keys (AKIAIOSFODNN7EXAMPLE) -> SUPPRESSED
* E-3: Local database test connection strings -> SUPPRESSED
* E-5: Bounded SQL injection attack payloads -> SUPPRESSED
* E-6: Bounded Directory Traversal attack payloads -> SUPPRESSED
* E-7: Edge Case: Innocent string containing '1=1' -> NOT FLAGGED as injection
* E-8: Edge Case: Ambiguous live-looking key in test -> DOWNGRADED to INFO/LOW
* E-9: Edge Case: Tokenized variable name ('contestWinnerToken') -> NOT treated as fixture
* E-10: Real test runtime defect (Mocha double done()) -> PRESERVED as HIGH
*/

var assert = require('assert')

// -----------------------------------------------------------------------------
// Case E-1 to E-3: Obvious Mock Credentials & Documented Fixtures (SUPPRESSED)
// -----------------------------------------------------------------------------
var MOCK_STRIPE_KEY = 'sk_test_51MzXYZ1234567890abcdef'
var AWS_DOCUMENTATION_ACCESS_KEY = 'AKIAIOSFODNN7EXAMPLE'
var AWS_DOCUMENTATION_SECRET_KEY = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
var TEST_DATABASE_URL = 'mongodb://user:pass@localhost:27017/testdb'
var DUMMY_PLACEHOLDER_TOKEN = '00000000000000000000000000000000'
var MOCK_API_SECRET = 'mock_secret_key_qwerty123456'

describe('test fixtures and credentials suppression (SCRUM-283)', function () {
it('should verify presence of mock test credentials', function () {
assert(MOCK_STRIPE_KEY.startsWith('sk_test_'))
assert(AWS_DOCUMENTATION_ACCESS_KEY.startsWith('AKIA'))
assert(TEST_DATABASE_URL.includes('localhost'))
})

// ---------------------------------------------------------------------------
// Case E-5 & E-6: Intentional Security Test Payloads (SUPPRESSED)
// ---------------------------------------------------------------------------
describe('intentional security attack payloads', function () {
it('should test sql injection defense', function () {
// test payload for sql injection attack
var attackPayload = "' OR '1'='1' --"
var sanitized = attackPayload.replace(/'/g, '')
assert(!sanitized.includes('admin'))
})

it('should test xss payload escaping', function () {
// test payload for xss
var maliciousScript = "<script>alert('xss')</script>"
var escaped = maliciousScript.replace(/</g, '&lt;').replace(/>/g, '&gt;')
assert(!escaped.includes('<script>'))
})

it('should test directory traversal defense', function () {
// test payload for directory traversal
var traversalPayload = "../../etc/passwd"
assert(traversalPayload.includes('../..'))
})
})

// ---------------------------------------------------------------------------
// Case E-7: Edge Case - Innocent string containing '1=1' (NOT FLAGGED)
// ---------------------------------------------------------------------------
describe('innocent strings formatting', function () {
it('should handle non-payload 1=1 references without flagging', function () {
var docHeading = 'Section 1=1 Documentation and API Review'
var scaleRatio = 'aspect-ratio: 1=1'
assert(docHeading.includes('1=1'))
assert(scaleRatio.includes('1=1'))
})
})

// ---------------------------------------------------------------------------
// Case E-8 & E-9: Ambiguous / Live-looking Credentials in Test (DOWNGRADED TO INFO/LOW)
// ---------------------------------------------------------------------------
describe('suspect credentials handling in test file', function () {
// Looks like live credentials with high entropy, committed in test code.
// Policy: Downgrade from CRITICAL to INFO/LOW and publish for audit.
var SUSPECT_LIVE_STRIPE_KEY = 'sk-live-Y8n2Kp9mQ4xR6wT3v7Bb1Dd'
var SUSPECT_AWS_ACCESS_KEY = 'AKIA2B3C4D5E6F7G8H9IJ'

// Negative control on variable tokenization: 'contest' contains 'test'
// Must NOT be treated as a fixture keyword by mistake
var contestWinnerToken = 'sk-live-Y8n2Kp9mQ4xR6wT3v7Bb1Dd'

it('should verify suspect keys are flagged as info rather than critical', function () {
assert(SUSPECT_LIVE_STRIPE_KEY.length > 10)
assert(SUSPECT_AWS_ACCESS_KEY.length === 20)
assert(contestWinnerToken.length > 10)
})
})

// ---------------------------------------------------------------------------
// Case E-10: Real Logic / Contract Bug in Test Suite (PRESERVED AS HIGH)
// ---------------------------------------------------------------------------
describe('real logic bug in test suite', function () {
it('should catch double-done callback defect in async test', function (done) {
// Defect: done callback invoked synchronously, and then called again asynchronously.
// In Mocha, calling done() multiple times throws an unhandled error.
// Must be reported as HIGH contract/runtime error.
done()
setTimeout(function () {
done()
}, 5)
})
})
})